Skip to content

Commit

Permalink
Don't highlight wiki links in code blocks
Browse files Browse the repository at this point in the history
See #17
  • Loading branch information
jrblevin committed Dec 16, 2015
1 parent 1ed32c3 commit d299a37
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
21 changes: 10 additions & 11 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -5235,18 +5235,17 @@ and highlight accordingly."
(goto-char from)
(save-match-data
(while (re-search-forward markdown-regex-wiki-link to t)
(let ((highlight-beginning (match-beginning 1))
(highlight-end (match-end 1))
(file-name
(markdown-convert-wiki-link-to-filename
(markdown-wiki-link-link))))
(if (file-exists-p file-name)
(when (not (markdown-code-block-at-point-p))
(let ((highlight-beginning (match-beginning 1))
(highlight-end (match-end 1))
(file-name
(markdown-convert-wiki-link-to-filename
(markdown-wiki-link-link))))
(if (file-exists-p file-name)
(markdown-highlight-wiki-link
highlight-beginning highlight-end markdown-link-face)
(markdown-highlight-wiki-link
highlight-beginning highlight-end markdown-link-face)
(markdown-highlight-wiki-link
highlight-beginning highlight-end markdown-link-face)
(markdown-highlight-wiki-link
highlight-beginning highlight-end markdown-missing-link-face))))))
highlight-beginning highlight-end markdown-missing-link-face)))))))

(defun markdown-extend-changed-region (from to)
"Extend region given by FROM and TO so that we can fontify all links.
Expand Down
2 changes: 2 additions & 0 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -2545,6 +2545,8 @@ body"
(should (eq (markdown-next-link) 155))
(should (string-equal (markdown-wiki-link-link) "inline"))
(markdown-test-range-has-property 155 164 'font-lock-face markdown-link-face)
;; Check wiki links in code blocks
(markdown-test-range-has-face 360 395 markdown-pre-face)
;; Remove temporary files
(delete-file fn)
)))
Expand Down
14 changes: 14 additions & 0 deletions tests/wiki-links.text
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,17 @@ Here's a second link, an aliased link [[first|second]], at point 73.
The first two links are invalid. This third link, [[inline]], is a
valid link since the file `inline.text` exists. The last link is at
point 155.

Bracketed expressions in code blocks should not be matched as wiki
links:

```
{
:user {
:repositories [["clojars" {:sign-releases false}]]
:plugins [
[lein-cloverage "1.0.6"]
]
}
}
```

0 comments on commit d299a37

Please sign in to comment.