diff options
| -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" ] |
