For example, if I have a markdown file with the following:

###This is my markdown file
here is some text.
here is my code block:

``` js
var accountdown = require('accountdown');
var level = require('level');
var db = level('/tmp/users.db');

var users = accountdown(db, {
    login: { basic: require('accountdown-basic') }

var user = process.argv[2];
var pass = process.argv[3];
var bio = process.argv[4];

var opts = {
    login: { basic: { username: user, password: pass } },
    value: { bio: bio }
users.create(user, opts, function (err) {
    if (err) console.error(err);

How can I enable highlighting in the code block?

Perhaps it's unrelated, but org-mode can highlight source code blocks as follows:

      '((python . t)
        (js . t)
        (R . t)))
  • The best you can do is using gfm-mode for README or more generally, all Markdown files, it will highlight the code blocks in one uniform color. The feature of highlighting them à la org-mode hasn't been implemented yet. – wasamasa Jun 16 '15 at 5:46
  • Thanks, that is disappointing but good to know. The feature works great in org-mode, hopefully someone can implement it in gfm-mode – modulitos Jun 16 '15 at 9:27
  • 1
    FWIW, I haven't turned this into an answer as one could still rip out the code responsible for this from org-mode and adapt it for your problem to turn it into an answer. – wasamasa Jun 16 '15 at 9:29

Native syntax highlighting of code blocks is now part of the current development version of Markdown mode. Specifically, it works for those GFM or tilde-fenced code blocks for which the language name has been specified, like the JavaScript code block in your question. You can toggle this mode with C-c C-x C-f (markdown-toggle-fontify-code-blocks-natively). You can set the default behavior by customizing the variable markdown-fontify-code-blocks-natively. For example:

(setq markdown-fontify-code-blocks-natively t)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.