Color code

I am looking for a way to color code in a markdown text, like in BBedit. Is there a script or something else to color the code of a markdown file (or Html or Css)? it would be nice…
Thanks.
Have a nice day.

Interesting question (and learned something first thing this morning :smiley: ):

Syntax highlighting isn’t directly supported, however it is possible to do it quite easily. Add this to the top of your Markdown document

<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>

Then put your code in a block like this…

<code class="prettyprint">
… insert your code here …
</code>

or you can use

<pre class="prettyprint">
… insert your code here …
</pre>

More info can be found here: github.com/google/code-prettify

Thank you very much for your answer. I have tried and it is an interesting solution. But what I am looking for is a coloring of the code in the main window while I am writing. But I suppose that this is not doable, because a markdown file is treated as a text file and so it cannot have any styling of text. Bbedit does color code the text as other html editors, but probably it is done in a very sophisticated way.

As a side: do you know how to change the css of the file that rends the text when you choose View -> Text Alternative? Where is located this css file (or whatever)?

Thank you!
Have a nice day.

There is no CSS controlling the Text alternative view. It is just plain text and the font is controlled by Preferences > Editing > Plain Text Font.

Sorry: maybe I was not clear.
If a write a markdown file with all the usual codes (italic, bold, etc.) and then I want to see how does it look I choose from View → Best alternative and I get a rendering of italic bold etc. And this could not be a plain text: there should be an engine that transforms my plain text in a styled text. I thought that this is done via css…

You can enter certain html tags into the plain text and they will be rendered as “styled” text by the markdown engine. For example, the tag will highlight text. You can get more sophisticated by adding css to the tag.

be careful, though. Not every markdown interpreter will recognize the tags, or recognize them the same way.

Very interesting. My question: the markdown engine generates a preview with the Best alternative function. But how do I change the style of the preview? for instance the style of Heading 1 (in markdown # Heading 1)? Maybe it is not possible…

You can point to a linked stylesheet or write internal CSS in the Markdown file. If you want to override an H1, redefine it yourself in by either means. This also allows you to not have to worry as much about what interpreter is rendering the Markdown.

I was very disappointed when I realized that color and even font size are not part of the core Markdown concept. It’s certainly not something beyond its capabilities: For headlines, you can easily get larger text and different colors. You can play around with css and also use html tags. On the other hand, I thought that Markdown was invented to escape mark-up hell. Html is about as unreadable as it could be with those verbose tags.

As a result, I’ve given up on Markdown at this point. I found that for anything that is within standard md, it is a superb format, but then I realized that almost every note I create seems to go beyond that. So it’s still RTF(D) for me. If only the images in RTFD were scalable…

I’ve been using PmWiki extensively for a decade now to maintain some websites. Its basic syntax is very much like Markdown in terms of bold face, italics, titles, etc. But then it has equally simply and nice tags for colors, sizes and whatnot. In principle, something like that could be a very nice engine to create good looking notes, not just websites.