From aad170d1edf70485995aafbabf4af6f4bcbca192 Mon Sep 17 00:00:00 2001 From: Rahul Martim Juliato Date: Tue, 19 May 2026 17:26:09 -0300 Subject: [PATCH] markdown-ts-mode: hide fence lines in view-mode (bug#81081) * lisp/textmodes/markdown-ts-mode.el (markdown-ts--fontify-delimiter): When `markdown-ts-hide-markup' is enabled in `markdown-ts-view-mode', also hide the whole line containing a `fenced_code_block_delimiter' (including its terminating newline) so Eldoc/LSP markdown snippets render without stray blank lines around the code block. Scoped to view-mode and to fenced delimiters on purpose: the same handler is shared by inline delimiters (emphasis, code span, link brackets) where munching surrounding whitespace would collapse word separators, and tuning rendering for hide-markup-while-editing is not a goal. --- lisp/textmodes/markdown-ts-mode.el | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lisp/textmodes/markdown-ts-mode.el b/lisp/textmodes/markdown-ts-mode.el index 01b7ac09995..7f87ff5d0bc 100644 --- a/lisp/textmodes/markdown-ts-mode.el +++ b/lisp/textmodes/markdown-ts-mode.el @@ -842,8 +842,27 @@ OVERRIDE, START, and END are passed through to (treesit-node-start node) (treesit-node-end node) 'markdown-ts-delimiter override start end) (when markdown-ts-hide-markup - (put-text-property (treesit-node-start node) (treesit-node-end node) - 'invisible 'markdown-ts--markup))) + (if (and (derived-mode-p 'markdown-ts-view-mode) + (equal (treesit-node-type node) "fenced_code_block_delimiter")) + ;; In view-mode only, hide the whole line containing the fence + ;; (including its terminating newline) so Eldoc/LSP markdown + ;; snippets render without stray blank lines around the code + ;; block. Restricted to view-mode because hide-markup while + ;; editing already has UX hazards (point movement, backspace + ;; across invisible regions) and we should not tune rendering + ;; for that mode. Restricted to fenced_code_block_delimiter + ;; because the same handler is shared by inline delimiters + ;; (emphasis, code span, link brackets) where munching + ;; surrounding whitespace would collapse word separators. + (save-excursion + (goto-char (treesit-node-start node)) + (let ((bol (pos-bol)) + (eol+1 (progn (goto-char (treesit-node-end node)) + (min (point-max) (1+ (pos-eol)))))) + (put-text-property bol eol+1 + 'invisible 'markdown-ts--markup))) + (put-text-property (treesit-node-start node) (treesit-node-end node) + 'invisible 'markdown-ts--markup)))) (defun markdown-ts--fontify-atx-delimiter (node override start end &rest _) "Fontify atx_heading delimiter NODE and optionally hide its markup.