Skip to content

Commit

Permalink
Never hide backslash escapes in fontified code blocks
Browse files Browse the repository at this point in the history
Previously, if hiding markup and using native fontification of code blocks,
backslash escapes could get hidden inside code. See #766.
  • Loading branch information
jimporter committed Jul 14, 2024
1 parent 8aab017 commit 55959ac
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
- Don't highlight superscript/subscript in math inline/block [GH-802][]
- Fix table alignment when a column has a seperator in code block [GH-817][]
- Fix the regexp in the download languages script [GH-827][]
- Don't hide backslashes in code blocks when using `markdown-hide-markup`
and `markdown-fontify-code-blocks-natively` together [GH-766][]

* Improvements:
- Apply url-unescape against URL in an inline link [GH-805][]
Expand Down
3 changes: 2 additions & 1 deletion markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,8 @@ Group 4 matches the text inside the delimiters.")
"Property list of all Markdown syntactic properties.")

(defvar markdown-literal-faces
'(markdown-inline-code-face
'(markdown-code-face
markdown-inline-code-face
markdown-pre-face
markdown-math-face
markdown-url-face
Expand Down
26 changes: 21 additions & 5 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -2243,9 +2243,25 @@ See GH-245."
(markdown-test-range-has-property 83 93 'invisible 'markdown-markup)
(should (invisible-p 83))
(should (invisible-p 93))
(markdown-test-range-has-property 154 156 'invisible 'markdown-markup)
(should (invisible-p 154))
(should (invisible-p 156)))))
;; The backslash in the Bash script should be visible.
(should-not (invisible-p 167))
(markdown-test-range-has-property 174 176 'invisible 'markdown-markup)
(should (invisible-p 174))
(should (invisible-p 176)))))

(ert-deftest test-markdown-markup-hiding/fenced-code-blocks-fontified ()
"Test hiding markup for tilde fenced code blocks with fontification."
(let ((markdown-hide-markup t)
(markdown-fontify-code-blocks-natively t))
(markdown-test-file "outline-code.text"
(markdown-test-range-has-property 83 93 'invisible 'markdown-markup)
(should (invisible-p 83))
(should (invisible-p 93))
;; The backslash in the Bash script should be visible.
(should-not (invisible-p 167))
(markdown-test-range-has-property 174 176 'invisible 'markdown-markup)
(should (invisible-p 174))
(should (invisible-p 176)))))

(ert-deftest test-markdown-markup-hiding/escape ()
"Test hiding markup for backslash escapes."
Expand Down Expand Up @@ -4838,7 +4854,7 @@ Detail: https://github.com/jrblevin/markdown-mode/issues/392"
(markdown-test-file "outline-code.text"
;; Navigate forward at the same level
(markdown-forward-same-level 1)
(should (eq (point) 159))
(should (eq (point) 179))
(should (looking-at "^# Level one again"))))

(ert-deftest test-markdown-outline/back-to-heading-over-code-block ()
Expand Down Expand Up @@ -4927,7 +4943,7 @@ Detail: https://github.com/jrblevin/markdown-mode/issues/392"
(should (eq (point) 69))
(should (looking-at "^## Level two"))
(outline-next-visible-heading 1)
(should (eq (point) 159))
(should (eq (point) 179))
(should (looking-at "^# Level one again")))))

(ert-deftest test-markdown-outline/visibility-with-metadata ()
Expand Down
2 changes: 2 additions & 0 deletions tests/outline-code.text
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#!/bin/bash

# In a code block, this shouldn't be a header

echo -e "foo\nbar"
~~~

# Level one again
Expand Down

0 comments on commit 55959ac

Please sign in to comment.