thlorenz / brace

📔 browserify compatible version of the ace editor.
http://thlorenz.github.io/brace/
MIT License
1.06k stars 304 forks source link

Interword emphasis syntax highlighting broken for many markdown implementations #137

Open gausie opened 5 years ago

gausie commented 5 years ago

According to the commonmark spec:

Many implementations have also restricted intraword emphasis to the * forms, to avoid unwanted emphasis in words containing internal underscores. (It is best practice to put these in code spans, but users often do not.)

internal emphasis: foo*bar*baz no emphasis: foo_bar_baz

However, the markdown highlighting mode does treat the second example as emphasised. In fact, in Github I have to escape the first example precisely due to this very common implementation detail.

gausie commented 5 years ago

I quickly made the regex ([*])(.*?\S[*]*)([*])|((?<!\S)[_])(.*?\S[_]*)([_](?!\S)) which passes:

_neat_ *start but not*end end but not*start* abso*bloody*lutely i cant *believe* that

but not

snake_case_sucks _start but not_end end but notstart

so that seems right, but I may be missing a case, and it may be inefficient. Note that the current implementation already doesn't detect escaped asterisks and underscores.