hniksic / emacs-htmlize

Convert buffer text and decorations to HTML.
193 stars 44 forks source link

Duplicated images if buffer with tabs in images are untabified #51

Closed TobiasZawada closed 4 months ago

TobiasZawada commented 5 months ago

The following lisp-code creates a buffer *test* with an embedded svg image data.

If htmlize-untabify is t, then the image appears as replacement for every tab in the HTML file generated with htmlize-buffer – three times overall.

This is because htmlize-untabify-string accidently puts the display property with the image on the corresponding table entry in htmlize-tab-spaces.

(with-current-buffer (get-buffer-create "*test*")
  (let (b e)
    (erase-buffer)
    (insert "\t  Text before\n\t")
    (setq b (point))
    (insert (propertize "bold\n" 'face 'bold)
        (propertize "\titalic\n" 'face 'italic))
    (setq e (point))
    (insert "\n\tText after")
    (let ((ol (make-overlay b e)))
      (overlay-put
       ol
       'display
       (create-image
    "<svg height=\"140\" width=\"500\" xmlns=\"http://www.w3.org/2000/svg\">
  <ellipse rx=\"100\" ry=\"50\" cx=\"120\" cy=\"80\"
  style=\"fill:yellow;stroke:green;stroke-width:3\" />
</svg>"
    'svg
    t)))))
TobiasZawada commented 5 months ago

@hniksic This error affects the HTML export of source code files with TeXfrag fragments. Such export is great for comments in math related source codes which are not supported by Doxygen, such like Modelica. Below you can see images of a toy-example that shows how the HTML export looks like with the fix or with the workaround and without it.

Switching off htmlize-untabify is a workaround. But a workaround is inconvenient when you want to promote the solution for the source code documentation.

Pull request https://github.com/hniksic/emacs-htmlize/pull/53 is a minimal fix for this issue with minimal impact on current behavior. It could only have a performance impact for tab indents that are really propertized with some images. I think this almost never happens.

From my point of view there is nothing special about https://github.com/hniksic/emacs-htmlize/pull/53 and you could accept it right away.

Later on we could think about pull request https://github.com/hniksic/emacs-htmlize/pull/52 for the same issue. This pull request simplifies the code. It removes htmlize-tab-spaces which looks like a performance optimization. But, has the performance impact really been measured? Sometimes measurement results can really surprise.

Toy-example with fix: htmlize

Toy-example without fix: htmlize-master