aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-06-14 20:21:37 -0600
committerGitHub <noreply@github.com>2016-06-14 20:21:37 -0600
commit15d2c09ba134094afe8fb4b74ccf50754f11e865 (patch)
tree16de375633d41f5e660617cffe5b1c6c8b3d8c8b
parent5ea3cc647b2645baeb6247d8bc422989d87b42aa (diff)
parent29552eff3e1c0a7eab8b114ac58ca83422a84fb0 (diff)
downloadpandoc-15d2c09ba134094afe8fb4b74ccf50754f11e865.tar.gz
Merge pull request #2980 from tarleb/org-raw-inlines
Org reader: raw inlines in arbitrary formats
-rw-r--r--src/Text/Pandoc/Readers/Org/Inlines.hs10
-rw-r--r--src/Text/Pandoc/Writers/Org.hs7
-rw-r--r--tests/Tests/Readers/Org.hs4
3 files changed, 17 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Readers/Org/Inlines.hs b/src/Text/Pandoc/Readers/Org/Inlines.hs
index dc6b739fe..d0e007312 100644
--- a/src/Text/Pandoc/Readers/Org/Inlines.hs
+++ b/src/Text/Pandoc/Readers/Org/Inlines.hs
@@ -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
diff --git a/src/Text/Pandoc/Writers/Org.hs b/src/Text/Pandoc/Writers/Org.hs
index f87aeca81..79ca37395 100644
--- a/src/Text/Pandoc/Writers/Org.hs
+++ b/src/Text/Pandoc/Writers/Org.hs
@@ -305,9 +305,10 @@ inlineToOrg (Math t str) = do
return $ if t == InlineMath
then "$" <> text str <> "$"
else "$$" <> text str <> "$$"
-inlineToOrg (RawInline f str) | isRawFormat f =
- return $ text str
-inlineToOrg (RawInline _ _) = return empty
+inlineToOrg (RawInline f@(Format f') str) =
+ return $ if isRawFormat f
+ then text str
+ else "@@" <> text f' <> ":" <> text str <> "@@"
inlineToOrg (LineBreak) = return (text "\\\\" <> cr)
inlineToOrg Space = return space
inlineToOrg SoftBreak = do
diff --git a/tests/Tests/Readers/Org.hs b/tests/Tests/Readers/Org.hs
index ab50aa49c..56dedee55 100644
--- a/tests/Tests/Readers/Org.hs
+++ b/tests/Tests/Readers/Org.hs
@@ -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: ' ').")