kaushalmodi / ox-hugo

A carefully crafted Org exporter back-end for Hugo
https://ox-hugo.scripter.co
GNU General Public License v3.0
882 stars 132 forks source link

Invalid inline svg #470

Closed Vincent-P closed 2 years ago

Vincent-P commented 2 years ago

Actual Behavior

Currently ox-hugo uses fill-region to inline svg to "Make huge one-liner SVGs sane" (https://github.com/kaushalmodi/ox-hugo/blob/master/ox-hugo.el#L2184). It actually breaks all my svg files created from Affinity Designer, because browsers misinterpret line breaks in tags.

Expected Behavior

I'd like to be able to disable this sanitizing, or maybe it isn't needed at all? To limit line length properly you should parse the svg to avoid breaking in the middle of a tag.

My workaround for now is to edit ox-hugo.el manually and comment the line mentioned above.

How to Reproduce the Issue

Example Org File

Here is the svg tag generated from Affinity Designer:

<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" viewBox="0 0 1485 440" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;">
</svg>

Generated Markdown File or Error

Here is the sanitized svg in the markdown file.

<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="100%"
height="100%" viewBox="0 0 1485 440" version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve"
xmlns:serif="http://www.serif.com/"
style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;">
</svg>

The browser doesn't understand this and adds <p> tag. image

Ox-Hugo Debug Information

Debug Info # Debug information for `ox-hugo` ## Emacs Version GNU Emacs 28.0.50 (build 1, x86_64-w64-mingw32) of 2021-07-28 (commit fa51d6cdcd49dad21c9e6ede878467cab95630b0) ## Org Version Org mode version 9.5 (9.5-g048f47 @ c:/Users/vince/.emacs.d/straight/build/org/) ## Hugo Version Hugo Static Site Generator v0.80.0-792EF0F4 windows/amd64 BuildDate: 2020-12-31T13:37:57Z ### Org `load-path` shadows **Warning**: Possible mixed installation of Org c:/Users/vince/.emacs.d/straight/build/org/ox hides c:/emacs/share/emacs/28.0.50/lisp/org/ox c:/Users/vince/.emacs.d/straight/build/org/ox-texinfo hides c:/emacs/share/emacs/28.0.50/lisp/org/ox-texinfo c:/Users/vince/.emacs.d/straight/build/org/ox-publish hides c:/emacs/share/emacs/28.0.50/lisp/org/ox-publish c:/Users/vince/.emacs.d/straight/build/org/ox-org hides c:/emacs/share/emacs/28.0.50/lisp/org/ox-org c:/Users/vince/.emacs.d/straight/build/org/ox-odt hides c:/emacs/share/emacs/28.0.50/lisp/org/ox-odt c:/Users/vince/.emacs.d/straight/build/org/ox-md hides c:/emacs/share/emacs/28.0.50/lisp/org/ox-md c:/Users/vince/.emacs.d/straight/build/org/ox-man hides c:/emacs/share/emacs/28.0.50/lisp/org/ox-man c:/Users/vince/.emacs.d/straight/build/org/ox-latex hides c:/emacs/share/emacs/28.0.50/lisp/org/ox-latex c:/Users/vince/.emacs.d/straight/build/org/ox-icalendar hides c:/emacs/share/emacs/28.0.50/lisp/org/ox-icalendar c:/Users/vince/.emacs.d/straight/build/org/ox-html hides c:/emacs/share/emacs/28.0.50/lisp/org/ox-html c:/Users/vince/.emacs.d/straight/build/org/ox-beamer hides c:/emacs/share/emacs/28.0.50/lisp/org/ox-beamer c:/Users/vince/.emacs.d/straight/build/org/ox-ascii hides c:/emacs/share/emacs/28.0.50/lisp/org/ox-ascii c:/Users/vince/.emacs.d/straight/build/org/org hides c:/emacs/share/emacs/28.0.50/lisp/org/org c:/Users/vince/.emacs.d/straight/build/org/org-version hides c:/emacs/share/emacs/28.0.50/lisp/org/org-version c:/Users/vince/.emacs.d/straight/build/org/org-timer hides c:/emacs/share/emacs/28.0.50/lisp/org/org-timer c:/Users/vince/.emacs.d/straight/build/org/org-tempo hides c:/emacs/share/emacs/28.0.50/lisp/org/org-tempo c:/Users/vince/.emacs.d/straight/build/org/org-table hides c:/emacs/share/emacs/28.0.50/lisp/org/org-table c:/Users/vince/.emacs.d/straight/build/org/org-src hides c:/emacs/share/emacs/28.0.50/lisp/org/org-src c:/Users/vince/.emacs.d/straight/build/org/org-refile hides c:/emacs/share/emacs/28.0.50/lisp/org/org-refile c:/Users/vince/.emacs.d/straight/build/org/org-protocol hides c:/emacs/share/emacs/28.0.50/lisp/org/org-protocol c:/Users/vince/.emacs.d/straight/build/org/org-plot hides c:/emacs/share/emacs/28.0.50/lisp/org/org-plot c:/Users/vince/.emacs.d/straight/build/org/org-pcomplete hides c:/emacs/share/emacs/28.0.50/lisp/org/org-pcomplete c:/Users/vince/.emacs.d/straight/build/org/org-num hides c:/emacs/share/emacs/28.0.50/lisp/org/org-num c:/Users/vince/.emacs.d/straight/build/org/org-mouse hides c:/emacs/share/emacs/28.0.50/lisp/org/org-mouse c:/Users/vince/.emacs.d/straight/build/org/org-mobile hides c:/emacs/share/emacs/28.0.50/lisp/org/org-mobile c:/Users/vince/.emacs.d/straight/build/org/org-macs hides c:/emacs/share/emacs/28.0.50/lisp/org/org-macs c:/Users/vince/.emacs.d/straight/build/org/org-macro hides c:/emacs/share/emacs/28.0.50/lisp/org/org-macro c:/Users/vince/.emacs.d/straight/build/org/org-loaddefs hides c:/emacs/share/emacs/28.0.50/lisp/org/org-loaddefs c:/Users/vince/.emacs.d/straight/build/org/org-list hides c:/emacs/share/emacs/28.0.50/lisp/org/org-list c:/Users/vince/.emacs.d/straight/build/org/org-lint hides c:/emacs/share/emacs/28.0.50/lisp/org/org-lint c:/Users/vince/.emacs.d/straight/build/org/org-keys hides c:/emacs/share/emacs/28.0.50/lisp/org/org-keys c:/Users/vince/.emacs.d/straight/build/org/org-install hides c:/emacs/share/emacs/28.0.50/lisp/org/org-install c:/Users/vince/.emacs.d/straight/build/org/org-inlinetask hides c:/emacs/share/emacs/28.0.50/lisp/org/org-inlinetask c:/Users/vince/.emacs.d/straight/build/org/org-indent hides c:/emacs/share/emacs/28.0.50/lisp/org/org-indent c:/Users/vince/.emacs.d/straight/build/org/org-id hides c:/emacs/share/emacs/28.0.50/lisp/org/org-id c:/Users/vince/.emacs.d/straight/build/org/org-habit hides c:/emacs/share/emacs/28.0.50/lisp/org/org-habit c:/Users/vince/.emacs.d/straight/build/org/org-goto hides c:/emacs/share/emacs/28.0.50/lisp/org/org-goto c:/Users/vince/.emacs.d/straight/build/org/org-footnote hides c:/emacs/share/emacs/28.0.50/lisp/org/org-footnote c:/Users/vince/.emacs.d/straight/build/org/org-feed hides c:/emacs/share/emacs/28.0.50/lisp/org/org-feed c:/Users/vince/.emacs.d/straight/build/org/org-faces hides c:/emacs/share/emacs/28.0.50/lisp/org/org-faces c:/Users/vince/.emacs.d/straight/build/org/org-entities hides c:/emacs/share/emacs/28.0.50/lisp/org/org-entities c:/Users/vince/.emacs.d/straight/build/org/org-element hides c:/emacs/share/emacs/28.0.50/lisp/org/org-element c:/Users/vince/.emacs.d/straight/build/org/org-duration hides c:/emacs/share/emacs/28.0.50/lisp/org/org-duration c:/Users/vince/.emacs.d/straight/build/org/org-datetree hides c:/emacs/share/emacs/28.0.50/lisp/org/org-datetree c:/Users/vince/.emacs.d/straight/build/org/org-ctags hides c:/emacs/share/emacs/28.0.50/lisp/org/org-ctags c:/Users/vince/.emacs.d/straight/build/org/org-crypt hides c:/emacs/share/emacs/28.0.50/lisp/org/org-crypt c:/Users/vince/.emacs.d/straight/build/org/org-compat hides c:/emacs/share/emacs/28.0.50/lisp/org/org-compat c:/Users/vince/.emacs.d/straight/build/org/org-colview hides c:/emacs/share/emacs/28.0.50/lisp/org/org-colview c:/Users/vince/.emacs.d/straight/build/org/org-clock hides c:/emacs/share/emacs/28.0.50/lisp/org/org-clock c:/Users/vince/.emacs.d/straight/build/org/org-capture hides c:/emacs/share/emacs/28.0.50/lisp/org/org-capture c:/Users/vince/.emacs.d/straight/build/org/org-attach hides c:/emacs/share/emacs/28.0.50/lisp/org/org-attach c:/Users/vince/.emacs.d/straight/build/org/org-attach-git hides c:/emacs/share/emacs/28.0.50/lisp/org/org-attach-git c:/Users/vince/.emacs.d/straight/build/org/org-archive hides c:/emacs/share/emacs/28.0.50/lisp/org/org-archive c:/Users/vince/.emacs.d/straight/build/org/org-agenda hides c:/emacs/share/emacs/28.0.50/lisp/org/org-agenda c:/Users/vince/.emacs.d/straight/build/org/ol hides c:/emacs/share/emacs/28.0.50/lisp/org/ol c:/Users/vince/.emacs.d/straight/build/org/ol-w3m hides c:/emacs/share/emacs/28.0.50/lisp/org/ol-w3m c:/Users/vince/.emacs.d/straight/build/org/ol-rmail hides c:/emacs/share/emacs/28.0.50/lisp/org/ol-rmail c:/Users/vince/.emacs.d/straight/build/org/ol-mhe hides c:/emacs/share/emacs/28.0.50/lisp/org/ol-mhe c:/Users/vince/.emacs.d/straight/build/org/ol-irc hides c:/emacs/share/emacs/28.0.50/lisp/org/ol-irc c:/Users/vince/.emacs.d/straight/build/org/ol-info hides c:/emacs/share/emacs/28.0.50/lisp/org/ol-info c:/Users/vince/.emacs.d/straight/build/org/ol-gnus hides c:/emacs/share/emacs/28.0.50/lisp/org/ol-gnus c:/Users/vince/.emacs.d/straight/build/org/ol-eww hides c:/emacs/share/emacs/28.0.50/lisp/org/ol-eww c:/Users/vince/.emacs.d/straight/build/org/ol-eshell hides c:/emacs/share/emacs/28.0.50/lisp/org/ol-eshell c:/Users/vince/.emacs.d/straight/build/org/ol-docview hides c:/emacs/share/emacs/28.0.50/lisp/org/ol-docview c:/Users/vince/.emacs.d/straight/build/org/ol-bibtex hides c:/emacs/share/emacs/28.0.50/lisp/org/ol-bibtex c:/Users/vince/.emacs.d/straight/build/org/ol-bbdb hides c:/emacs/share/emacs/28.0.50/lisp/org/ol-bbdb c:/Users/vince/.emacs.d/straight/build/org/ob hides c:/emacs/share/emacs/28.0.50/lisp/org/ob c:/Users/vince/.emacs.d/straight/build/org/ob-tangle hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-tangle c:/Users/vince/.emacs.d/straight/build/org/ob-table hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-table c:/Users/vince/.emacs.d/straight/build/org/ob-sqlite hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-sqlite c:/Users/vince/.emacs.d/straight/build/org/ob-sql hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-sql c:/Users/vince/.emacs.d/straight/build/org/ob-shell hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-shell c:/Users/vince/.emacs.d/straight/build/org/ob-sed hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-sed c:/Users/vince/.emacs.d/straight/build/org/ob-screen hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-screen c:/Users/vince/.emacs.d/straight/build/org/ob-scheme hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-scheme c:/Users/vince/.emacs.d/straight/build/org/ob-sass hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-sass c:/Users/vince/.emacs.d/straight/build/org/ob-ruby hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-ruby c:/Users/vince/.emacs.d/straight/build/org/ob-ref hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-ref c:/Users/vince/.emacs.d/straight/build/org/ob-R hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-R c:/Users/vince/.emacs.d/straight/build/org/ob-python hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-python c:/Users/vince/.emacs.d/straight/build/org/ob-processing hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-processing c:/Users/vince/.emacs.d/straight/build/org/ob-plantuml hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-plantuml c:/Users/vince/.emacs.d/straight/build/org/ob-perl hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-perl c:/Users/vince/.emacs.d/straight/build/org/ob-org hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-org c:/Users/vince/.emacs.d/straight/build/org/ob-octave hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-octave c:/Users/vince/.emacs.d/straight/build/org/ob-ocaml hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-ocaml c:/Users/vince/.emacs.d/straight/build/org/ob-maxima hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-maxima c:/Users/vince/.emacs.d/straight/build/org/ob-matlab hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-matlab c:/Users/vince/.emacs.d/straight/build/org/ob-makefile hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-makefile c:/Users/vince/.emacs.d/straight/build/org/ob-lua hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-lua c:/Users/vince/.emacs.d/straight/build/org/ob-lob hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-lob c:/Users/vince/.emacs.d/straight/build/org/ob-lisp hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-lisp c:/Users/vince/.emacs.d/straight/build/org/ob-lilypond hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-lilypond c:/Users/vince/.emacs.d/straight/build/org/ob-latex hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-latex c:/Users/vince/.emacs.d/straight/build/org/ob-js hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-js c:/Users/vince/.emacs.d/straight/build/org/ob-java hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-java c:/Users/vince/.emacs.d/straight/build/org/ob-haskell hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-haskell c:/Users/vince/.emacs.d/straight/build/org/ob-groovy hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-groovy c:/Users/vince/.emacs.d/straight/build/org/ob-gnuplot hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-gnuplot c:/Users/vince/.emacs.d/straight/build/org/ob-fortran hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-fortran c:/Users/vince/.emacs.d/straight/build/org/ob-forth hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-forth c:/Users/vince/.emacs.d/straight/build/org/ob-exp hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-exp c:/Users/vince/.emacs.d/straight/build/org/ob-eval hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-eval c:/Users/vince/.emacs.d/straight/build/org/ob-eshell hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-eshell c:/Users/vince/.emacs.d/straight/build/org/ob-emacs-lisp hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-emacs-lisp c:/Users/vince/.emacs.d/straight/build/org/ob-dot hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-dot c:/Users/vince/.emacs.d/straight/build/org/ob-ditaa hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-ditaa c:/Users/vince/.emacs.d/straight/build/org/ob-css hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-css c:/Users/vince/.emacs.d/straight/build/org/ob-core hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-core c:/Users/vince/.emacs.d/straight/build/org/ob-comint hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-comint c:/Users/vince/.emacs.d/straight/build/org/ob-clojure hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-clojure c:/Users/vince/.emacs.d/straight/build/org/ob-calc hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-calc c:/Users/vince/.emacs.d/straight/build/org/ob-C hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-C c:/Users/vince/.emacs.d/straight/build/org/ob-awk hides c:/emacs/share/emacs/28.0.50/lisp/org/ob-awk Study the output of `M-x list-load-path-shadows`. ## `ox-hugo` defcustoms
org-hugo-section "posts"
org-hugo-use-code-for-kbd nil
org-hugo-preserve-filling t
org-hugo-delete-trailing-ws t
org-hugo-prefer-hyphen-in-tags t
org-hugo-allow-spaces-in-tags t
org-hugo-tag-processing-functions (org-hugo–tag-processing-fn-replace-with-spaces-maybe org-hugo–tag-processing-fn-replace-with-hyphens-maybe)
org-hugo-auto-set-lastmod nil
org-hugo-export-with-toc nil
org-hugo-export-with-section-numbers nil
org-hugo-front-matter-format "toml"
org-hugo-default-static-subdirectory-for-externals "ox-hugo"
org-hugo-external-file-extensions-allowed-for-copying ("jpg" "jpeg" "tiff" "png" "svg" "gif" "mp4" "pdf" "odt" "doc" "ppt" "xls" "docx" "pptx" "xlsx")
org-hugo-date-format "%Y-%m-%dT%T%z"
org-hugo-paired-shortcodes ""
org-hugo-langs-no-descr-in-code-fences nil
org-hugo-suppress-lastmod-period 0.0
org-hugo-front-matter-format "toml"
kaushalmodi commented 2 years ago

@Vincent-P You make a valid point.

Can you submit a PR that has your suggested change and also changes in any tests so that the CI is passing?

kaushalmodi commented 2 years ago

@Vincent-P

Actually, as I am looking at your example closer, I don't think you should inline the DOCTYPE tag. That tag is supposed to be only at the beginning of a file, like .html, .svg, .xhtml, etc. (Reference).

Does the issue go away if you remove the <!DOCTYPE.. line? i.e. just have this?

<svg width="100%" height="100%" viewBox="0 0 1485 440" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;">
</svg>
Vincent-P commented 2 years ago

Removing the xml and doctype tags at the beginning of the file seems to work, but is a pain to edit all svg files manually after exporting them.

I am inlining the svg as mentionned in the documentation:

#+caption: An SVG with hyperlink
#+attr_html: :inlined t
[[file:../test/site/content-org/images/svg-with-hyperlinks.svg]]

It also seems that the doctype should definitely be at the beginning of the svg file?

kaushalmodi commented 2 years ago

@Vincent-P When I use your exact example, the browser gives me this warning:

image

kaushalmodi commented 2 years ago

It also seems that the doctype should definitely be at the beginning of the svg file?

It doesn't seem to be the case. I have using PlantUML generated svg files and they don't insert the doctype at the beginning.

You are not supposed to have multiple doctypes. Can you tweak your tool generating the SVG's to not insert the doctype? Or postprocess the generated SVG's to remove the first line (which would always have the doctype)?

kaushalmodi commented 2 years ago

https://rocketvalidator.com/html-validation/stray-doctype

Vincent-P commented 2 years ago

I made a typo in the original post, there is an xml tag <?xml version="1.0" encoding="UTF-8" standalone="no"?> at the beginning of the file before the doctype. It seems that ox-hugo removes this xml tag. That may be the cause to the stray doctype error?

Manually adding the xml tag in the generated markdown results in this error: image

Vincent-P commented 2 years ago

I think ox-hugo should remove the doctype, as it does for the xml tag.

kaushalmodi commented 2 years ago

I think ox-hugo should remove the doctype

ok, that might be doable.

kaushalmodi commented 2 years ago

@Vincent-P The issue is auto-closed as I tagged it in the commit sanitizing the DOCTYPE tag. But please try out the latest commit and let me know if this issue actually got fixed. If not, we can reopen this and work on it further.

Vincent-P commented 2 years ago

Thank you! The latest commit fixed my original issue. I think there is still a problem when breaking the line inside an inline css in the svg but I will try to figure it out first and I will post another issue if needed.

kaushalmodi commented 2 years ago

I think there is still a problem when breaking the line inside an inline css in the svg but I will try to figure it out first and I will post another issue if needed.

From my experience, svg and html are newline insensitive. But I haven't seen css inside svg. So this might be a corner case.

Yes, I would like to see what that looks like.

kaushalmodi commented 2 years ago

The latest commit fixed my original issue.

Also, apologies, I had to force push over my hasty commits. Please checkout the latest master branch now.

Vincent-P commented 2 years ago

It is working fine, thank you again.

johanwk commented 2 years ago

I have a problem with SVGs containing hyperlinks: The output shown in HTML is the XML code of the SVG, with "<" converted to &lt;, etc.

My image is generated with PlantUML, as in the example at https://ox-hugo.scripter.co/doc/inlined-svgs/. So, there's an org-babel block with the PlantUML code, then the generated SVG image.

Clue: If I add <p> ... </p> immediately around the content in the generated Markdown file, the image is displayed properly.