diff options
| author | Albert Krewinkel <albert@zeitkraut.de> | 2022-03-29 17:50:55 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-29 08:50:55 -0700 |
| commit | 7a7e1b2b70d7f22ad7ca2c6aea56055804a1cdb2 (patch) | |
| tree | 41bab83740ab373d2ce9c62072cfa951dc9aa8a1 | |
| parent | cd931e55b685a0f3526781fda724bbd7dbd0a908 (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.
| -rw-r--r-- | src/Text/Pandoc/Readers/RST.hs | 16 | ||||
| -rw-r--r-- | test/rst-reader.native | 11 |
2 files changed, 21 insertions, 6 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 --- diff --git a/test/rst-reader.native b/test/rst-reader.native index f5c60cd4f..51bb940bf 100644 --- a/test/rst-reader.native +++ b/test/rst-reader.native @@ -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" ] |
