Roi Martin <[email protected]> writes: > Htmlize's commit bf759aa3b2c4 ("Fix ensuring that the buffer is > fontified") broke line number formatting in ox-html. > > You can find two screenshots attached to this e-mail that show the > issue: > > - before_bf759aa3b2c4.png: rendered HTML before bf759aa3b2c4. > - after_bf759aa3b2c4.png: rendered HTML after bf759aa3b2c4. > > ox-html calls `font-lock-ensure' and then removes formatting on newline > characters by setting the face property to nil, so lines can be > formatted independently (i.e. '<span>' tags are closed on the same > line). > > However, after bf759aa3b2c4, the function `htmlize-buffer-1' calls > `font-lock-ensure', which removes the generated nil faces.
Thanks for reporting! Could you try the attached patch?
>From f6c0a53128ab27199e9c63ac17bca2d99a007ccb Mon Sep 17 00:00:00 2001 Message-ID: <f6c0a53128ab27199e9c63ac17bca2d99a007ccb.1775319641.git.yanta...@posteo.net> From: Ihor Radchenko <[email protected]> Date: Sat, 4 Apr 2026 18:19:22 +0200 Subject: [PATCH] org-html-fontify-code: Work around htmlize force-fontifying buffer * lisp/ox-html.el (org-html-fontify-code): Disable `font-lock-ensure' while applying htmlize. This prevents our custom faces from being overridden. Reported-by: Roi Martin <[email protected]> Link: https://orgmode.org/list/[email protected] --- lisp/ox-html.el | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 6916cc216..654e510e4 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -2433,11 +2433,17 @@ (defun org-html-fontify-code (code lang) (forward-char 1)))) (org-src-mode) (set-buffer-modified-p nil) - ;; Htmlize region. - (let ((org-html-htmlize-output-type output-type) - (org-html-htmlize-font-prefix font-prefix)) - (org-html-htmlize-region-for-paste - (point-min) (point-max)))))) + ;; htmlize itself triggers re-fontification. + ;; We do additional font manipulation, so + ;; prevent font-lock from undoing our changes by + ;; preventing `font-lock-mode' from re-fontifying + ;; the buffer. + (let ((font-lock-ensure-function #'ignore)) + ;; Htmlize region. + (let ((org-html-htmlize-output-type output-type) + (org-html-htmlize-font-prefix font-prefix)) + (org-html-htmlize-region-for-paste + (point-min) (point-max))))))) ;; Strip any enclosing <pre></pre> tags. (let* ((beg (and (string-match "\\`<pre[^>]*>\n?" code) (match-end 0))) (end (and beg (string-match "</pre>\\'" code)))) -- 2.52.0
-- Ihor Radchenko // yantar92, Org mode maintainer, Learn more about Org mode at <https://orgmode.org/>. Support Org development at <https://liberapay.com/org-mode>, or support my work at <https://liberapay.com/yantar92>
