Kai23
Kai23

Reputation: 1576

Highlight specific line in markdown

I'm pretty new in markdown, and I wonder if it's possible to highlight a specific line of a block of source code, like explained in this page

http://en.support.wordpress.com/code/posting-source-code/

Thanks in advance for your answers,

Edit : To be clearer, with the wordpress plugin, you can write something like this :

[code highlight="2,3"]
This line won't be highlighted.
This line will be highlighted.
This line will be highlighted.
This line won't be highlighted.
[/code]

But obviously, this isn't a markdown syntax.

Upvotes: 20

Views: 24144

Answers (3)

mabam
mabam

Reputation: 21

Your question seems to be regarding markdown on GitHub as that’s how you tagged it. But it also pops up googling for markdown in general which is why I’m providing another answer:

In some flavours of markdown, highlighting lines can be achieved by using syntax similar to your example for the WordPress plugin:

<code text [highlight_lines_extra="2,3"]>Line 1 is not highlighted.
Line 2 is highlighted.
Line 3 is highlighted.</code>

This doesn’t work on stackoverflow either. It does on DokuWiki though: https://www.dokuwiki.org/syntax_highlighting

Upvotes: 0

Karl-Marx
Karl-Marx

Reputation: 546

It can be done, but there is no Markdown syntax for it, at least not on the most common flavors. Fortunately, also on the most common flavors you can embed HTML.

My solution:

Example


function main() {
    __config_bash
    __config_xdg_dirs
}

Code

<pre><code>
    function main() {
        __config_bash
        <strong>__config_xdg_dirs</strong>
    }
</code></pre>

Upvotes: 7

daedalus
daedalus

Reputation: 10923

On SO, langauge highlighting is possible as explained in Advanced Help but not formatting within code blocks.

This is a code block
Markdown is **not** processed

You might mimic what you want by using quote:

This line won't be highlighted.
This line will be highlighted.
This line will be highlighted.
This line won't be highlighted.

You might also mimic what you want by using two spaces at end of each line:

This line won't be highlighted.
This line will be highlighted.
This line won't be highlighted.

But of course, these are not then rendered in monospaced font nor do you get syntax highlighting.

Upvotes: 5

Related Questions