From e0aeee2dc5fc898eae28dd6bbacce232387fb49a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Marks?= Date: Thu, 14 May 2026 14:08:02 -0400 Subject: [PATCH] Fix markdown-ts-mode atx_heading face computation (bug#81042) The grammar reports leading spaces as part of the atx_heading "marker" and we cannot use the length of the marker as a result. Instead, count the number of consecutive # after any blanks to determine its "level." * lisp/textmodes/markdown-ts-mode.el (markdown-ts--fontify-atx-heading): Count the octothorpes rather than using the length of the marker node's text. --- lisp/textmodes/markdown-ts-mode.el | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lisp/textmodes/markdown-ts-mode.el b/lisp/textmodes/markdown-ts-mode.el index 515d0620127..6430e2c8119 100644 --- a/lisp/textmodes/markdown-ts-mode.el +++ b/lisp/textmodes/markdown-ts-mode.el @@ -1093,8 +1093,12 @@ CommonMark they are decorative and must be preceded by a space or tab." (let* ((n-start (treesit-node-start node)) (n-end (treesit-node-end node)) (face (let ((marker (treesit-node-child node 0))) - (intern (format "markdown-ts-heading-%d" - (length (treesit-node-text marker t))))))) + (intern + (format "markdown-ts-heading-%d" + (progn + (string-match "[[:blank:]]*\\([#]+\\)" + (treesit-node-text marker t)) + (- (match-end 1) (match-beginning 1)))))))) (font-lock--remove-face-from-text-property n-start n-end 'face face) (font-lock-append-text-property n-start (1- n-end) 'face face) (save-excursion