Closed saf-dmitry closed 1 year ago
I think this would just need to add an extra check to not fontify backslash escapes when fontification has already added one of the following faces to the backslash:
markdown-inline-code-face
markdown-pre-face
markdown-math-face
That should be pretty straightforward with some new markdown-match-escape
function that checks the backslash's face before returning whether it matched.
Maybe there's a cleaner way to do that though?
I think this would just need to add an extra check to not fontify backslash escapes when fontification has already added one of the following faces to the backslash:
markdown-inline-code-face
markdown-pre-face
markdown-math-face
That should be pretty straightforward with some new
markdown-match-escape
function that checks the backslash's face before returning whether it matched.
Yes, that is how I would approach this. Another point to consider is, it should fontify only backslashes not preceding by another backslashes, i.e., in \\
only the first backslash should be fontified because the second backslash stands for itself. Generally speaking, in something like \\\\\\
only odd, i.e., 1, 3, and 5 backslash positions should be fontified.
Yes, that is how I would approach this. Another point to consider is, it should fontify only backslashes not preceding by another backslashes, i.e., in
\\
only the first backslash should be fontified because the second backslash stands for itself. Generally speaking, in something like\\\\\\
only odd, i.e., 1, 3, and 5 backslash positions should be fontified.
This part should already work. The regexp is (approximately) \\.
, so it'll match a backslash followed by anything. That means it'll see the first backslash, then skip past the next one before trying again. If you type a bunch of backslashes in a row into a markdown-mode
buffer, it should do the right thing.
@saf-dmitry Ok, hopefully my PR fixes this. Can you try it out to see?
I just played with it a little bit and it looks good.
The markdown-literal-faces
variable can be re-used for various other purposes as well, so I would consider adding the following faces to the list:
markdown-url-face
markdown-plain-url-face
markdown-language-keyword-face
markdown-language-info-face
markdown-metadata-key-face
markdown-metadata-value-face
markdown-html-entity-face
markdown-html-tag-name-face
markdown-html-tag-delimiter-face
markdown-html-attr-name-face
markdown-html-attr-value-face
And maybe these faces too:
markdown-link-title-face
markdown-reference-face
markdown-footnote-marker-face
markdown-line-break-face
markdown-comment-face
markdown-link-title-face
Link titles look like they support escape sequences, so I think they should be excluded from markdown-literal-faces
. The others make sense though (I think...)
It seems that the current solution works in code blocks only if native fontification is disabled (which is the default). If the variable markdown-fontify-code-blocks-natively
is set to t
, the backslash fontification issue comes again:
I think we should reopen the issue.
It seems that the current solution works in code blocks only if native fontification is disabled (which is the default). If the variable
markdown-fontify-code-blocks-natively
is set tot
, the backslash fontification issue comes again:
@saf-dmitry Thanks for noticing, here's a fix: https://github.com/jrblevin/markdown-mode/pull/836
Backslashes inside math and code are fontified as Markdown markup.
Expected Behavior
Backslashes as part of math or code are fontified according to the type of content (i.e., LaTeX or corresponding code language).
Actual Behavior
Backslashes inside math or code are fontified and propertized as Markdown markup:
This is especially misleading when hiding Markdown syntax is enabled.
Steps to Reproduce
See the examples above.
Backtrace
Software Versions
Note
Commit ae1085a