mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-01 15:38:09 +08:00
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:
@@ -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
|
||||
---
|
||||
|
||||
@@ -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" ]
|
||||
|
||||
Reference in New Issue
Block a user