Org reader: support arbitrary raw inlines

Org mode allows arbitrary raw inlines ("export snippets" in Emacs
parlance) to be included as `@@format:raw foreign format text@@`.

Support for this features is added to the Org reader.
This commit is contained in:
Albert Krewinkel 2016-06-13 23:53:14 +02:00
parent cf2502de8f
commit 29552eff3e
2 changed files with 13 additions and 1 deletions

View file

@ -118,6 +118,7 @@ inline =
, subscript
, superscript
, inlineLaTeX
, exportSnippet
, smart
, symbol
] <* (guard =<< newlinesCountWithinLimits)
@ -129,7 +130,7 @@ inlines = trimInlinesF . mconcat <$> many1 inline
-- treat these as potentially non-text when parsing inline:
specialChars :: [Char]
specialChars = "\"$'()*+-,./:;<=>[\\]^_{|}~"
specialChars = "\"$'()*+-,./:;<=>@[\\]^_{|}~"
whitespace :: OrgParser (F Inlines)
@ -841,6 +842,13 @@ inlineLaTeXCommand = try $ do
dropWhileEnd :: (a -> Bool) -> [a] -> [a]
dropWhileEnd p = foldr (\x xs -> if p x && null xs then [] else x : xs) []
exportSnippet :: OrgParser (F Inlines)
exportSnippet = try $ do
string "@@"
format <- many1Till (alphaNum <|> char '-') (char ':')
snippet <- manyTill anyChar (try $ string "@@")
returnF $ B.rawInline format snippet
smart :: OrgParser (F Inlines)
smart = do
getOption readerSmart >>= guard

View file

@ -405,6 +405,10 @@ tests =
"\\notacommand{foo}" =?>
para (rawInline "latex" "\\notacommand{foo}")
, "Export snippet" =:
"@@html:<kbd>M-x org-agenda</kbd>@@" =?>
para (rawInline "html" "<kbd>M-x org-agenda</kbd>")
, "MathML symbol in LaTeX-style" =:
"There is a hackerspace in Lübeck, Germany, called nbsp (unicode symbol: '\\nbsp')." =?>
para ("There is a hackerspace in Lübeck, Germany, called nbsp (unicode symbol: ' ').")