Improved Markdown coloring and functions

and a lot more. This diff is too big.
Need to maker smaller commits in future.