git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #2980 from tarleb/org-raw-inlines

Org reader: raw inlines in arbitrary formats

commit15d2c09ba134094afe8fb4b74ccf50754f11e865 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 14 Jun 2016, 20:21 (10 years ago) parent5ea3cc629552ef
3 files changed+17−4
src/Text/Pandoc/Readers/Org/Inlines.hs+9−1 src/Text/Pandoc/Writers/Org.hs+4−3 tests/Tests/Readers/Org.hs+4
src/Text/Pandoc/Readers/Org/Inlines.hs+9−1
@@ -118,6 +118,7 @@ inline =
118118 , subscript
119119 , superscript
120120 , inlineLaTeX
121+ , exportSnippet
121122 , smart
122123 , symbol
123124 ] <* (guard =<< newlinesCountWithinLimits)
@@ -129,7 +130,7 @@ inlines = trimInlinesF . mconcat <$> many1 inline
129130
130131-- treat these as potentially non-text when parsing inline:
131132specialChars :: [Char]
132−specialChars = "\"$'()*+-,./:;<=>[\\]^_{|}~"
133+specialChars = "\"$'()*+-,./:;<=>@[\\]^_{|}~"
133134
134135
135136whitespace :: OrgParser (F Inlines)
@@ -841,6 +842,13 @@ inlineLaTeXCommand = try $ do
841842dropWhileEnd :: (a -> Bool) -> [a] -> [a]
842843dropWhileEnd p = foldr (\x xs -> if p x && null xs then [] else x : xs) []
843844
845+exportSnippet :: OrgParser (F Inlines)
846+exportSnippet = try $ do
847+ string "@@"
848+ format <- many1Till (alphaNum <|> char '-') (char ':')
849+ snippet <- manyTill anyChar (try $ string "@@")
850+ returnF $ B.rawInline format snippet
851+
844852smart :: OrgParser (F Inlines)
845853smart = do
846854 getOption readerSmart >>= guard
src/Text/Pandoc/Writers/Org.hs+4−3
@@ -305,9 +305,10 @@ inlineToOrg (Math t str) = do
305305 return $ if t == InlineMath
306306 then "$" <> text str <> "$"
307307 else "$$" <> text str <> "$$"
308−inlineToOrg (RawInline f str) | isRawFormat f =
309− return $ text str
310−inlineToOrg (RawInline _ _) = return empty
308+inlineToOrg (RawInline f@(Format f') str) =
309+ return $ if isRawFormat f
310+ then text str
311+ else "@@" <> text f' <> ":" <> text str <> "@@"
311312inlineToOrg (LineBreak) = return (text "\\\\" <> cr)
312313inlineToOrg Space = return space
313314inlineToOrg SoftBreak = do
tests/Tests/Readers/Org.hs+4
@@ -405,6 +405,10 @@ tests =
405405 "\\notacommand{foo}" =?>
406406 para (rawInline "latex" "\\notacommand{foo}")
407407
408+ , "Export snippet" =:
409+ "@@html:<kbd>M-x org-agenda</kbd>@@" =?>
410+ para (rawInline "html" "<kbd>M-x org-agenda</kbd>")
411+
408412 , "MathML symbol in LaTeX-style" =:
409413 "There is a hackerspace in Lübeck, Germany, called nbsp (unicode symbol: '\\nbsp')." =?>
410414 para ("There is a hackerspace in Lübeck, Germany, called nbsp (unicode symbol: ' ').")