Skip to content

Instantly share code, notes, and snippets.

@zachharkey
Last active August 29, 2015 13:57
Show Gist options
  • Save zachharkey/9382987 to your computer and use it in GitHub Desktop.
Save zachharkey/9382987 to your computer and use it in GitHub Desktop.
Trying to understand syntax highlighting inconsistencies in Marked.app

Lets see how this works

Let's look at a few lines from my terminal as an example.

Here is what they look like if I simply indent the block of text without any code fence or anything.

~/Sites/d7sandbox1/sites/all/themes $ rm -R mybrokentheme
~/Sites/d7sandbox1/sites/all/themes $ drush vset -y theme_default bartik

Sweet. No syntax coloring. This is how it should be.

Now lets format these same lines as a fenced code block, but without specifying the language.

~/Sites/d7sandbox1/sites/all/themes $ rm -R mybrokentheme
~/Sites/d7sandbox1/sites/all/themes $ drush vset -y theme_default bartik

Excellent. Still no syntax coloring because I didn't ask for any. This is how it should be.

And finally, here is a fenced code block with the language specified.

<div class="example">
  <p>This is an example of some HTML code in a fenced code block.</p>
</div>

Perfect. The code is syntax highlighted properly because it was explicitly specified in the markdown.

I wish it were possible to configure Marked to

  1. never apply automatic syntax highlighting to traditional Markdown indented style code blocks.
  2. not attempt to automatically infer the syntax for fenced code blocks without a specified language.
  3. always apply syntax highlighting to fenced code blocks if a language is explicitly specified after the backticks.

1 and 3 should be non-negotiable. But 2 could be a preference.

Here are the current Marked preferences:

Screenshot

Inconsistencies in Marked's display of fenced code blocks

~/Sites/d7sandbox1/sites/all/themes $ rm -R mybrokentheme
~/Sites/d7sandbox1/sites/all/themes $ drush vset -y theme_default bartik

Here's the same fenced code block with an extra line before and after:


~/Sites/d7sandbox1/sites/all/themes $ rm -R mybrokentheme
~/Sites/d7sandbox1/sites/all/themes $ drush vset -y theme_default bartik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment