Skip to content

Commit

Permalink
Handle false positive italics across list items
Browse files Browse the repository at this point in the history
Simply checking for `markdown-list-face` in the potential italic range
seems to be a safer and more general approach.  It also covers the
hanging list test case in 6aafece and is more efficient since we've
already done the hard work of parsing the nested lists.

Also, remove an ambiguous test case. With the example below, Markdown.pl
does indeed generate a list item with italics:

* foo_bar
foo_bar
  • Loading branch information
jrblevin committed Jan 10, 2016
1 parent 6aafece commit 84d94aa
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
13 changes: 2 additions & 11 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -2434,15 +2434,6 @@ Return nil otherwise."
(match-beginning 5) (match-end 5)))
(goto-char (1+ (match-end 0)))))

(defun markdown-list-p (pos)
(save-excursion
(goto-char pos)
(goto-char (line-beginning-position))
(looking-at-p markdown-regex-list)))

(defun markdown-same-line-p (pos1 pos2)
(= (markdown-line-number-at-pos pos1) (markdown-line-number-at-pos pos2)))

(defun markdown-match-italic (last)
"Match inline italics from the point to LAST."
(let ((regex (if (eq major-mode 'gfm-mode)
Expand All @@ -2453,11 +2444,11 @@ Return nil otherwise."
((markdown-range-property-any
begin end 'face (list markdown-inline-code-face
markdown-bold-face
markdown-list-face
markdown-math-face))
(goto-char (1+ (match-end 0)))
(markdown-match-italic last))
((or (markdown-same-line-p begin end)
(not (or (markdown-list-p begin) (markdown-list-p end))))
(t
(set-match-data (list (match-beginning 1) (match-end 1)
(match-beginning 2) (match-end 2)
(match-beginning 3) (match-end 3)
Expand Down
7 changes: 0 additions & 7 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,6 @@ the opening bracket of [^2], and then subsequent functions would kill [^2])."

(ert-deftest test-markdown-font-lock/italics-6 ()
"Test multiline italics across list items."
:expected-result :failed
(markdown-test-string
"* something about function foo_bar
* something else about foo_bar"
Expand All @@ -1760,12 +1759,6 @@ the opening bracket of [^2], and then subsequent functions would kill [^2])."
"foo_bar
* foo_bar"
(markdown-test-range-has-face 4 7 nil)
(markdown-test-range-has-face 11 14 nil))

(markdown-test-string
"* foo_bar
foo_bar"
(markdown-test-range-has-face 6 9 nil)
(markdown-test-range-has-face 11 14 nil)))

(ert-deftest test-markdown-font-lock/italics-after-hr ()
Expand Down

0 comments on commit 84d94aa

Please sign in to comment.