diff options
author | John MacFarlane <jgm@berkeley.edu> | 2016-05-12 00:03:14 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2016-05-12 00:03:14 -0700 |
commit | 344412cba83b0f2ecbc74f2805be6da4f3d2d24b (patch) | |
tree | 1a21d6300fe1502eb698cbcd4e1fb1508595f1fe /src/Text | |
parent | 609fb33302156348fa3f2fc6d86b9201fa17f052 (diff) | |
parent | ff489a59f4158a95fb01d1164b5fd2b865586e73 (diff) | |
download | pandoc-344412cba83b0f2ecbc74f2805be6da4f3d2d24b.tar.gz |
Merge pull request #2894 from sid-kap/rst-code-class
Add class option for code block in RST reader
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Readers/RST.hs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs index 7be0cd392..296c55f32 100644 --- a/src/Text/Pandoc/Readers/RST.hs +++ b/src/Text/Pandoc/Readers/RST.hs @@ -586,8 +586,9 @@ directive' = do case trim top of "" -> stateRstDefaultRole def role -> role }) - "code" -> codeblock (lookup "number-lines" fields) (trim top) body - "code-block" -> codeblock (lookup "number-lines" fields) (trim top) body + x | x == "code" || x == "code-block" -> + codeblock (words $ fromMaybe [] $ lookup "class" fields) + (lookup "number-lines" fields) (trim top) body "aafig" -> do let attribs = ("", ["aafig"], map (\(k,v) -> (k, trimr v)) fields) return $ B.codeBlockWith attribs $ stripTrailingNewlines body @@ -713,12 +714,13 @@ toChunks = dropWhile null . map (trim . unlines) . splitBy (all (`elem` (" \t" :: String))) . lines -codeblock :: Maybe String -> String -> String -> RSTParser Blocks -codeblock numberLines lang body = +codeblock :: [String] -> Maybe String -> String -> String -> RSTParser Blocks +codeblock classes numberLines lang body = return $ B.codeBlockWith attribs $ stripTrailingNewlines body - where attribs = ("", classes, kvs) - classes = "sourceCode" : lang + where attribs = ("", classes', kvs) + classes' = "sourceCode" : lang : maybe [] (\_ -> ["numberLines"]) numberLines + ++ classes kvs = case numberLines of Just "" -> [] Nothing -> [] |