Org writer: add code block identifier as #+name
to src blocks.
This commit is contained in:
parent
eb96defcc6
commit
1de40c62fc
2 changed files with 16 additions and 2 deletions
|
@ -148,7 +148,10 @@ blockToOrg (Header level attr inlines) = do
|
||||||
then empty
|
then empty
|
||||||
else cr <> propertiesDrawer attr
|
else cr <> propertiesDrawer attr
|
||||||
return $ headerStr <> " " <> contents <> drawerStr <> cr
|
return $ headerStr <> " " <> contents <> drawerStr <> cr
|
||||||
blockToOrg (CodeBlock (_,classes,kvs) str) = do
|
blockToOrg (CodeBlock (ident,classes,kvs) str) = do
|
||||||
|
let name = if T.null ident
|
||||||
|
then empty
|
||||||
|
else literal $ "#+name: " <> ident
|
||||||
let startnum = maybe "" (\x -> " " <> trimr x) $ lookup "startFrom" kvs
|
let startnum = maybe "" (\x -> " " <> trimr x) $ lookup "startFrom" kvs
|
||||||
let numberlines = if "numberLines" `elem` classes
|
let numberlines = if "numberLines" `elem` classes
|
||||||
then if "continuedSourceBlock" `elem` classes
|
then if "continuedSourceBlock" `elem` classes
|
||||||
|
@ -159,7 +162,7 @@ blockToOrg (CodeBlock (_,classes,kvs) str) = do
|
||||||
let (beg, end) = case at of
|
let (beg, end) = case at of
|
||||||
[] -> ("#+begin_example" <> numberlines, "#+end_example")
|
[] -> ("#+begin_example" <> numberlines, "#+end_example")
|
||||||
(x:_) -> ("#+begin_src " <> x <> numberlines, "#+end_src")
|
(x:_) -> ("#+begin_src " <> x <> numberlines, "#+end_src")
|
||||||
return $ literal beg $$ literal str $$ text end $$ blankline
|
return $ name $$ literal beg $$ literal str $$ text end $$ blankline
|
||||||
blockToOrg (BlockQuote blocks) = do
|
blockToOrg (BlockQuote blocks) = do
|
||||||
contents <- blockListToOrg blocks
|
contents <- blockListToOrg blocks
|
||||||
return $ blankline $$ "#+begin_quote" $$
|
return $ blankline $$ "#+begin_quote" $$
|
||||||
|
|
|
@ -66,4 +66,15 @@ tests =
|
||||||
, "- ☒ b"
|
, "- ☒ b"
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
, testGroup "code blocks"
|
||||||
|
[ "identifier"
|
||||||
|
=: codeBlockWith ("abc", ["python"], []) "return True"
|
||||||
|
=?> T.unlines
|
||||||
|
[ "#+name: abc"
|
||||||
|
, "#+begin_src python"
|
||||||
|
, "return True"
|
||||||
|
, "#+end_src"
|
||||||
|
]
|
||||||
|
]
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue