Joseph Tura
Joseph Tura

Reputation: 6360

Use markdown to embolden partial words on Github

I am trying to make part of a snake-cased word bold with Github markdown.

my\_great**\_word**

And I would expect it to be rendered like this:

my_great_word

Github, however, renders it like this:

my_great**_word**

I also tried

my_great**_word**

to no avail.

Upvotes: 1

Views: 344

Answers (1)

Waylan
Waylan

Reputation: 42627

According to GitHub's spec, the first character of emphasized text cannot be punctuation. Therefore, you would need to do this:

my\_great\_**word**

If the underscore must be included in the emphasized text, then you would need to fall back to raw HTML:

my\_great<b>\_word</b>

As a reminder, GitHub uses its own Spec which is an extended CommonMark Spec. See the Emphasis and Strong Emphasis section for details. In short, emphasis (and strong emphasis) must start with a "left-flanking delimiter run" and end with a "right-flanking delimiter run".

The problem in your case is that you do not have a " left-flanking delimiter run", which is defined as (emphasis added):

A left-flanking delimiter run is a delimiter run that is (a) not followed by Unicode whitespace, and (b) not followed by a punctuation character, or preceded by Unicode whitespace or a punctuation character. For purposes of this definition, the beginning and the end of the line count as Unicode whitespace.

Note that a left-flanking delimiter run can "not be followed by a punctuation character." Of course, in your example, the underscore is a punctuation character, which causes the two asterisks before it to not be consider a left-flanking delimiter run. As you do not have a left-flanking delimiter run, then there is no emphasis.

To void that problem, you would need to move the two asterisks after the underscore so that they will be seen as a left-flanking delimiter run, giving you strong emphasis.

By the way, the rules for asterisk and underscore based emphasis are slightly different so that underscored within words to not result in false positives. That being the case, you don't actually need to escape your underscores. These work just fine on GitHub:

my_great_**word**
my_great<b>_word</b>

Upvotes: 2

Related Questions