Skip to content

Commit

Permalink
Markup hiding for italics, bold, code, and kbd tags
Browse files Browse the repository at this point in the history
  • Loading branch information
jrblevin committed Jun 9, 2017
1 parent 8390d07 commit fd9eb1c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 8 deletions.
20 changes: 12 additions & 8 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -2095,6 +2095,10 @@ START and END delimit region to propertize."

;;; Markup Hiding

(defconst markdown-markup-properties
'(face markdown-markup-face invisible markdown-markup)
"List of properties and values to apply to markup.")

(defcustom markdown-hide-markup nil
"Determines whether markup in the buffer will be hidden.
When set to nil, all markup is displayed in the buffer as it
Expand Down Expand Up @@ -2497,12 +2501,12 @@ See `font-lock-syntactic-face-function' for details."
(2 markdown-markup-face)
(3 markdown-metadata-value-face)))
(markdown-match-hr . markdown-header-delimiter-face)
(markdown-match-code . ((1 markdown-markup-face)
(markdown-match-code . ((1 markdown-markup-properties)
(2 markdown-inline-code-face)
(3 markdown-markup-face)))
(,markdown-regex-kbd . ((1 markdown-markup-face)
(3 markdown-markup-properties)))
(,markdown-regex-kbd . ((1 markdown-markup-properties)
(2 markdown-inline-code-face)
(3 markdown-markup-face)))
(3 markdown-markup-properties)))
(markdown-fontify-angle-uris)
(,markdown-regex-list . (2 markdown-list-face))
(,markdown-regex-footnote . ((1 markdown-markup-face) ; [^
Expand All @@ -2524,12 +2528,12 @@ See `font-lock-syntactic-face-function' for details."
(markdown-match-math-double . ((1 markdown-markup-face prepend)
(2 markdown-math-face append)
(3 markdown-markup-face prepend)))
(markdown-match-bold . ((1 markdown-markup-face prepend)
(markdown-match-bold . ((1 markdown-markup-properties prepend)
(2 markdown-bold-face append)
(3 markdown-markup-face prepend)))
(markdown-match-italic . ((1 markdown-markup-face prepend)
(3 markdown-markup-properties prepend)))
(markdown-match-italic . ((1 markdown-markup-properties prepend)
(2 markdown-italic-face append)
(3 markdown-markup-face prepend)))
(3 markdown-markup-properties prepend)))
(markdown-fontify-plain-uris)
(,markdown-regex-email . markdown-link-face)
(,markdown-regex-line-break . (1 markdown-line-break-face prepend))
Expand Down
52 changes: 52 additions & 0 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -1871,6 +1871,58 @@ the opening bracket of [^2], and then subsequent functions would kill [^2])."
(should (string-equal (buffer-string) " - [X] item\n - [ ] "))
(should (= (point) 28))))

;;; Markup hiding tests:

(ert-deftest test-markdown-markup-hiding/italics-1 ()
"Test hiding markup for italics."
(markdown-test-file "inline.text"
(goto-char 9)
(should (looking-at "\*italic\*"))
(markdown-test-range-has-property (point) (point) 'invisible 'markdown-markup)
(should-not (invisible-p (point)))
(should-not (invisible-p (+ 1 (point))))
(markdown-toggle-markup-hiding t)
(should (invisible-p (point)))
(should-not (invisible-p (+ 1 (point))))))

(ert-deftest test-markdown-markup-hiding/bold-1 ()
"Test hiding markup for bold."
(markdown-test-file "inline.text"
(goto-char 27)
(should (looking-at "\*\*bold\*\*"))
(markdown-test-range-has-property (point) (1+ (point)) 'invisible 'markdown-markup)
(should-not (invisible-p (point)))
(should-not (invisible-p (+ 1 (point))))
(should-not (invisible-p (+ 2 (point))))
(markdown-toggle-markup-hiding t)
(should (invisible-p (point)))
(should (invisible-p (+ 1 (point))))
(should-not (invisible-p (+ 2 (point))))))

(ert-deftest test-markdown-markup-hiding/code-1 ()
"Test hiding markup for inline code."
(markdown-test-file "inline.text"
(goto-char 45)
(should (looking-at "`code`"))
(markdown-test-range-has-property (point) (point) 'invisible 'markdown-markup)
(should-not (invisible-p (point)))
(should-not (invisible-p (1+ (point))))
(markdown-toggle-markup-hiding t)
(should (invisible-p (point)))
(should-not (invisible-p (1+ (point))))))

(ert-deftest test-markdown-markup-hiding/kbd-1 ()
"Test hiding markup for <kbd> tags."
(markdown-test-string "<kbd>C-c C-x C-m</kbd>"
(markdown-test-range-has-property (point) (+ 4 (point)) 'invisible 'markdown-markup)
(should-not (invisible-p (point))) ;; part of <kbd>
(should-not (invisible-p (+ 4 (point)))) ;; part of <kbd>
(should-not (invisible-p (+ 5 (point)))) ;; inside <kbd>
(markdown-toggle-markup-hiding t)
(should (invisible-p (point))) ;; part of <kbd>
(should (invisible-p (+ 4 (point)))) ;; part of <kbd>
(should-not (invisible-p (+ 5 (point)))))) ;; inside <kbd>

;;; Font lock tests:

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

0 comments on commit fd9eb1c

Please sign in to comment.