Skip to content

Commit

Permalink
Make fill functions respect Pandoc pipe blocks
Browse files Browse the repository at this point in the history
Closes GH-144.
  • Loading branch information
jrblevin committed Jun 15, 2017
1 parent 669815e commit e8197fc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
- Add font lock support for Pandoc inline footnotes. ([GH-81][])
- Raise footnote markers and inline footnote text, and
optionally hide markup.
- Filling with now respects Pandoc line blocks. ([GH-144][])

* Improvements:

Expand Down Expand Up @@ -152,6 +153,7 @@
[gh-123]: https://github.com/jrblevin/markdown-mode/issues/123
[gh-130]: https://github.com/jrblevin/markdown-mode/issues/130
[gh-134]: https://github.com/jrblevin/markdown-mode/issues/134
[gh-144]: https://github.com/jrblevin/markdown-mode/issues/144
[gh-172]: https://github.com/jrblevin/markdown-mode/issues/172
[gh-176]: https://github.com/jrblevin/markdown-mode/issues/176
[gh-185]: https://github.com/jrblevin/markdown-mode/issues/185
Expand Down
12 changes: 12 additions & 0 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -3333,6 +3333,11 @@ Set match data for `markdown-regex-header'."
(set-match-data match-data)
t)))

(defun markdown-pipe-at-bol-p ()
"Return non-nil if the line begins with a pipe symbol.
This may be useful for tables and Pandoc's line_blocks extension."
(char-equal (char-after (point-at-bol)) ?|))


;;; Markdown Font Lock Matching Functions =====================================

Expand Down Expand Up @@ -7891,6 +7896,10 @@ return the number of paragraphs left to move."
;; Move point past whitespace following list marker.
((looking-at markdown-regex-list)
(goto-char (match-end 0)))
;; Move point past whitespace following pipe at beginning of line
;; to handle Pandoc line blocks.
((looking-at "^|\\s-*")
(goto-char (match-end 0)))
;; Return point if the paragraph passed was a code block.
((markdown-code-block-at-pos (point-at-bol 2))
(goto-char start)))))
Expand Down Expand Up @@ -8356,6 +8365,7 @@ position."
"[ \t]*\\(?:[0-9]+\\|#\\)\\.[ \t]+" ; ordered list item
"[ \t]*\\[\\S-*\\]:[ \t]+" ; link ref def
"[ \t]*:[ \t]+" ; definition
"^|" ; table or Pandoc line block
)
"\\|"))
(set
Expand Down Expand Up @@ -8394,6 +8404,8 @@ position."
'markdown-inside-link-p nil t)
(add-hook 'fill-nobreak-predicate
'markdown-line-is-reference-definition-p nil t)
(add-hook 'fill-nobreak-predicate
'markdown-pipe-at-bol-p nil t)

;; Indentation
(setq indent-line-function markdown-indent-function)
Expand Down
15 changes: 15 additions & 0 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -4494,6 +4494,21 @@ paragraph 2")))))
(fill-paragraph)
(should (string-equal (buffer-string) "aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa\naaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa\naaa aaa [aaa aaa aaa aaa](aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) aaa aaa aaa aaa aaa."))))

(ert-deftest test-markdown-filling/pandoc-line-blocks ()
"Filling should leave Pandoc line blocks undisturbed.
This includes preserving whitespace after the pipe."
(let ((text "| The limerick packs laughs anatomical
| In space that is quite economical.
| But the good ones I've seen
| So seldom are clean
| And the clean ones so seldom are comical

| 200 Main St.
| Berkeley, CA 94718"))
(markdown-test-string text
(fill-region (point-min) (point-max))
(should (string-equal (buffer-string) text)))))

;;; Export tests:

(ert-deftest test-markdown-hook/xhtml-standalone ()
Expand Down

0 comments on commit e8197fc

Please sign in to comment.