git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #2477 from tarleb/org-toggling-header-args

Org reader: allow toggling header args

commit45df87cf15b36815c28ea6306a380e673bcd0e68 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 25 Oct 2015, 12:10 (11 years ago) parentf3e559c27a8603
2 files changed+35−4
src/Text/Pandoc/Readers/Org.hs+16−4 tests/Tests/Readers/Org.hs+19
src/Text/Pandoc/Readers/Org.hs+16−4
@@ -532,10 +532,16 @@ rundocBlockClass :: String
532532rundocBlockClass = rundocPrefix ++ "block"
533533
534534blockOption :: OrgParser (String, String)
535−blockOption = try $ (,) <$> orgArgKey <*> orgParamValue
535+blockOption = try $ do
536+ argKey <- orgArgKey
537+ paramValue <- option "yes" orgParamValue
538+ return (argKey, paramValue)
536539
537540inlineBlockOption :: OrgParser (String, String)
538−inlineBlockOption = try $ (,) <$> orgArgKey <*> orgInlineParamValue
541+inlineBlockOption = try $ do
542+ argKey <- orgArgKey
543+ paramValue <- option "yes" orgInlineParamValue
544+ return (argKey, paramValue)
539545
540546orgArgKey :: OrgParser String
541547orgArgKey = try $
@@ -544,11 +550,17 @@ orgArgKey = try $
544550
545551orgParamValue :: OrgParser String
546552orgParamValue = try $
547− skipSpaces *> many1 (noneOf "\t\n\r ") <* skipSpaces
553+ skipSpaces
554+ *> notFollowedBy (char ':' )
555+ *> many1 (noneOf "\t\n\r ")
556+ <* skipSpaces
548557
549558orgInlineParamValue :: OrgParser String
550559orgInlineParamValue = try $
551− skipSpaces *> many1 (noneOf "\t\n\r ]") <* skipSpaces
560+ skipSpaces
561+ *> notFollowedBy (char ':')
562+ *> many1 (noneOf "\t\n\r ]")
563+ <* skipSpaces
552564
553565orgArgWordChar :: OrgParser Char
554566orgArgWordChar = alphaNum <|> oneOf "-_"
tests/Tests/Readers/Org.hs+19
@@ -264,6 +264,16 @@ tests =
264264 )
265265 "echo 'Hello, World'")
266266
267+ , "Inline code block with toggle" =:
268+ "src_sh[:toggle]{echo $HOME}" =?>
269+ (para $ codeWith ( ""
270+ , [ "bash", "rundoc-block" ]
271+ , [ ("rundoc-language", "sh")
272+ , ("rundoc-toggle", "yes")
273+ ]
274+ )
275+ "echo $HOME")
276+
267277 , "Citation" =:
268278 "[@nonexistent]" =?>
269279 let citation = Citation
@@ -1102,6 +1112,15 @@ tests =
11021112 , ": 65" ] =?>
11031113 rawBlock "html" ""
11041114
1115+ , "Source block with toggling header arguments" =:
1116+ unlines [ "#+BEGIN_SRC sh :noeval"
1117+ , "echo $HOME"
1118+ , "#+END_SRC"
1119+ ] =?>
1120+ let classes = [ "bash", "rundoc-block" ]
1121+ params = [ ("rundoc-language", "sh"), ("rundoc-noeval", "yes") ]
1122+ in codeBlockWith ("", classes, params) "echo $HOME\n"
1123+
11051124 , "Example block" =:
11061125 unlines [ "#+begin_example"
11071126 , "A chosen representation of"