diff options
| author | John MacFarlane <[email protected]> | 2024-02-16 10:06:12 -0800 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2024-02-16 10:06:12 -0800 |
| commit | 45b6df537a3165b07d0280488b6c1692d44667c2 (patch) | |
| tree | abc37c5546685cffc2cf7e404a129ca4a2025c2a /src | |
| parent | ba3e17de8e3c31e85cdd0d8b57d7617d829ae14f (diff) | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/SelfContained.hs | 14 |
1 files changed, 9 insertions, 5 deletions
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 |
