diff options
| author | John MacFarlane <[email protected]> | 2023-07-27 09:56:56 -0600 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2023-07-27 09:56:56 -0600 |
| commit | 7b8e8f6f52c82f846808427e69406111f0e2a7ac (patch) | |
| tree | 478c0981e91ccb79c8f645b3eb4cb37db8e64ddc /src | |
| parent | 340184958545402f687a77c083950c684b2c7e7d (diff) | |
SelfContained: retain attributes in svg tag...
when referring to another svg's content using `<use>`.
Closes #8969.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/SelfContained.hs | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/Text/Pandoc/SelfContained.hs b/src/Text/Pandoc/SelfContained.hs index a6d893da1..e39d62961 100644 --- a/src/Text/Pandoc/SelfContained.hs +++ b/src/Text/Pandoc/SelfContained.hs @@ -69,7 +69,8 @@ isSourceAttribute tagname (x,_) = data ConvertState = ConvertState { isHtml5 :: Bool - , svgMap :: M.Map T.Text T.Text -- map from hash to id + , svgMap :: M.Map T.Text (T.Text, [Attribute T.Text]) + -- map from hash to (id, svg attributes) } deriving (Show) convertTags :: PandocMonad m => @@ -157,10 +158,8 @@ convertTags (t@(TagOpen tagname as):ts) _ -> rest svgmap <- gets svgMap case M.lookup hash svgmap of - Just svgid -> do - let attrs' = if ("id", svgid) `elem` attrs - then [(k,v) | (k,v) <- attrs, k /= "id"] - else attrs + Just (svgid, svgattrs) -> do + let attrs' = combineSvgAttrs svgattrs attrs return $ TagOpen "svg" attrs' : TagOpen "use" [("href", "#" <> svgid)] : TagClose "use" : @@ -170,14 +169,12 @@ convertTags (t@(TagOpen tagname as):ts) case dropWhile (not . isTagOpenName "svg") tags of TagOpen "svg" svgattrs : tags' -> do let attrs' = combineSvgAttrs svgattrs attrs - let (svgId, attrs'') = -- keep original image id if present - case lookup "id" as of - Just id' -> (id', attrs') - Nothing -> - let newid = "svg_" <> hash - in (newid, ("id", newid) : - filter (\(k,_) -> k /= "id") attrs') - modify $ \st -> st{ svgMap = M.insert hash svgId (svgMap st) } + let svgid = case lookup "id" attrs' of + Just id' -> id' + Nothing -> "svg_" <> hash + let attrs'' = [(k,v) | (k,v) <- attrs', k /= "id"] + modify $ \st -> + st{ svgMap = M.insert hash (svgid, attrs'') (svgMap st) } return $ TagOpen "svg" attrs'' : tags' ++ rest' _ -> return $ TagOpen tagname attrs : rest where processAttribute (x,y) = |
