git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #1706 from tarleb/org-symbol-entities

Org reader: parse LaTeX-style MathML entities

commit78bdc08de7191e81c198832b4dd62de15c549027 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 21 Oct 2014, 10:11 (12 years ago) parent0714a36a5eb02f
2 files changed+20−1
src/Text/Pandoc/Readers/Org.hs+8−1 tests/Tests/Readers/Org.hs+12
src/Text/Pandoc/Readers/Org.hs+8−1
@@ -42,6 +42,7 @@ import Text.Pandoc.Parsing hiding ( F, unF, askF, asksF, runF
4242import Text.Pandoc.Readers.LaTeX (inlineCommand, rawLaTeXInline)
4343import Text.Pandoc.Shared (compactify', compactify'DL)
4444import Text.TeXMath (readTeX, writePandoc, DisplayType(..))
45+import qualified Text.TeXMath.Readers.MathML.EntityMap as MathMLEntityMap
4546
4647import Control.Applicative ( Applicative, pure
4748 , (<$>), (<$), (<*>), (<*), (*>) )
@@ -1431,7 +1432,8 @@ simpleSubOrSuperString = try $
14311432inlineLaTeX :: OrgParser (F Inlines)
14321433inlineLaTeX = try $ do
14331434 cmd <- inlineLaTeXCommand
1434− maybe mzero returnF $ parseAsMath cmd `mplus` parseAsInlineLaTeX cmd
1435+ maybe mzero returnF $
1436+ parseAsMath cmd `mplus` parseAsMathMLSym cmd `mplus` parseAsInlineLaTeX cmd
14351437 where
14361438 parseAsMath :: String -> Maybe Inlines
14371439 parseAsMath cs = B.fromList <$> texMathToPandoc cs
@@ -1439,6 +1441,11 @@ inlineLaTeX = try $ do
14391441 parseAsInlineLaTeX :: String -> Maybe Inlines
14401442 parseAsInlineLaTeX cs = maybeRight $ runParser inlineCommand state "" cs
14411443
1444+ parseAsMathMLSym :: String -> Maybe Inlines
1445+ parseAsMathMLSym cs = B.str <$> MathMLEntityMap.getUnicode (clean cs)
1446+ -- dropWhileEnd would be nice here, but it's not available before base 4.5
1447+ where clean = reverse . dropWhile (`elem` "{}") . reverse . drop 1
1448+
14421449 state :: ParserState
14431450 state = def{ stateOptions = def{ readerParseRaw = True }}
14441451
tests/Tests/Readers/Org.hs+12
@@ -276,6 +276,18 @@ tests =
276276 "\\notacommand{foo}" =?>
277277 para (rawInline "latex" "\\notacommand{foo}")
278278
279+ , "MathML symbol in LaTeX-style" =:
280+ "There is a hackerspace in Lübeck, Germany, called nbsp (unicode symbol: '\\nbsp')." =?>
281+ para ("There is a hackerspace in Lübeck, Germany, called nbsp (unicode symbol: ' ').")
282+
283+ , "MathML symbol in LaTeX-style, including braces" =:
284+ "\\Aacute{}stor" =?>
285+ para "Ástor"
286+
287+ , "MathML copy sign" =:
288+ "\\copy" =?>
289+ para "©"
290+
279291 , "LaTeX citation" =:
280292 "\\cite{Coffee}" =?>
281293 let citation = Citation