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
660 stars 96 forks source link

Bug: Highlighting is missed up when using Dollar $ sign #160

Closed ditek closed 6 years ago

ditek commented 7 years ago

Highlighting is missed up when using Dollar $ sign even if it is escaped (\$). This only affects highlighting. This file is still rendered correctly. image

sidwiesner commented 7 years ago

I'm seeing the same problem. I keep all my notes in this file, and a normal $ appears around pricing and costs all over the place. I'm guessing this is related to the integration of LaTex changes, and that just impacted me starting this last week. I also am not able to escape the $, and only get back to normal highlighting in a file by putting in 4 of them in a row ($$$$).

jonschlinkert commented 7 years ago

Noted, I'll look into it. thanks for reporting.

edit: also, since I'm not experiencing the issue (and I restarted both ST and my mac, then restarted everything again, and received a package update notification from the GitGutter, which indicates that everything I have is the latest), it's possible that the issue isn't caused by this package, or it's caused by this package when another package is installed. If you could also do some checking on your end that would be helpful.

sidwiesner commented 7 years ago

@jonschlinkert thanks. I added all my packages to ignored_packages except Package Control and Markdown Extended, then restarted Sublime Text (build 3126). I'm still seeing the same issue.

sidwiesner commented 7 years ago

It looks like it the latex-inline and latex-display matches are the issue. See https://github.com/jonschlinkert/sublime-markdown-extended/blob/master/Syntaxes/Markdown%20Extended.sublime-syntax#L1282

  latex-inline:
    - match: '(?=\$)'
      push:
        - meta_scope: text.tex.latex
        - match: '(?<=\$)'
          pop: true
        - include: scope:text.tex.latex

  latex-display:
    - match: '(?=\$\$)'
      push:
        - meta_scope: text.tex.latex
        - match: '(?<=\$\$)'
          pop: true
        - include: scope:text.tex.latex

If I use $ $ or $$ $$ separated by spaces, I can see the syntax highlighting terminate after those blocks.

sidwiesner commented 7 years ago

1 suggestion would be to limit the latex delimiters to just $$. That would certainly work for me, but not sure what is considered standard. I'm not sure what other constraints could be put on the regex to have it work in both use cases.

Another suggestion would be to have a settings flag to disable/enable the latex behavior.

ditek commented 7 years ago

Commit 2229f7baa0219fa6c92c620064eb06e93ed3b4bb doesn't have the issue. It was probably introduced in the Latex support commit as @sidwiesner mentioned.

lwolfsonkin commented 7 years ago

I believe that this is a result of the LaTeX math inclusions in the new release (#105) (which are wonderful), but there's one corner, that seems to have been missed:

This seems to cost about $3 but I'm not 100% sure

is highlighted as:

captura de tela 2017-03-18 as 18 18 01

It gets stuck in LaTeX mode after a dollar sign until it hits another one.

Ideally, $ delimited math mode would not trigger in cases like this by enforcing a second $ which doesn't have a space before it. I believe this is how it was implemented under the old LaTeX math highlighting

jonschlinkert commented 7 years ago

sorry for the delay, I started working on some fixes. I'll update this issue once I've had enough time to test for regressions

randy3k commented 7 years ago

FYI, it is how I handle latex in R Markdown.

jwarner112 commented 7 years ago

Hey all,

Just wanted to note that this issue is affecting me too. It's odd because I don't remember it doing this last year when I was writing lots of Markdown. I also speculated that it had to do with MathJax/LaTex support.

lwolfsonkin commented 7 years ago

I also noticed that it isn't possible to even escape the $. If you write \$, it still triggers the LaTeX math environment.

lrdegeest commented 7 years ago

Another strange thing re: dollar signs: when I type "$", and then type "$" again, it prints double. When I want to type "$x+y$", it prints "$x+y$$" and I have to delete the trailing dollar sign.

theterran commented 7 years ago

After installing Markdown Extended in Sublime Text 3 yesterday, I noticed this issue today as well. It happens with dollar signs in several instances, but not all; for example:

Screenshot included.

2017-05-20 screen shot sublime text 3 markdown extended syntax highlighting
willbeaufoy commented 7 years ago

I'm having the same issue. I have temporarily made a new Markdown Extended.sublime-syntax file and commented out the latex highlighting lines indicated by sidwiesner, as I don't write latex.

randy3k commented 6 years ago

should be fixed by e77e917

theterran commented 6 years ago

Fix confirmed. Updated screenshot included.

2017-07-23 screen shot sublime text 3 markdown extended syntax highlighting

Thank you!

lwolfsonkin commented 6 years ago

Great fix! Does this fix still support latex highlighting between dollar signs?

randy3k commented 6 years ago

Yes, only if there are no spaces before the closing dollar sign and no characters after it.