aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorAlbert Krewinkel <tarleb@moltkeplatz.de>2014-04-10 15:11:03 +0200
committerAlbert Krewinkel <tarleb@moltkeplatz.de>2014-04-10 15:32:02 +0200
commit1715d7cee0b9388ac77b8b2a31fcbb00ead80adf (patch)
tree92c4f0d3df14d2b9e065336a2bb994da00acb6f0 /src/Text/Pandoc
parenta9eb0caabbb37d7ceb6f6791f375eac4b509b058 (diff)
downloadpandoc-1715d7cee0b9388ac77b8b2a31fcbb00ead80adf.tar.gz
Org reader: Support more inline/display math variants
Support all of the following variants as valid ways to define inline or display math inlines: - `\[..\]` (display) - `$$..$$` (display) - `\(..\)` (inline) - `$..$` (inline) This closes #1223. Again.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Readers/Org.hs28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/Org.hs b/src/Text/Pandoc/Readers/Org.hs
index 392b17bbc..1d0400d96 100644
--- a/src/Text/Pandoc/Readers/Org.hs
+++ b/src/Text/Pandoc/Readers/Org.hs
@@ -512,6 +512,7 @@ inline =
, underline
, code
, math
+ , displayMath
, verbatim
, subscript
, superscript
@@ -607,7 +608,15 @@ verbatim :: OrgParser Inlines
verbatim = B.rawInline "" <$> verbatimBetween '~'
math :: OrgParser Inlines
-math = B.math <$> mathStringBetween '$'
+math = B.math <$> choice [ math1CharBetween '$'
+ , mathStringBetween '$'
+ , rawMathBetween "\\(" "\\)"
+ ]
+
+displayMath :: OrgParser Inlines
+displayMath = B.displayMath <$> choice [ rawMathBetween "\\[" "\\]"
+ , rawMathBetween "$$" "$$"
+ ]
subscript :: OrgParser Inlines
subscript = B.subscript <$> (try $ char '_' *> maybeGroupedByBraces)
@@ -655,6 +664,21 @@ mathStringBetween c = try $ do
final <- mathEnd c
return $ body ++ [final]
+-- | Parse a single character between @c@ using math rules
+math1CharBetween :: Char
+ -> OrgParser String
+math1CharBetween c = try $ do
+ char c
+ res <- noneOf $ c:mathForbiddenBorderChars
+ char c
+ eof <|> lookAhead (oneOf mathPostChars) *> return ()
+ return [res]
+
+rawMathBetween :: String
+ -> String
+ -> OrgParser String
+rawMathBetween s e = try $ string s *> manyTill anyChar (try $ string e)
+
-- | Parses the start (opening character) of emphasis
emphasisStart :: Char -> OrgParser Char
emphasisStart c = try $ do
@@ -747,7 +771,7 @@ emphasisAllowedNewlines = 1
-- | Chars allowed after an inline ($...$) math statement
mathPostChars :: [Char]
-mathPostChars = "\t\n \"',-.:;?"
+mathPostChars = "\t\n \"'),-.:;?"
-- | Chars not allowed at the (inner) border of math
mathForbiddenBorderChars :: [Char]