From 45b6df537a3165b07d0280488b6c1692d44667c2 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 16 Feb 2024 10:06:12 -0800 Subject: More fixes for SVG ids with `--self-contained`. This generalizes the fix to #9420 so it applies to things like `style="fill(url(#..."`. Closes #9467. --- src/Text/Pandoc/SelfContained.hs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/SelfContained.hs b/src/Text/Pandoc/SelfContained.hs index ddb44385a..fdec874ff 100644 --- a/src/Text/Pandoc/SelfContained.hs +++ b/src/Text/Pandoc/SelfContained.hs @@ -179,17 +179,21 @@ convertTags (t@(TagOpen tagname as):ts) [(k,v) | (k,v) <- attrs', k /= "id"] modify $ \st -> st{ svgMap = M.insert hash (svgid, attrs'') (svgMap st) } + let fixUrl x = + case T.breakOn "url(#" x of + (_,"") -> x + (before, after) -> before <> + "url(#" <> svgid <> "_" <> T.drop 5 after let addIdPrefix ("id", x) = ("id", svgid <> "_" <> x) addIdPrefix (k, x) | k == "xlink:href" || k == "href" = 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 + -- this clause handles things like + -- style="fill:url(#radialGradient46);stroke:none", + -- adding the svg id prefix to the anchor: + addIdPrefix (k, x) = (k, fixUrl x) let ensureUniqueId (TagOpen tname ats) = TagOpen tname (map addIdPrefix ats) ensureUniqueId x = x -- cgit v1.2.3