Function: markdown-ts--fill-paragraph
markdown-ts--fill-paragraph is a byte-compiled function defined in
markdown-ts-mode.el.gz.
Signature
(markdown-ts--fill-paragraph &optional JUSTIFY)
Documentation
Fill the current paragraph, respecting Markdown block structure.
This function prevents filling inside blocks matched by
markdown-ts--fill-unfillable-block-query, and fills within list
items without merging adjacent items. JUSTIFY is as in
fill-paragraph.
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/markdown-ts-mode.el.gz
(defun markdown-ts--fill-paragraph (&optional justify)
"Fill the current paragraph, respecting Markdown block structure.
This function prevents filling inside blocks matched by
`markdown-ts--fill-unfillable-block-query', and fills within list
items without merging adjacent items. JUSTIFY is as in
`fill-paragraph'."
(cond*
;; Don't fill inside unfillable blocks. Use a query against the
;; root node because `treesit-node-at' may not return a node
;; inside the block when point is on anonymous (unnamed) text.
((treesit-query-capture
(treesit-buffer-root-node 'markdown)
markdown-ts--fill-unfillable-block-query
(point) (min (1+ (point)) (point-max)))
t)
;; Fill within the enclosing list item. Use
;; `markdown-ts--list-item-at-point' which handles block quote
;; markers. When the list item is inside a block quote, delegate
;; to the block quote filler which handles `> ' prefixes correctly.
((bind-and* (item (markdown-ts--list-item-at-point)))
(if (treesit-parent-until item "\\`block_quote\\'")
(markdown-ts--fill-block-quote justify)
(markdown-ts--fill-list-item item justify)))
;; Point is on a blank line before a list. If the next
;; non-whitespace position falls inside a list item, fill that item.
((save-excursion
(beginning-of-line)
(looking-at-p "[ \t]*$"))
(and-let* ((next-pos (save-excursion
(skip-chars-forward " \t\n")
(point)))
(next-node (treesit-node-at next-pos 'markdown))
(item (treesit-parent-until
next-node "\\`list_item\\'")))
(markdown-ts--fill-list-item item justify)))
;; Fill within a block quote. Narrow to the paragraph node at
;; point's nesting level so lines with different `> ' depths
;; are not merged.
((treesit-parent-until
(treesit-node-at
(save-excursion (back-to-indentation) (point))
'markdown)
"\\`block_quote\\'")
(markdown-ts--fill-block-quote justify))
;; Fill within an HTML comment. The node type is "html_block"
;; in grammar v0.4.x and "comment" in some other versions.
((bind-and* (block (let ((n (treesit-node-at (point) 'markdown)))
(or (treesit-parent-until
n "\\`\\(?:html_block\\|comment\\)\\'")
(and (member (treesit-node-type n)
'("html_block" "comment"))
n)))))
(markdown-ts--fill-html-comment block justify))
;; Default: let fill-paragraph handle it.
(t nil)))