git.iko.soy/typeable/pandoc
on master help sign in
Org reader: stop adding rundoc prefix to src params
2e43e27Albert Krewinkel
src/Text/Pandoc/Readers/Org/Blocks.hs+10−22
@@ -39,8 +39,7 @@ import Text.Pandoc.Readers.Org.Meta (metaExport, metaKey, metaLine)
39import Text.Pandoc.Readers.Org.ParserState
39import Text.Pandoc.Readers.Org.ParserState
40import Text.Pandoc.Readers.Org.Parsing
40import Text.Pandoc.Readers.Org.Parsing
41import Text.Pandoc.Readers.Org.Shared (cleanLinkString, isImageFilename,
41import Text.Pandoc.Readers.Org.Shared (cleanLinkString, isImageFilename,
42− rundocBlockClass, toRundocAttrib,
43− translateLang)
42+ originalLang, translateLang)
44
43
45import Text.Pandoc.Builder (Blocks, Inlines)
44import Text.Pandoc.Builder (Blocks, Inlines)
46import qualified Text.Pandoc.Builder as B
45import qualified Text.Pandoc.Builder as B
@@ -493,16 +492,14 @@ codeBlock blockAttrs blockType = do
493 content <- rawBlockContent blockType
492 content <- rawBlockContent blockType
494 resultsContent <- trailingResultsBlock
493 resultsContent <- trailingResultsBlock
495 let id' = fromMaybe mempty $ blockAttrName blockAttrs
494 let id' = fromMaybe mempty $ blockAttrName blockAttrs
496− let includeCode = exportsCode kv
497− let includeResults = exportsResults kv
498 let codeBlck = B.codeBlockWith ( id', classes, kv ) content
495 let codeBlck = B.codeBlockWith ( id', classes, kv ) content
499 let labelledBlck = maybe (pure codeBlck)
496 let labelledBlck = maybe (pure codeBlck)
500 (labelDiv codeBlck)
497 (labelDiv codeBlck)
501 (blockAttrCaption blockAttrs)
498 (blockAttrCaption blockAttrs)
502 let resultBlck = fromMaybe mempty resultsContent
499 let resultBlck = fromMaybe mempty resultsContent
503 return $
500 return $
504− (if includeCode then labelledBlck else mempty) <>
501+ (if exportsCode kv then labelledBlck else mempty) <>
505− (if includeResults then resultBlck else mempty)
502+ (if exportsResults kv then resultBlck else mempty)
506 where
503 where
507 labelDiv :: Blocks -> F Inlines -> F Blocks
504 labelDiv :: Blocks -> F Inlines -> F Blocks
508 labelDiv blk value =
505 labelDiv blk value =
@@ -511,13 +508,11 @@ codeBlock blockAttrs blockType = do
511 labelledBlock :: F Inlines -> F Blocks
508 labelledBlock :: F Inlines -> F Blocks
512 labelledBlock = fmap (B.plain . B.spanWith ("", ["label"], []))
509 labelledBlock = fmap (B.plain . B.spanWith ("", ["label"], []))
513
510
514−exportsCode :: [(String, String)] -> Bool
511+ exportsCode :: [(String, String)] -> Bool
515−exportsCode attrs = not (("rundoc-exports", "none") `elem` attrs
512+ exportsCode = maybe True (`elem` ["code", "both"]) . lookup "exports"
516− || ("rundoc-exports", "results") `elem` attrs)
517
513
518−exportsResults :: [(String, String)] -> Bool
514+ exportsResults :: [(String, String)] -> Bool
519−exportsResults attrs = ("rundoc-exports", "results") `elem` attrs
515+ exportsResults = maybe False (`elem` ["results", "both"]) . lookup "exports"
520− || ("rundoc-exports", "both") `elem` attrs
521
516
522trailingResultsBlock :: PandocMonad m => OrgParser m (Maybe (F Blocks))
517trailingResultsBlock :: PandocMonad m => OrgParser m (Maybe (F Blocks))
523trailingResultsBlock = optionMaybe . try $ do
518trailingResultsBlock = optionMaybe . try $ do
@@ -532,16 +527,9 @@ codeHeaderArgs = try $ do
532 language <- skipSpaces *> orgArgWord
527 language <- skipSpaces *> orgArgWord
533 (switchClasses, switchKv) <- switchesAsAttributes
528 (switchClasses, switchKv) <- switchesAsAttributes
534 parameters <- manyTill blockOption newline
529 parameters <- manyTill blockOption newline
535− let pandocLang = translateLang language
530+ return $ ( translateLang language : switchClasses
536− let classes = pandocLang : switchClasses
537− return $
538− if hasRundocParameters parameters
539− then ( classes <> [ rundocBlockClass ]
540− , switchKv <> map toRundocAttrib (("language", language) : parameters)
541− )
542− else (classes, switchKv <> parameters)
531+ , originalLang language <> switchKv <> parameters
543− where
532+ )
544− hasRundocParameters = not . null
545
533
546switchesAsAttributes :: Monad m => OrgParser m ([String], [(String, String)])
534switchesAsAttributes :: Monad m => OrgParser m ([String], [(String, String)])
547switchesAsAttributes = try $ do
535switchesAsAttributes = try $ do
src/Text/Pandoc/Readers/Org/Inlines.hs+3−4
@@ -37,8 +37,7 @@ import Text.Pandoc.Readers.Org.BlockStarts (endOfBlock, noteMarker)
37import Text.Pandoc.Readers.Org.ParserState
37import Text.Pandoc.Readers.Org.ParserState
38import Text.Pandoc.Readers.Org.Parsing
38import Text.Pandoc.Readers.Org.Parsing
39import Text.Pandoc.Readers.Org.Shared (cleanLinkString, isImageFilename,
39import Text.Pandoc.Readers.Org.Shared (cleanLinkString, isImageFilename,
40− rundocBlockClass, toRundocAttrib,
41− translateLang)
40+ originalLang, translateLang)
42
41
43import Text.Pandoc.Builder (Inlines)
42import Text.Pandoc.Builder (Inlines)
44import qualified Text.Pandoc.Builder as B
43import qualified Text.Pandoc.Builder as B
@@ -518,8 +517,8 @@ inlineCodeBlock = try $ do
518 lang <- many1 orgArgWordChar
517 lang <- many1 orgArgWordChar
519 opts <- option [] $ enclosedByPair '[' ']' inlineBlockOption
518 opts <- option [] $ enclosedByPair '[' ']' inlineBlockOption
520 inlineCode <- enclosedByPair '{' '}' (noneOf "\n\r")
519 inlineCode <- enclosedByPair '{' '}' (noneOf "\n\r")
521− let attrClasses = [translateLang lang, rundocBlockClass]
520+ let attrClasses = [translateLang lang]
522− let attrKeyVal = map toRundocAttrib (("language", lang) : opts)
521+ let attrKeyVal = originalLang lang <> opts
523 returnF $ B.codeWith ("", attrClasses, attrKeyVal) inlineCode
522 returnF $ B.codeWith ("", attrClasses, attrKeyVal) inlineCode
524 where
523 where
525 inlineBlockOption :: PandocMonad m => OrgParser m (String, String)
524 inlineBlockOption :: PandocMonad m => OrgParser m (String, String)
src/Text/Pandoc/Readers/Org/Shared.hs+11−13
@@ -29,12 +29,10 @@ Utility functions used in other Pandoc Org modules.
29module Text.Pandoc.Readers.Org.Shared
29module Text.Pandoc.Readers.Org.Shared
30 ( cleanLinkString
30 ( cleanLinkString
31 , isImageFilename
31 , isImageFilename
32− , rundocBlockClass
32+ , originalLang
33− , toRundocAttrib
34 , translateLang
33 , translateLang
35 ) where
34 ) where
36
35
37−import Control.Arrow (first)
38import Data.Char (isAlphaNum)
36import Data.Char (isAlphaNum)
39import Data.List (isPrefixOf, isSuffixOf)
37import Data.List (isPrefixOf, isSuffixOf)
40
38
@@ -68,17 +66,17 @@ cleanLinkString s =
68 in all (\c -> isAlphaNum c || c `elem` (".-"::String)) scheme
66 in all (\c -> isAlphaNum c || c `elem` (".-"::String)) scheme
69 && not (null path)
67 && not (null path)
70
68
71−-- | Prefix used for Rundoc classes and arguments.
69+-- | Creates an key-value pair marking the original language name specified for
72−rundocPrefix :: String
70+-- a piece of source code.
73−rundocPrefix = "rundoc-"
74
71
75−-- | The class-name used to mark rundoc blocks.
72+-- | Creates an key-value attributes marking the original language name
76−rundocBlockClass :: String
73+-- specified for a piece of source code.
77−rundocBlockClass = rundocPrefix ++ "block"
78−
79−-- | Prefix the name of a attribute, marking it as a code execution parameter.
80−toRundocAttrib :: (String, String) -> (String, String)
74+originalLang :: String -> [(String, String)]
81−toRundocAttrib = first (rundocPrefix ++)
75+originalLang lang =
76+ let transLang = translateLang lang
77+ in if transLang == lang
78+ then []
79+ else [("data-org-language", lang)]
82
80
83-- | Translate from Org-mode's programming language identifiers to those used
81-- | Translate from Org-mode's programming language identifiers to those used
84-- by Pandoc. This is useful to allow for proper syntax highlighting in
82-- by Pandoc. This is useful to allow for proper syntax highlighting in
test/Tests/Readers/Org.hs+26−33
@@ -275,17 +275,17 @@ tests =
275 , "Inline code block" =:
275 , "Inline code block" =:
276 "src_emacs-lisp{(message \"Hello\")}" =?>
276 "src_emacs-lisp{(message \"Hello\")}" =?>
277 (para $ codeWith ( ""
277 (para $ codeWith ( ""
278− , [ "commonlisp", "rundoc-block" ]
278+ , [ "commonlisp" ]
279− , [ ("rundoc-language", "emacs-lisp") ])
279+ , [ ("data-org-language", "emacs-lisp") ])
280 "(message \"Hello\")")
280 "(message \"Hello\")")
281
281
282 , "Inline code block with arguments" =:
282 , "Inline code block with arguments" =:
283 "src_sh[:export both :results output]{echo 'Hello, World'}" =?>
283 "src_sh[:export both :results output]{echo 'Hello, World'}" =?>
284 (para $ codeWith ( ""
284 (para $ codeWith ( ""
285− , [ "bash", "rundoc-block" ]
285+ , [ "bash" ]
286− , [ ("rundoc-language", "sh")
286+ , [ ("data-org-language", "sh")
287− , ("rundoc-export", "both")
287+ , ("export", "both")
288− , ("rundoc-results", "output")
288+ , ("results", "output")
289 ]
289 ]
290 )
290 )
291 "echo 'Hello, World'")
291 "echo 'Hello, World'")
@@ -293,9 +293,9 @@ tests =
293 , "Inline code block with toggle" =:
293 , "Inline code block with toggle" =:
294 "src_sh[:toggle]{echo $HOME}" =?>
294 "src_sh[:toggle]{echo $HOME}" =?>
295 (para $ codeWith ( ""
295 (para $ codeWith ( ""
296− , [ "bash", "rundoc-block" ]
296+ , [ "bash" ]
297− , [ ("rundoc-language", "sh")
297+ , [ ("data-org-language", "sh")
298− , ("rundoc-toggle", "yes")
298+ , ("toggle", "yes")
299 ]
299 ]
300 )
300 )
301 "echo $HOME")
301 "echo $HOME")
@@ -1472,16 +1472,14 @@ tests =
1472 in mconcat [ para $ spcSep [ "Low", "German", "greeting" ]
1472 in mconcat [ para $ spcSep [ "Low", "German", "greeting" ]
1473 , codeBlockWith attr' code'
1473 , codeBlockWith attr' code'
1474 ]
1474 ]
1475− , "Source block with rundoc/babel arguments" =:
1475+ , "Source block with babel arguments" =:
1476 unlines [ "#+BEGIN_SRC emacs-lisp :exports both"
1476 unlines [ "#+BEGIN_SRC emacs-lisp :exports both"
1477 , "(progn (message \"Hello, World!\")"
1477 , "(progn (message \"Hello, World!\")"
1478 , " (+ 23 42))"
1478 , " (+ 23 42))"
1479 , "#+END_SRC" ] =?>
1479 , "#+END_SRC" ] =?>
1480− let classes = [ "commonlisp" -- as kate doesn't know emacs-lisp syntax
1480+ let classes = [ "commonlisp" ] -- as kate doesn't know emacs-lisp syntax
1481− , "rundoc-block"
1482− ]
1483− params = [ ("rundoc-language", "emacs-lisp")
1481+ params = [ ("data-org-language", "emacs-lisp")
1484− , ("rundoc-exports", "both")
1482+ , ("exports", "both")
1485 ]
1483 ]
1486 code' = unlines [ "(progn (message \"Hello, World!\")"
1484 code' = unlines [ "(progn (message \"Hello, World!\")"
1487 , " (+ 23 42))" ]
1485 , " (+ 23 42))" ]
@@ -1495,11 +1493,9 @@ tests =
1495 , ""
1493 , ""
1496 , "#+RESULTS:"
1494 , "#+RESULTS:"
1497 , ": 65"] =?>
1495 , ": 65"] =?>
1498− let classes = [ "commonlisp" -- as kate doesn't know emacs-lisp syntax
1496+ let classes = [ "commonlisp" ]
1499− , "rundoc-block"
1500− ]
1501− params = [ ("rundoc-language", "emacs-lisp")
1497+ params = [ ("data-org-language", "emacs-lisp")
1502− , ("rundoc-exports", "both")
1498+ , ("exports", "both")
1503 ]
1499 ]
1504 code' = unlines [ "(progn (message \"Hello, World!\")"
1500 code' = unlines [ "(progn (message \"Hello, World!\")"
1505 , " (+ 23 42))" ]
1501 , " (+ 23 42))" ]
@@ -1516,11 +1512,9 @@ tests =
1516 , ""
1512 , ""
1517 , "#+RESULTS:"
1513 , "#+RESULTS:"
1518 , ": 65" ] =?>
1514 , ": 65" ] =?>
1519− let classes = [ "commonlisp" -- as kate doesn't know emacs-lisp syntax
1515+ let classes = [ "commonlisp" ]
1520− , "rundoc-block"
1521− ]
1522− params = [ ("rundoc-language", "emacs-lisp")
1516+ params = [ ("data-org-language", "emacs-lisp")
1523− , ("rundoc-exports", "code")
1517+ , ("exports", "code")
1524 ]
1518 ]
1525 code' = unlines [ "(progn (message \"Hello, World!\")"
1519 code' = unlines [ "(progn (message \"Hello, World!\")"
1526 , " (+ 23 42))" ]
1520 , " (+ 23 42))" ]
@@ -1552,8 +1546,8 @@ tests =
1552 , "echo $HOME"
1546 , "echo $HOME"
1553 , "#+END_SRC"
1547 , "#+END_SRC"
1554 ] =?>
1548 ] =?>
1555− let classes = [ "bash", "rundoc-block" ]
1549+ let classes = [ "bash" ]
1556− params = [ ("rundoc-language", "sh"), ("rundoc-noeval", "yes") ]
1550+ params = [ ("data-org-language", "sh"), ("noeval", "yes") ]
1557 in codeBlockWith ("", classes, params) "echo $HOME\n"
1551 in codeBlockWith ("", classes, params) "echo $HOME\n"
1558
1552
1559 , "Source block with line number switch" =:
1553 , "Source block with line number switch" =:
@@ -1562,7 +1556,7 @@ tests =
1562 , "#+END_SRC"
1556 , "#+END_SRC"
1563 ] =?>
1557 ] =?>
1564 let classes = [ "bash", "numberLines" ]
1558 let classes = [ "bash", "numberLines" ]
1565− params = [ ("startFrom", "10") ]
1559+ params = [ ("data-org-language", "sh"), ("startFrom", "10") ]
1566 in codeBlockWith ("", classes, params) ":() { :|:& };:\n"
1560 in codeBlockWith ("", classes, params) ":() { :|:& };:\n"
1567
1561
1568 , "Example block" =:
1562 , "Example block" =:
@@ -1712,12 +1706,11 @@ tests =
1712 , "code body"
1706 , "code body"
1713 , "#+END_SRC"
1707 , "#+END_SRC"
1714 ] =?>
1708 ] =?>
1715− let classes = [ "c", "rundoc-block" ]
1716− params = [ ("rundoc-language", "C")
1709+ let params = [ ("data-org-language", "C")
1717− , ("rundoc-tangle", "xxxx.c")
1710+ , ("tangle", "xxxx.c")
1718− , ("rundoc-city", "Zürich")
1711+ , ("city", "Zürich")
1719 ]
1712 ]
1720− in codeBlockWith ( "", classes, params) "code body\n"
1713+ in codeBlockWith ( "", ["c"], params) "code body\n"
1721 ]
1714 ]
1722
1715
1723 , testGroup "Smart punctuation"
1716 , testGroup "Smart punctuation"