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.

For instance, let's say we have the following code block:

  #+begin_src emacs-lisp -n
  ;; Comment.
  (message "one")
  (message "two")
  #+end_src

Just before `htmlize-buffer-1' calls `font-lock-ensure', (buffer-string)
returns:

  #(";; Comment.\n(message \"one\")\n(message \"two\")"
    0 3 (face font-lock-comment-delimiter-face)
    3 11 (face font-lock-comment-face)
    11 12 (face nil)
    21 26 (face font-lock-string-face)
    27 28 (face nil)
    37 42 (face font-lock-string-face))

After the call, (buffer-string) returns:

  #(";; Comment.\n(message \"one\")\n(message \"two\")"
    0 3 (face font-lock-comment-delimiter-face)
    3 12 (face font-lock-comment-face)
    21 26 (face font-lock-string-face)
    37 42 (face font-lock-string-face))

Thus, the generated html code contains interleaved span tags:

  <pre class="src src-emacs-lisp"><code><span class="linenr">1: </span><span 
style="color: #b22222;">;; </span><span style="color: #b22222;">Comment.
  <span class="linenr">2: </span></span>(message <span style="color: 
#8b2252;">"one"</span>)
  <span class="linenr">3: </span>(message <span style="color: 
#8b2252;">"two"</span>)
  </code></pre>

System information:

Emacs  : GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.51, 
cairo version 1.18.4)
 of 2026-03-30
Package: Org mode version 10.0-pre (release_9.8-79-gc1b424 @ 
/home/user/src/org-mode/lisp/)

        Roi

Reply via email to