git.iko.soy/typeable/pandoc
on master help sign in
Org reader: respect export setting which disables entities

MathML-like entities, e.g., `\alpha`, can be disabled with the `#+OPTION: e:nil` export setting.

commit738c08bb27dc5b06f3a691eec7aba6052b4942ac authorAlbert Krewinkel <albert@zeitkraut.de> dateTue 30 Jun 2020, 11:36 (6 years ago) parentcf2f8d2
4 files changed+22−6
src/Text/Pandoc/Readers/Org/ExportSettings.hs+1−1 src/Text/Pandoc/Readers/Org/Inlines.hs+13−5 src/Text/Pandoc/Readers/Org/ParserState.hs+2 test/Tests/Readers/Org/Directive.hs+6
src/Text/Pandoc/Readers/Org/ExportSettings.hs+1−1
@@ -47,7 +47,7 @@ exportSetting = choice
4747 , booleanSetting "creator" (\val es -> es { exportWithCreator = val })
4848 , complementableListSetting "d" (\val es -> es { exportDrawers = val })
4949 , ignoredSetting "date"
50− , ignoredSetting "e"
50+ , booleanSetting "e" (\val es -> es { exportWithEntities = val })
5151 , booleanSetting "email" (\val es -> es { exportWithEmail = val })
5252 , ignoredSetting "f"
5353 , integerSetting "H" (\val es -> es { exportHeadlineLevels = val })
src/Text/Pandoc/Readers/Org/Inlines.hs+13−5
@@ -790,9 +790,12 @@ inlineLaTeX :: PandocMonad m => OrgParser m (F Inlines)
790790inlineLaTeX = try $ do
791791 cmd <- inlineLaTeXCommand
792792 texOpt <- getExportSetting exportWithLatex
793+ allowEntities <- getExportSetting exportWithEntities
793794 ils <- parseAsInlineLaTeX cmd texOpt
794795 maybe mzero returnF $
795− parseAsMathMLSym cmd `mplus` parseAsMath cmd texOpt `mplus` ils
796+ parseAsMathMLSym allowEntities cmd `mplus`
797+ parseAsMath cmd texOpt `mplus`
798+ ils
796799 where
797800 parseAsInlineLaTeX :: PandocMonad m
798801 => Text -> TeXExport -> OrgParser m (Maybe Inlines)
@@ -801,10 +804,15 @@ inlineLaTeX = try $ do
801804 TeXIgnore -> return (Just mempty)
802805 TeXVerbatim -> return (Just $ B.str cs)
803806
804− parseAsMathMLSym :: Text -> Maybe Inlines
805− parseAsMathMLSym cs = B.str <$> MathMLEntityMap.getUnicode (clean cs)
806− -- drop initial backslash and any trailing "{}"
807− where clean = T.dropWhileEnd (`elem` ("{}" :: String)) . T.drop 1
807+ parseAsMathMLSym :: Bool -> Text -> Maybe Inlines
808+ parseAsMathMLSym allowEntities cs = do
809+ -- drop initial backslash and any trailing "{}"
810+ let clean = T.dropWhileEnd (`elem` ("{}" :: String)) . T.drop 1
811+ -- If entities are disabled, then return the string as text, but
812+ -- only if this *is* a MathML entity.
813+ case B.str <$> MathMLEntityMap.getUnicode (clean cs) of
814+ Just _ | not allowEntities -> Just $ B.str cs
815+ x -> x
808816
809817 state :: ParserState
810818 state = def{ stateOptions = def{ readerExtensions =
src/Text/Pandoc/Readers/Org/ParserState.hs+2
@@ -257,6 +257,7 @@ data ExportSettings = ExportSettings
257257 , exportWithAuthor :: Bool -- ^ Include author in final meta-data
258258 , exportWithCreator :: Bool -- ^ Include creator in final meta-data
259259 , exportWithEmail :: Bool -- ^ Include email in final meta-data
260+ , exportWithEntities :: Bool -- ^ Include MathML-like entities
260261 , exportWithLatex :: TeXExport -- ^ Handling of raw TeX commands
261262 , exportWithPlanning :: Bool -- ^ Keep planning info after headlines
262263 , exportWithTags :: Bool -- ^ Keep tags as part of headlines
@@ -279,6 +280,7 @@ defaultExportSettings = ExportSettings
279280 , exportWithAuthor = True
280281 , exportWithCreator = True
281282 , exportWithEmail = True
283+ , exportWithEntities = True
282284 , exportWithLatex = TeXExport
283285 , exportWithPlanning = False
284286 , exportWithTags = True
test/Tests/Readers/Org/Directive.hs+6
@@ -150,6 +150,12 @@ tests =
150150 ] =?>
151151 Pandoc nullMeta mempty
152152
153+ , "disable MathML-like entities" =:
154+ T.unlines [ "#+OPTIONS: e:nil"
155+ , "Icelandic letter: \\thorn"
156+ ] =?>
157+ para "Icelandic letter: \\thorn"
158+
153159 , "disable inclusion of todo keywords" =:
154160 T.unlines [ "#+OPTIONS: todo:nil"
155161 , "** DONE todo export"