aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2024-02-09 11:59:26 -0800
committerJohn MacFarlane <[email protected]>2024-02-09 16:39:48 -0800
commit0604fa297dfdacf32cd8360a0c48651e45c9e566 (patch)
treea3a2fa3f175067e7ba4c0811eaa365a802707ae4
parentea23868ae46aa7677c9e0d74d892cd8dea628b1f (diff)
Fix id replacements in SVGs with clipping paths.
This fixes `--embed-resources` when SVGs have `clip-path` attributes. Closes #9420.
-rw-r--r--src/Text/Pandoc/SelfContained.hs4
-rw-r--r--test/command/9420.md13
-rw-r--r--test/command/9420.svg9
3 files changed, 26 insertions, 0 deletions
diff --git a/src/Text/Pandoc/SelfContained.hs b/src/Text/Pandoc/SelfContained.hs
index 54d49127a..ddb44385a 100644
--- a/src/Text/Pandoc/SelfContained.hs
+++ b/src/Text/Pandoc/SelfContained.hs
@@ -185,6 +185,10 @@ convertTags (t@(TagOpen tagname as):ts)
case T.uncons x of
Just ('#', x') -> (k, "#" <> svgid <> "_" <> x')
_ -> (k, x)
+ addIdPrefix ("clip-path", x) = ("clip-path",
+ case T.stripPrefix "url(#" x of
+ Just x' -> "url(#" <> svgid <> "_" <> x'
+ Nothing -> x)
addIdPrefix kv = kv
let ensureUniqueId (TagOpen tname ats) =
TagOpen tname (map addIdPrefix ats)
diff --git a/test/command/9420.md b/test/command/9420.md
new file mode 100644
index 000000000..89f666964
--- /dev/null
+++ b/test/command/9420.md
@@ -0,0 +1,13 @@
+```
+% pandoc --embed-resources
+![](command/9420.svg)
+^D
+<p><svg id="svg_e1815ef374a63cf552e4" width="504pt" height="360pt" viewBox="0 0 504 360">
+<defs>
+<clipPath id="svg_e1815ef374a63cf552e4_clip1-c3ce354c">
+ <path />
+</clipPath>
+</defs>
+<g clip-path="url(#svg_e1815ef374a63cf552e4_clip1-c3ce354c)" clip-rule="nonzero"></g>
+</svg></p>
+```
diff --git a/test/command/9420.svg b/test/command/9420.svg
new file mode 100644
index 000000000..694278425
--- /dev/null
+++ b/test/command/9420.svg
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="504pt" height="360pt" viewBox="0 0 504 360" version="1.1">
+<defs>
+<clipPath id="clip1-c3ce354c">
+ <path/>
+</clipPath>
+</defs>
+<g clip-path="url(#clip1-c3ce354c)" clip-rule="nonzero"></g>
+</svg> \ No newline at end of file