Org writer: keep code block attributes as header args.
This allows to keep more information in the resulting `src` blocks, making it easier to roundtrip from or through Org. Org babel ignores unknown header arguments.
This commit is contained in:
parent
1de40c62fc
commit
a31cf9a005
2 changed files with 19 additions and 4 deletions
|
@ -159,10 +159,16 @@ blockToOrg (CodeBlock (ident,classes,kvs) str) = do
|
||||||
else " -n" <> startnum
|
else " -n" <> startnum
|
||||||
else ""
|
else ""
|
||||||
let at = map pandocLangToOrg classes `intersect` orgLangIdentifiers
|
let at = map pandocLangToOrg classes `intersect` orgLangIdentifiers
|
||||||
let (beg, end) = case at of
|
let lang = case at of
|
||||||
[] -> ("#+begin_example" <> numberlines, "#+end_example")
|
[] -> Nothing
|
||||||
(x:_) -> ("#+begin_src " <> x <> numberlines, "#+end_src")
|
l:_ -> Just l
|
||||||
return $ name $$ literal beg $$ literal str $$ text end $$ blankline
|
let args = mconcat $
|
||||||
|
[ " :" <> k <> " " <> v
|
||||||
|
| (k, v) <- kvs, k `notElem` ["startFrom", "org-language"]]
|
||||||
|
let (beg, end) = case lang of
|
||||||
|
Nothing -> ("#+begin_example" <> numberlines, "#+end_example")
|
||||||
|
Just x -> ("#+begin_src " <> x <> numberlines <> args, "#+end_src")
|
||||||
|
return $ name $$ literal beg $$ literal str $$ literal end $$ blankline
|
||||||
blockToOrg (BlockQuote blocks) = do
|
blockToOrg (BlockQuote blocks) = do
|
||||||
contents <- blockListToOrg blocks
|
contents <- blockListToOrg blocks
|
||||||
return $ blankline $$ "#+begin_quote" $$
|
return $ blankline $$ "#+begin_quote" $$
|
||||||
|
|
|
@ -76,5 +76,14 @@ tests =
|
||||||
, "return True"
|
, "return True"
|
||||||
, "#+end_src"
|
, "#+end_src"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
, "attributes"
|
||||||
|
=: codeBlockWith ("", ["python"], [("cache", "yes"), ("noweb", "yes")])
|
||||||
|
"'Hello'"
|
||||||
|
=?> T.unlines
|
||||||
|
[ "#+begin_src python :cache yes :noweb yes"
|
||||||
|
, "'Hello'"
|
||||||
|
, "#+end_src"
|
||||||
|
]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
Loading…
Add table
Reference in a new issue