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.
This commit is contained in:
Albert Krewinkel
2022-03-29 17:50:55 +02:00
committed by GitHub
parent cd931e55b6
commit 7a7e1b2b70
2 changed files with 21 additions and 6 deletions
+14 -2
View File
@@ -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
---
+7 -4
View File
@@ -1556,10 +1556,13 @@ Pandoc
, Math DisplayMath "\\alpha = \\beta"
]
, Para
[ Math
DisplayMath
"\\begin{aligned}\nE &= mc^2\\\\\nF &= \\pi E\n\\end{aligned}"
, Math DisplayMath "F &= \\gamma \\alpha^2"
[ Span
( "" , [] , [ ( "label" , "hithere" ) , ( "nowrap" , "" ) ] )
[ Math
DisplayMath
"\\begin{aligned}\nE &= mc^2\\\\\nF &= \\pi E\n\\end{aligned}"
, Math DisplayMath "F &= \\gamma \\alpha^2"
]
]
, Para [ Str "All" , Space , Str "done." ]
, Header 1 ( "default-role" , [] , [] ) [ Str "Default-Role" ]