Skip to content

Commit

Permalink
Font lock and filling for Pandoc fancy_lists
Browse files Browse the repository at this point in the history
From the Pandoc User's Guide

> The `fancy_lists` extension also allows '#' to be used as an ordered
> list marker in place of a numeral:
>
> #. one
> #. two
  • Loading branch information
jrblevin committed Jul 15, 2015
1 parent 3ca7a12 commit 4b8ac27
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ Group 5 matches the reference label.")
"Regexp identifying Markdown headers.")

(defconst markdown-regex-header-1-atx
"^\\(#\\)[ \t]*\\(.+?\\)[ \t]*\\(#*\\)$"
"^\\(#\\)[ \t]*\\([^\\.].*?\\)[ \t]*\\(#*\\)$"
"Regular expression for level 1 atx-style (hash mark) headers.")

(defconst markdown-regex-header-2-atx
Expand Down Expand Up @@ -1259,7 +1259,7 @@ Group 2 matches the key sequence.")
"Regular expression for matching preformatted text sections.")

(defconst markdown-regex-list
"^\\([ \t]*\\)\\([0-9]+\\.\\|[\\*\\+-]\\)\\([ \t]+\\)"
"^\\([ \t]*\\)\\([0-9#]+\\.\\|[\\*\\+-]\\)\\([ \t]+\\)"
"Regular expression for matching list items.")

(defconst markdown-regex-bold
Expand Down Expand Up @@ -4681,7 +4681,7 @@ This is an exact copy of `line-number-at-pos' for use in emacs21."
"Return prefix for filling paragraph or nil if not determined."
(cond
;; List item inside blockquote
((looking-at "^[ \t]*>[ \t]*\\([0-9]+\\.\\|[*+-]\\)[ \t]+")
((looking-at "^[ \t]*>[ \t]*\\(\\(?:[0-9]+\\|#\\)\\.\\|[*+-]\\)[ \t]+")
(replace-regexp-in-string
"[0-9\\.*+-]" " " (match-string-no-properties 0)))
;; Blockquote
Expand Down Expand Up @@ -4789,7 +4789,7 @@ if ARG is omitted or nil."
"\f" ; starts with a literal line-feed
"[ \t\f]*$" ; space-only line
"[ \t]*[*+-][ \t]+" ; unordered list item
"[ \t]*[0-9]+\\.[ \t]+" ; ordered list item
"[ \t]*\\(?:[0-9]+\\|#\\)\\.[ \t]+" ; ordered list item
"[ \t]*\\[\\S-*\\]:[ \t]+" ; link ref def
)
"\\|"))
Expand Down
16 changes: 16 additions & 0 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -2593,6 +2593,22 @@ See `paragraph-separate'."
(markdown-test-range-has-face 24 26 markdown-pre-face)
(markdown-test-range-has-face 28 30 markdown-pre-face)))

;;; Tests for other extensions:

(ert-deftest test-markdown-ext/pandoc-fancy-lists ()
"Test basic support for font lock and filling of Pandoc 'fancy lists'."
(markdown-test-string " #. abc\ndef\n"
;; font lock
(markdown-test-range-has-face 1 1 nil)
(markdown-test-range-has-face 2 3 markdown-list-face)
(markdown-test-range-has-face 4 11 nil)
;; filling
(forward-line)
(markdown-indent-region (line-beginning-position) (line-end-position) nil)
(should (string-equal (buffer-string) " #. abc\n def\n"))
(markdown-indent-region (line-beginning-position) (line-end-position) nil)
(should (string-equal (buffer-string) " #. abc\n def\n"))))

(provide 'markdown-test)

;;; markdown-test.el ends here

0 comments on commit 4b8ac27

Please sign in to comment.