git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #1706 from tarleb/org-symbol-entities
78bdc08John MacFarlane
src/Text/Pandoc/Readers/Org.hs+8−1
@@ -42,6 +42,7 @@ import Text.Pandoc.Parsing hiding ( F, unF, askF, asksF, runF
42import Text.Pandoc.Readers.LaTeX (inlineCommand, rawLaTeXInline)
42import Text.Pandoc.Readers.LaTeX (inlineCommand, rawLaTeXInline)
43import Text.Pandoc.Shared (compactify', compactify'DL)
43import Text.Pandoc.Shared (compactify', compactify'DL)
44import Text.TeXMath (readTeX, writePandoc, DisplayType(..))
44import Text.TeXMath (readTeX, writePandoc, DisplayType(..))
45+import qualified Text.TeXMath.Readers.MathML.EntityMap as MathMLEntityMap
45
46
46import Control.Applicative ( Applicative, pure
47import Control.Applicative ( Applicative, pure
47 , (<$>), (<$), (<*>), (<*), (*>) )
48 , (<$>), (<$), (<*>), (<*), (*>) )
@@ -1431,7 +1432,8 @@ simpleSubOrSuperString = try $
1431inlineLaTeX :: OrgParser (F Inlines)
1432inlineLaTeX :: OrgParser (F Inlines)
1432inlineLaTeX = try $ do
1433inlineLaTeX = try $ do
1433 cmd <- inlineLaTeXCommand
1434 cmd <- inlineLaTeXCommand
1435+ maybe mzero returnF $
1434− maybe mzero returnF $ parseAsMath cmd `mplus` parseAsInlineLaTeX cmd
1436+ parseAsMath cmd `mplus` parseAsMathMLSym cmd `mplus` parseAsInlineLaTeX cmd
1435 where
1437 where
1436 parseAsMath :: String -> Maybe Inlines
1438 parseAsMath :: String -> Maybe Inlines
1437 parseAsMath cs = B.fromList <$> texMathToPandoc cs
1439 parseAsMath cs = B.fromList <$> texMathToPandoc cs
@@ -1439,6 +1441,11 @@ inlineLaTeX = try $ do
1439 parseAsInlineLaTeX :: String -> Maybe Inlines
1441 parseAsInlineLaTeX :: String -> Maybe Inlines
1440 parseAsInlineLaTeX cs = maybeRight $ runParser inlineCommand state "" cs
1442 parseAsInlineLaTeX cs = maybeRight $ runParser inlineCommand state "" cs
1441
1443
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+
1442 state :: ParserState
1449 state :: ParserState
1443 state = def{ stateOptions = def{ readerParseRaw = True }}
1450 state = def{ stateOptions = def{ readerParseRaw = True }}
1444
1451
tests/Tests/Readers/Org.hs+12
@@ -276,6 +276,18 @@ tests =
276 "\\notacommand{foo}" =?>
276 "\\notacommand{foo}" =?>
277 para (rawInline "latex" "\\notacommand{foo}")
277 para (rawInline "latex" "\\notacommand{foo}")
278
278
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+
279 , "LaTeX citation" =:
291 , "LaTeX citation" =:
280 "\\cite{Coffee}" =?>
292 "\\cite{Coffee}" =?>
281 let citation = Citation
293 let citation = Citation