Function: markdown-ts--fontify-non-ts-code-block
markdown-ts--fontify-non-ts-code-block is a byte-compiled function
defined in markdown-ts-mode.el.gz.
Signature
(markdown-ts--fontify-non-ts-code-block NODE OVERRIDE START END &rest _)
Documentation
Fontify code_fence_content NODE using a non-tree-sitter mode.
Apply the code-block mode's conventional font-lock in a temporary
buffer. OVERRIDE, START, and END are passed through to
treesit-fontify-with-override.
Cache results to avoid fontification of unchanged code blocks.
NODE should already have passed through
markdown-ts--code-block-ts-language which may have classified this
node as a non-ts mode.
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/markdown-ts-mode.el.gz
(defun markdown-ts--fontify-non-ts-code-block (node override start end &rest _)
"Fontify code_fence_content NODE using a non-tree-sitter mode.
Apply the code-block mode's conventional font-lock in a temporary
buffer. OVERRIDE, START, and END are passed through to
`treesit-fontify-with-override'.
Cache results to avoid fontification of unchanged code blocks.
NODE should already have passed through
`markdown-ts--code-block-ts-language' which may have classified this
node as a non-ts mode."
(when-let* ((_ markdown-ts-fontify-code-blocks-natively)
(lang (markdown-ts--language-at-node node))
(mode (alist-get lang markdown-ts--code-block-non-ts-modes))
(tick (buffer-chars-modified-tick))
(block-start (treesit-node-start node))
;; Cannot rely on anything set in
;; `markdown-ts--fontify-code-block' that runs after this
;; function runs.
(node-start (save-excursion
(goto-char (treesit-node-start node))
(line-beginning-position)))
(node-end (save-excursion
(goto-char (treesit-node-end node))
(skip-chars-backward " \t")
(point))))
(when (> node-end node-start)
(unless (eq tick markdown-ts--non-ts-fontify-cache-tick)
(clrhash markdown-ts--non-ts-fontify-cache))
(let* ((cache-key (cons lang (secure-hash
'sha256
(current-buffer) node-start node-end)))
(props
(or (gethash cache-key
markdown-ts--non-ts-fontify-cache)
(let ((result
(markdown-ts--fontify-non-ts-collect-faces
mode node-start node-end)))
(puthash cache-key result
markdown-ts--non-ts-fontify-cache)
(setq markdown-ts--non-ts-fontify-cache-tick tick)
result))))
(dolist (range props)
(treesit-fontify-with-override
(nth 0 range)
(nth 1 range)
(nth 2 range)
override start end))))))