summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2022-03-29 17:50:55 +0200
committerGitHub <noreply@github.com>2022-03-29 08:50:55 -0700
commit7a7e1b2b70d7f22ad7ca2c6aea56055804a1cdb2 (patch)
tree41bab83740ab373d2ce9c62072cfa951dc9aa8a1 /src
parentcd931e55b685a0f3526781fda724bbd7dbd0a908 (diff)
RST reader: wrap math in Span to preserve attributes (#7998)
Math elements with a name, classes, or other fields are wrapped in a `Span` with these attributes.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/RST.hs16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
index 89479a541..f13b70738 100644
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -720,8 +720,12 @@ directive' = do
"aafig" -> do
let attribs = (name, ["aafig"], map (second trimr) fields)
return $ B.codeBlockWith attribs $ stripTrailingNewlines body
- "math" -> return $ B.para $ mconcat $ map B.displayMath
- $ toChunks $ top <> "\n\n" <> body
+ "math" -> return $ B.para
+ $ (case mkAttr name classes fields of
+ attr | attr == nullAttr -> id
+ | otherwise -> B.spanWith attr)
+ $ mconcat $ map B.displayMath
+ $ toChunks $ top <> "\n\n" <> body
"figure" -> do
(caption, legend) <- parseFromString' extractCaption body'
let src = escapeURI $ trim top
@@ -1027,6 +1031,14 @@ codeblock ident classes fields lang rmTrailingNewlines body =
Just v | not (T.null v) -> [("startFrom", v)]
_ -> []
+-- | Creates element attributes from a name, list of classes, and fields.
+-- Removes fields named @name@, @id@, or @class@.
+mkAttr :: Text -> [Text] -> [(Text, Text)] -> Attr
+mkAttr ident classes fields = (ident, classes, fields')
+ where fields' = [(k, v') | (k, v) <- fields
+ , let v' = trimr v
+ , k /= "name", k /= "id", k /= "class"]
+
---
--- note block
---