jonschlinkert / sublime-markdown-extended

Top 100 Sublime Text plugin! Markdown syntax highlighter for Sublime Text, with extended support for GFM fenced code blocks, with language-specific syntax highlighting. YAML Front Matter. Works with ST2/ST3. Goes great with Assemble.
https://github.com/jonschlinkert
MIT License
659 stars 96 forks source link

Variable underscore mistaken as emphasize #61

Closed codehugger closed 6 years ago

codehugger commented 9 years ago

It is very common to use in the names of variables. Is it possible to fix it so that variables names that start with or use it within the variable name are not highlighted as emphasis (italic). Example

screenshot

willbeaufoy commented 9 years ago

I found a solution to this. See the answer here:

http://www.sublimetext.com/forum/viewtopic.php?f=3&t=8957

For this package the relevant line is from 1850 in Markdown Extended.tmLanguage

You'll need to override the file, see 'Overriding files from a zipped package' here: http://www.sublimetext.com/docs/3/packages.html

jonschlinkert commented 9 years ago

@willbeaufoy you were able to fix this? want to do a pr? :-)

willbeaufoy commented 9 years ago

Yes thanks, will do in the next few days.

willbeaufoy commented 9 years ago

Hhm I made a pull request but withdrew it as the fix actually removes all highlighting behaviour from underscores even if they're not prececeded by a word. This is fine for me but isn't ideal for those who use this as emphasis.

Anyone see a way to preserve the proper behaviour? My change is in my branch:

https://github.com/willbeaufoy/sublime-markdown-extended/tree/fix-underscore-highlighting

willbeaufoy commented 9 years ago

Ah some progress (code taken from the Markdown Editing package), using a negative lookbehind preserves proper markdown italic behaviour from underscores, the line now becomes:

(?<!\w)(\*|_)(?=\S)

as opposed to the original:

(\*|_)(?=\S)

and my first fix:

(\W)(\*|_)(?=\S)

It still doesn't support code like $_variable_name or _variable_name though so I'm still looking for a solution to this.

pradyunsg commented 8 years ago

Bump. Any fixes?