branch: elpa/markdown-mode commit ccb3a54ed112369cdaebb629b856cef483b11a9b Author: Shohei YOSHIDA <syo...@gmail.com> Commit: Shohei YOSHIDA <syo...@gmail.com>
Support enable highlighting --- CHANGES.md | 2 ++ README.md | 5 ++++- markdown-mode.el | 28 ++++++++++++++++++++++++++++ tests/markdown-test.el | 10 ++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index aa1aa9a..4cae4f4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,7 @@ - Add `markdown-insert-foldable-block` function [GH-598][] - Add `markdown-table-align-p` flag [GH-625][] Control table alignment after table operation + - Support highlighting syntax like Obsidian, Quilt. [GH-652][] * Improvements: - Correct indirect buffer's indentation in `markdown-edit-code-block` [GH-375][] @@ -113,6 +114,7 @@ [gh-640]: https://github.com/jrblevin/markdown-mode/issues/640 [gh-641]: https://github.com/jrblevin/markdown-mode/issues/641 [gh-649]: https://github.com/jrblevin/markdown-mode/issues/649 + [gh-652]: https://github.com/jrblevin/markdown-mode/issues/652 # Markdown Mode 2.4 diff --git a/README.md b/README.md index b3c21c3..342e1de 100644 --- a/README.md +++ b/README.md @@ -907,6 +907,9 @@ provides an interface to all of the possible customizations: `markdown-insert-list-item` inserts enumerated numbers for ordered list marker. While nil, it always inserts `1.`. + * `markdown-enable-highlighting-syntax` - font lock for highlighting + syntax like Obsidian, Quilt(default: `nil`). + Additionally, the faces used for syntax highlighting can be modified to your liking by issuing <kbd>M-x customize-group RET markdown-faces</kbd> or by using the "Markdown Faces" link at the bottom of the mode @@ -992,7 +995,7 @@ by `markdown-mode` and `gfm-mode` as described below. region will be placed inside the code block. You will be prompted for the name of the language, but may press enter to continue without naming a language. - + In addition, in `gfm-mode`, GFM code blocks can be inserted via the option `markdown-gfm-use-electric-backquote`. If the option `markdown-code-block-braces` is set to `t`, code blocks inserted with diff --git a/markdown-mode.el b/markdown-mode.el index 5db1068..9c52cd3 100644 --- a/markdown-mode.el +++ b/markdown-mode.el @@ -347,6 +347,13 @@ Math support can be enabled, disabled, or toggled later using :safe 'booleanp :package-version '(markdown-mode . "2.4")) +(defcustom markdown-enable-highlighting-syntax nil + "Enable highlighting syntax." + :group 'markdown + :type 'boolean + :safe 'booleanp + :package-version '(markdown-mode . "2.5")) + (defcustom markdown-css-paths nil "List of URLs of CSS files to link to in the output XHTML." :group 'markdown @@ -1043,6 +1050,15 @@ Group 3 matches all attributes and whitespace following the tag name.") "\\(&#?[[:alnum:]]+;\\)" "Regular expression for matching HTML entities.") +(defconst markdown-regex-highlighting + "\\(?1:^\\|[^\\]\\)\\(?2:\\(?3:==\\)\\(?4:[^ \n\t\\]\\|[^ \n\t]\\(?:.\\|\n[^\n]\\)*?[^\\ ]\\)\\(?5:==\\)\\)" +"Regular expression for matching highlighting text. +Group 1 matches the character before the opening equal, if any, +ensuring that it is not a backslash escape. +Group 2 matches the entire expression, including delimiters. +Groups 3 and 5 matches the opening and closing delimiters. +Group 4 matches the text inside the delimiters.") + ;;; Syntax ==================================================================== @@ -1979,6 +1995,11 @@ For example, this applies to plain angle bracket URLs: "Face for HTML entities." :group 'markdown-faces) +(defface markdown-highlighting-face + '((t (:background "yellow" :foreground "black"))) + "Face for highlighting." + :group 'markdown-faces) + (defcustom markdown-header-scaling nil "Whether to use variable-height faces for headers. When non-nil, `markdown-header-face' will inherit from @@ -2171,6 +2192,9 @@ Depending on your font, some reasonable choices are: (,markdown-regex-strike-through . ((3 markdown-markup-properties) (4 'markdown-strike-through-face) (5 markdown-markup-properties))) + (markdown--match-highlighting . ((3 markdown-markup-properties) + (4 'markdown-highlighting-face) + (5 markdown-markup-properties))) (,markdown-regex-line-break . (1 'markdown-line-break-face prepend)) (markdown-fontify-sub-superscripts) (markdown-match-inline-attributes . ((0 markdown-markup-properties prepend))) @@ -2891,6 +2915,10 @@ When FACELESS is non-nil, do not return matches where faces have been applied." (match-beginning 4) (match-end 4))) t))))) +(defun markdown--match-highlighting (last) + (when markdown-enable-highlighting-syntax + (re-search-forward markdown-regex-highlighting last t))) + (defun markdown-match-math-generic (regex last) "Match REGEX from point to LAST. REGEX is either `markdown-regex-math-inline-single' for matching diff --git a/tests/markdown-test.el b/tests/markdown-test.el index cbc1bbc..67cf3a1 100644 --- a/tests/markdown-test.el +++ b/tests/markdown-test.el @@ -3561,6 +3561,16 @@ across blocks]" (markdown-test-range-has-face 29 37 'markdown-html-attr-value-face) (markdown-test-range-has-face 38 38 'markdown-html-tag-delimiter-face))) +(ert-deftest test-markdown-font-lock/highlighting-syntax () + "Test highlighting syntax ==foo==." + (let ((markdown-enable-highlighting-syntax t)) + (markdown-test-string "==foo==" + (markdown-test-range-has-face 1 2 'markdown-markup-face) + (markdown-test-range-has-face 3 5 'markdown-highlighting-face) + (markdown-test-range-has-face 6 7 'markdown-markup-face))) + (markdown-test-string "==foo==" + (markdown-test-range-has-face 1 7 nil))) + ;;; Markdown Parsing Functions: (ert-deftest test-markdown-parsing/extend-region-function ()