Skip to content

Commit

Permalink
Fix carets in math inline issue
Browse files Browse the repository at this point in the history
  • Loading branch information
syohex committed Oct 17, 2023
1 parent c12adcf commit ec2d21a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

*Under development*

* Bug fixes:
- Don't highlight superscript/subscript in math inline/block [GH-802][]

[gh-802]: https://github.com/jrblevin/markdown-mode/issues/802

# Markdown Mode 2.6

* **Breaking changes:**
Expand Down
7 changes: 6 additions & 1 deletion markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,10 @@ If POS is not given, use point instead."
thereis (memq face faces))
(memq face-prop faces))))

(defsubst markdown--math-block-p (&optional pos)
(when markdown-enable-math
(markdown--face-p (or pos (point)) '(markdown-math-face))))

(defun markdown-syntax-propertize-extend-region (start end)
"Extend START to END region to include an entire block of text.
This helps improve syntax analysis for block constructs.
Expand Down Expand Up @@ -3588,7 +3592,8 @@ SEQ may be an atom or a sequence."
(when (markdown-search-until-condition
(lambda () (and (not (markdown-code-block-at-point-p))
(not (markdown-inline-code-at-point-p))
(not (markdown-in-comment-p))))
(not (markdown-in-comment-p))
(not (markdown--math-block-p))))
markdown-regex-sub-superscript last t)
(let* ((subscript-p (string= (match-string 2) "~"))
(props
Expand Down
12 changes: 12 additions & 0 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -6183,6 +6183,18 @@ Detail: https://github.com/jrblevin/markdown-mode/issues/352"
(markdown-test-range-has-face 9 9 'markdown-math-face)
(markdown-test-range-has-face 10 11 'markdown-markup-face))))

(ert-deftest test-markdown-math/caret-in-math-inline ()
"Test for carets in math inline.
Details: https://github.com/jrblevin/markdown-mode/issues/802"
(let ((markdown-enable-math t))
(markdown-test-string "$a^b^c$"
(markdown-test-range-has-face 3 3 'markdown-math-face)
(markdown-test-range-has-face 5 5 'markdown-math-face))

(markdown-test-string "$$a^b^c$$"
(markdown-test-range-has-face 4 4 'markdown-math-face)
(markdown-test-range-has-face 6 6 'markdown-math-face))))

(ert-deftest test-markdown-math/math-inline-small-buffer ()
"Test that font-lock parsing works with a single dollar."
(let ((markdown-enable-math t))
Expand Down

0 comments on commit ec2d21a

Please sign in to comment.