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.
This commit is contained in:
parent
4f84cf02c7
commit
c17c62a2c7
2 changed files with 24 additions and 1 deletions
|
@ -168,6 +168,7 @@ orgBlock = try $ do
|
|||
blkType <- blockHeaderStart
|
||||
($ blkType) $
|
||||
case blkType of
|
||||
"export" -> exportBlock
|
||||
"comment" -> rawBlockLines (const mempty)
|
||||
"html" -> rawBlockLines (return . (B.rawBlock blkType))
|
||||
"latex" -> rawBlockLines (return . (B.rawBlock blkType))
|
||||
|
@ -239,6 +240,14 @@ rawBlockContent blockType = try $ do
|
|||
ignHeaders :: OrgParser ()
|
||||
ignHeaders = (() <$ newline) <|> (() <$ anyLine)
|
||||
|
||||
-- | Read a block containing code intended for export in specific backends
|
||||
-- only.
|
||||
exportBlock :: String -> OrgParser (F Blocks)
|
||||
exportBlock blockType = try $ do
|
||||
exportType <- skipSpaces *> orgArgWord <* ignHeaders
|
||||
contents <- rawBlockContent blockType
|
||||
returnF (B.rawBlock (map toLower exportType) contents)
|
||||
|
||||
verseBlock :: String -> OrgParser (F Blocks)
|
||||
verseBlock blockType = try $ do
|
||||
ignHeaders
|
||||
|
|
|
@ -1293,7 +1293,7 @@ tests =
|
|||
]
|
||||
]
|
||||
|
||||
, "Verse block with newlines" =:
|
||||
, "Verse block with blank lines" =:
|
||||
unlines [ "#+BEGIN_VERSE"
|
||||
, "foo"
|
||||
, ""
|
||||
|
@ -1302,6 +1302,20 @@ tests =
|
|||
] =?>
|
||||
para ("foo" <> linebreak <> linebreak <> "bar")
|
||||
|
||||
, "Raw block LaTeX" =:
|
||||
unlines [ "#+BEGIN_LaTeX"
|
||||
, "The category $\\cat{Set}$ is adhesive."
|
||||
, "#+END_LaTeX"
|
||||
] =?>
|
||||
rawBlock "latex" "The category $\\cat{Set}$ is adhesive.\n"
|
||||
|
||||
, "Export block HTML" =:
|
||||
unlines [ "#+BEGIN_export html"
|
||||
, "<samp>Hello, World!</samp>"
|
||||
, "#+END_export"
|
||||
] =?>
|
||||
rawBlock "html" "<samp>Hello, World!</samp>\n"
|
||||
|
||||
, "LaTeX fragment" =:
|
||||
unlines [ "\\begin{equation}"
|
||||
, "X_i = \\begin{cases}"
|
||||
|
|
Loading…
Reference in a new issue