git.iko.soy/typeable/pandoc
on master help sign in
Org reader: stop adding rundoc prefix to src params

Source block parameter names are no longer prefixed with *rundoc*. This was intended to simplify working with the rundoc project, a babel runner. However, the rundoc project is unmaintained, and adding those markers is not the reader's job anyway. The original language that is specified for a source element is now retained as the `data-org-language` attribute and only added if it differs from the translated language.

commit2e43e27e5c6374c0cbc3ad690f04ec95bbac1f91 authorAlbert Krewinkel <albert@zeitkraut.de> dateSun 23 Apr 2017, 12:56 (10 years ago) parent04658c4
4 files changed+50−72
src/Text/Pandoc/Readers/Org/Blocks.hs+10−22 src/Text/Pandoc/Readers/Org/Inlines.hs+3−4 src/Text/Pandoc/Readers/Org/Shared.hs+11−13 test/Tests/Readers/Org.hs+26−33
src/Text/Pandoc/Readers/Org/Blocks.hs+10−22
@@ -39,8 +39,7 @@ import Text.Pandoc.Readers.Org.Meta (metaExport, metaKey, metaLine)
3939import Text.Pandoc.Readers.Org.ParserState
4040import Text.Pandoc.Readers.Org.Parsing
4141import Text.Pandoc.Readers.Org.Shared (cleanLinkString, isImageFilename,
42− rundocBlockClass, toRundocAttrib,
43− translateLang)
42+ originalLang, translateLang)
4443
4544import Text.Pandoc.Builder (Blocks, Inlines)
4645import qualified Text.Pandoc.Builder as B
@@ -493,16 +492,14 @@ codeBlock blockAttrs blockType = do
493492 content <- rawBlockContent blockType
494493 resultsContent <- trailingResultsBlock
495494 let id' = fromMaybe mempty $ blockAttrName blockAttrs
496− let includeCode = exportsCode kv
497− let includeResults = exportsResults kv
498495 let codeBlck = B.codeBlockWith ( id', classes, kv ) content
499496 let labelledBlck = maybe (pure codeBlck)
500497 (labelDiv codeBlck)
501498 (blockAttrCaption blockAttrs)
502499 let resultBlck = fromMaybe mempty resultsContent
503500 return $
504− (if includeCode then labelledBlck else mempty) <>
505− (if includeResults then resultBlck else mempty)
501+ (if exportsCode kv then labelledBlck else mempty) <>
502+ (if exportsResults kv then resultBlck else mempty)
506503 where
507504 labelDiv :: Blocks -> F Inlines -> F Blocks
508505 labelDiv blk value =
@@ -511,13 +508,11 @@ codeBlock blockAttrs blockType = do
511508 labelledBlock :: F Inlines -> F Blocks
512509 labelledBlock = fmap (B.plain . B.spanWith ("", ["label"], []))
513510
514−exportsCode :: [(String, String)] -> Bool
515−exportsCode attrs = not (("rundoc-exports", "none") `elem` attrs
516− || ("rundoc-exports", "results") `elem` attrs)
511+ exportsCode :: [(String, String)] -> Bool
512+ exportsCode = maybe True (`elem` ["code", "both"]) . lookup "exports"
517513
518−exportsResults :: [(String, String)] -> Bool
519−exportsResults attrs = ("rundoc-exports", "results") `elem` attrs
520− || ("rundoc-exports", "both") `elem` attrs
514+ exportsResults :: [(String, String)] -> Bool
515+ exportsResults = maybe False (`elem` ["results", "both"]) . lookup "exports"
521516
522517trailingResultsBlock :: PandocMonad m => OrgParser m (Maybe (F Blocks))
523518trailingResultsBlock = optionMaybe . try $ do
@@ -532,16 +527,9 @@ codeHeaderArgs = try $ do
532527 language <- skipSpaces *> orgArgWord
533528 (switchClasses, switchKv) <- switchesAsAttributes
534529 parameters <- manyTill blockOption newline
535− let pandocLang = translateLang language
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)
543− where
544− hasRundocParameters = not . null
530+ return $ ( translateLang language : switchClasses
531+ , originalLang language <> switchKv <> parameters
532+ )
545533
546534switchesAsAttributes :: Monad m => OrgParser m ([String], [(String, String)])
547535switchesAsAttributes = try $ do
src/Text/Pandoc/Readers/Org/Inlines.hs+3−4
@@ -37,8 +37,7 @@ import Text.Pandoc.Readers.Org.BlockStarts (endOfBlock, noteMarker)
3737import Text.Pandoc.Readers.Org.ParserState
3838import Text.Pandoc.Readers.Org.Parsing
3939import Text.Pandoc.Readers.Org.Shared (cleanLinkString, isImageFilename,
40− rundocBlockClass, toRundocAttrib,
41− translateLang)
40+ originalLang, translateLang)
4241
4342import Text.Pandoc.Builder (Inlines)
4443import qualified Text.Pandoc.Builder as B
@@ -518,8 +517,8 @@ inlineCodeBlock = try $ do
518517 lang <- many1 orgArgWordChar
519518 opts <- option [] $ enclosedByPair '[' ']' inlineBlockOption
520519 inlineCode <- enclosedByPair '{' '}' (noneOf "\n\r")
521− let attrClasses = [translateLang lang, rundocBlockClass]
522− let attrKeyVal = map toRundocAttrib (("language", lang) : opts)
520+ let attrClasses = [translateLang lang]
521+ let attrKeyVal = originalLang lang <> opts
523522 returnF $ B.codeWith ("", attrClasses, attrKeyVal) inlineCode
524523 where
525524 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.
2929module Text.Pandoc.Readers.Org.Shared
3030 ( cleanLinkString
3131 , isImageFilename
32− , rundocBlockClass
33− , toRundocAttrib
32+ , originalLang
3433 , translateLang
3534 ) where
3635
37−import Control.Arrow (first)
3836import Data.Char (isAlphaNum)
3937import Data.List (isPrefixOf, isSuffixOf)
4038
@@ -68,17 +66,17 @@ cleanLinkString s =
6866 in all (\c -> isAlphaNum c || c `elem` (".-"::String)) scheme
6967 && not (null path)
7068
71−-- | Prefix used for Rundoc classes and arguments.
72−rundocPrefix :: String
73−rundocPrefix = "rundoc-"
69+-- | Creates an key-value pair marking the original language name specified for
70+-- a piece of source code.
7471
75−-- | The class-name used to mark rundoc blocks.
76−rundocBlockClass :: String
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)
81−toRundocAttrib = first (rundocPrefix ++)
72+-- | Creates an key-value attributes marking the original language name
73+-- specified for a piece of source code.
74+originalLang :: String -> [(String, String)]
75+originalLang lang =
76+ let transLang = translateLang lang
77+ in if transLang == lang
78+ then []
79+ else [("data-org-language", lang)]
8280
8381-- | Translate from Org-mode's programming language identifiers to those used
8482-- by Pandoc. This is useful to allow for proper syntax highlighting in
test/Tests/Readers/Org.hs+26−33
@@ -275,17 +275,17 @@ tests =
275275 , "Inline code block" =:
276276 "src_emacs-lisp{(message \"Hello\")}" =?>
277277 (para $ codeWith ( ""
278− , [ "commonlisp", "rundoc-block" ]
279− , [ ("rundoc-language", "emacs-lisp") ])
278+ , [ "commonlisp" ]
279+ , [ ("data-org-language", "emacs-lisp") ])
280280 "(message \"Hello\")")
281281
282282 , "Inline code block with arguments" =:
283283 "src_sh[:export both :results output]{echo 'Hello, World'}" =?>
284284 (para $ codeWith ( ""
285− , [ "bash", "rundoc-block" ]
286− , [ ("rundoc-language", "sh")
287− , ("rundoc-export", "both")
288− , ("rundoc-results", "output")
285+ , [ "bash" ]
286+ , [ ("data-org-language", "sh")
287+ , ("export", "both")
288+ , ("results", "output")
289289 ]
290290 )
291291 "echo 'Hello, World'")
@@ -293,9 +293,9 @@ tests =
293293 , "Inline code block with toggle" =:
294294 "src_sh[:toggle]{echo $HOME}" =?>
295295 (para $ codeWith ( ""
296− , [ "bash", "rundoc-block" ]
297− , [ ("rundoc-language", "sh")
298− , ("rundoc-toggle", "yes")
296+ , [ "bash" ]
297+ , [ ("data-org-language", "sh")
298+ , ("toggle", "yes")
299299 ]
300300 )
301301 "echo $HOME")
@@ -1472,16 +1472,14 @@ tests =
14721472 in mconcat [ para $ spcSep [ "Low", "German", "greeting" ]
14731473 , codeBlockWith attr' code'
14741474 ]
1475− , "Source block with rundoc/babel arguments" =:
1475+ , "Source block with babel arguments" =:
14761476 unlines [ "#+BEGIN_SRC emacs-lisp :exports both"
14771477 , "(progn (message \"Hello, World!\")"
14781478 , " (+ 23 42))"
14791479 , "#+END_SRC" ] =?>
1480− let classes = [ "commonlisp" -- as kate doesn't know emacs-lisp syntax
1481− , "rundoc-block"
1482− ]
1483− params = [ ("rundoc-language", "emacs-lisp")
1484− , ("rundoc-exports", "both")
1480+ let classes = [ "commonlisp" ] -- as kate doesn't know emacs-lisp syntax
1481+ params = [ ("data-org-language", "emacs-lisp")
1482+ , ("exports", "both")
14851483 ]
14861484 code' = unlines [ "(progn (message \"Hello, World!\")"
14871485 , " (+ 23 42))" ]
@@ -1495,11 +1493,9 @@ tests =
14951493 , ""
14961494 , "#+RESULTS:"
14971495 , ": 65"] =?>
1498− let classes = [ "commonlisp" -- as kate doesn't know emacs-lisp syntax
1499− , "rundoc-block"
1500− ]
1501− params = [ ("rundoc-language", "emacs-lisp")
1502− , ("rundoc-exports", "both")
1496+ let classes = [ "commonlisp" ]
1497+ params = [ ("data-org-language", "emacs-lisp")
1498+ , ("exports", "both")
15031499 ]
15041500 code' = unlines [ "(progn (message \"Hello, World!\")"
15051501 , " (+ 23 42))" ]
@@ -1516,11 +1512,9 @@ tests =
15161512 , ""
15171513 , "#+RESULTS:"
15181514 , ": 65" ] =?>
1519− let classes = [ "commonlisp" -- as kate doesn't know emacs-lisp syntax
1520− , "rundoc-block"
1521− ]
1522− params = [ ("rundoc-language", "emacs-lisp")
1523− , ("rundoc-exports", "code")
1515+ let classes = [ "commonlisp" ]
1516+ params = [ ("data-org-language", "emacs-lisp")
1517+ , ("exports", "code")
15241518 ]
15251519 code' = unlines [ "(progn (message \"Hello, World!\")"
15261520 , " (+ 23 42))" ]
@@ -1552,8 +1546,8 @@ tests =
15521546 , "echo $HOME"
15531547 , "#+END_SRC"
15541548 ] =?>
1555− let classes = [ "bash", "rundoc-block" ]
1556− params = [ ("rundoc-language", "sh"), ("rundoc-noeval", "yes") ]
1549+ let classes = [ "bash" ]
1550+ params = [ ("data-org-language", "sh"), ("noeval", "yes") ]
15571551 in codeBlockWith ("", classes, params) "echo $HOME\n"
15581552
15591553 , "Source block with line number switch" =:
@@ -1562,7 +1556,7 @@ tests =
15621556 , "#+END_SRC"
15631557 ] =?>
15641558 let classes = [ "bash", "numberLines" ]
1565− params = [ ("startFrom", "10") ]
1559+ params = [ ("data-org-language", "sh"), ("startFrom", "10") ]
15661560 in codeBlockWith ("", classes, params) ":() { :|:& };:\n"
15671561
15681562 , "Example block" =:
@@ -1712,12 +1706,11 @@ tests =
17121706 , "code body"
17131707 , "#+END_SRC"
17141708 ] =?>
1715− let classes = [ "c", "rundoc-block" ]
1716− params = [ ("rundoc-language", "C")
1717− , ("rundoc-tangle", "xxxx.c")
1718− , ("rundoc-city", "Zürich")
1709+ let params = [ ("data-org-language", "C")
1710+ , ("tangle", "xxxx.c")
1711+ , ("city", "Zürich")
17191712 ]
1720− in codeBlockWith ( "", classes, params) "code body\n"
1713+ in codeBlockWith ( "", ["c"], params) "code body\n"
17211714 ]
17221715
17231716 , testGroup "Smart punctuation"