git.iko.soy/typeable/pandoc
on master help sign in
Org reader: support new syntax for export blocks

Org-mode version 9 usees a new syntax for export blocks. Instead of `#+BEGIN_<FORMAT>`, where `<FORMAT>` is the format of the block's content, the new format uses `#+BEGIN_export <FORMAT>` instead. Both types are supported.

commitc17c62a2c74bbb6e36e12feea5aa6ba8679a023a authorAlbert Krewinkel <albert@zeitkraut.de> dateSun 29 May 2016, 20:00 (10 years ago) parent4f84cf0
2 files changed+24−1
src/Text/Pandoc/Readers/Org/Blocks.hs+9 tests/Tests/Readers/Org.hs+15−1
src/Text/Pandoc/Readers/Org/Blocks.hs+9
@@ -168,6 +168,7 @@ orgBlock = try $ do
168168 blkType <- blockHeaderStart
169169 ($ blkType) $
170170 case blkType of
171+ "export" -> exportBlock
171172 "comment" -> rawBlockLines (const mempty)
172173 "html" -> rawBlockLines (return . (B.rawBlock blkType))
173174 "latex" -> rawBlockLines (return . (B.rawBlock blkType))
@@ -239,6 +240,14 @@ rawBlockContent blockType = try $ do
239240ignHeaders :: OrgParser ()
240241ignHeaders = (() <$ newline) <|> (() <$ anyLine)
241242
243+-- | Read a block containing code intended for export in specific backends
244+-- only.
245+exportBlock :: String -> OrgParser (F Blocks)
246+exportBlock blockType = try $ do
247+ exportType <- skipSpaces *> orgArgWord <* ignHeaders
248+ contents <- rawBlockContent blockType
249+ returnF (B.rawBlock (map toLower exportType) contents)
250+
242251verseBlock :: String -> OrgParser (F Blocks)
243252verseBlock blockType = try $ do
244253 ignHeaders
tests/Tests/Readers/Org.hs+15−1
@@ -1293,7 +1293,7 @@ tests =
12931293 ]
12941294 ]
12951295
1296− , "Verse block with newlines" =:
1296+ , "Verse block with blank lines" =:
12971297 unlines [ "#+BEGIN_VERSE"
12981298 , "foo"
12991299 , ""
@@ -1302,6 +1302,20 @@ tests =
13021302 ] =?>
13031303 para ("foo" <> linebreak <> linebreak <> "bar")
13041304
1305+ , "Raw block LaTeX" =:
1306+ unlines [ "#+BEGIN_LaTeX"
1307+ , "The category $\\cat{Set}$ is adhesive."
1308+ , "#+END_LaTeX"
1309+ ] =?>
1310+ rawBlock "latex" "The category $\\cat{Set}$ is adhesive.\n"
1311+
1312+ , "Export block HTML" =:
1313+ unlines [ "#+BEGIN_export html"
1314+ , "<samp>Hello, World!</samp>"
1315+ , "#+END_export"
1316+ ] =?>
1317+ rawBlock "html" "<samp>Hello, World!</samp>\n"
1318+
13051319 , "LaTeX fragment" =:
13061320 unlines [ "\\begin{equation}"
13071321 , "X_i = \\begin{cases}"