Org reader: respect export setting which disables entities
MathML-like entities, e.g., `\alpha`, can be disabled with the `#+OPTION: e:nil` export setting.
This commit is contained in:
parent
c212886d2b
commit
7c207c3051
4 changed files with 22 additions and 6 deletions
|
@ -47,7 +47,7 @@ exportSetting = choice
|
||||||
, booleanSetting "creator" (\val es -> es { exportWithCreator = val })
|
, booleanSetting "creator" (\val es -> es { exportWithCreator = val })
|
||||||
, complementableListSetting "d" (\val es -> es { exportDrawers = val })
|
, complementableListSetting "d" (\val es -> es { exportDrawers = val })
|
||||||
, ignoredSetting "date"
|
, ignoredSetting "date"
|
||||||
, ignoredSetting "e"
|
, booleanSetting "e" (\val es -> es { exportWithEntities = val })
|
||||||
, booleanSetting "email" (\val es -> es { exportWithEmail = val })
|
, booleanSetting "email" (\val es -> es { exportWithEmail = val })
|
||||||
, ignoredSetting "f"
|
, ignoredSetting "f"
|
||||||
, integerSetting "H" (\val es -> es { exportHeadlineLevels = val })
|
, integerSetting "H" (\val es -> es { exportHeadlineLevels = val })
|
||||||
|
|
|
@ -790,9 +790,12 @@ inlineLaTeX :: PandocMonad m => OrgParser m (F Inlines)
|
||||||
inlineLaTeX = try $ do
|
inlineLaTeX = try $ do
|
||||||
cmd <- inlineLaTeXCommand
|
cmd <- inlineLaTeXCommand
|
||||||
texOpt <- getExportSetting exportWithLatex
|
texOpt <- getExportSetting exportWithLatex
|
||||||
|
allowEntities <- getExportSetting exportWithEntities
|
||||||
ils <- parseAsInlineLaTeX cmd texOpt
|
ils <- parseAsInlineLaTeX cmd texOpt
|
||||||
maybe mzero returnF $
|
maybe mzero returnF $
|
||||||
parseAsMathMLSym cmd `mplus` parseAsMath cmd texOpt `mplus` ils
|
parseAsMathMLSym allowEntities cmd `mplus`
|
||||||
|
parseAsMath cmd texOpt `mplus`
|
||||||
|
ils
|
||||||
where
|
where
|
||||||
parseAsInlineLaTeX :: PandocMonad m
|
parseAsInlineLaTeX :: PandocMonad m
|
||||||
=> Text -> TeXExport -> OrgParser m (Maybe Inlines)
|
=> Text -> TeXExport -> OrgParser m (Maybe Inlines)
|
||||||
|
@ -801,10 +804,15 @@ inlineLaTeX = try $ do
|
||||||
TeXIgnore -> return (Just mempty)
|
TeXIgnore -> return (Just mempty)
|
||||||
TeXVerbatim -> return (Just $ B.str cs)
|
TeXVerbatim -> return (Just $ B.str cs)
|
||||||
|
|
||||||
parseAsMathMLSym :: Text -> Maybe Inlines
|
parseAsMathMLSym :: Bool -> Text -> Maybe Inlines
|
||||||
parseAsMathMLSym cs = B.str <$> MathMLEntityMap.getUnicode (clean cs)
|
parseAsMathMLSym allowEntities cs = do
|
||||||
-- drop initial backslash and any trailing "{}"
|
-- drop initial backslash and any trailing "{}"
|
||||||
where clean = T.dropWhileEnd (`elem` ("{}" :: String)) . T.drop 1
|
let clean = T.dropWhileEnd (`elem` ("{}" :: String)) . T.drop 1
|
||||||
|
-- If entities are disabled, then return the string as text, but
|
||||||
|
-- only if this *is* a MathML entity.
|
||||||
|
case B.str <$> MathMLEntityMap.getUnicode (clean cs) of
|
||||||
|
Just _ | not allowEntities -> Just $ B.str cs
|
||||||
|
x -> x
|
||||||
|
|
||||||
state :: ParserState
|
state :: ParserState
|
||||||
state = def{ stateOptions = def{ readerExtensions =
|
state = def{ stateOptions = def{ readerExtensions =
|
||||||
|
|
|
@ -257,6 +257,7 @@ data ExportSettings = ExportSettings
|
||||||
, exportWithAuthor :: Bool -- ^ Include author in final meta-data
|
, exportWithAuthor :: Bool -- ^ Include author in final meta-data
|
||||||
, exportWithCreator :: Bool -- ^ Include creator in final meta-data
|
, exportWithCreator :: Bool -- ^ Include creator in final meta-data
|
||||||
, exportWithEmail :: Bool -- ^ Include email in final meta-data
|
, exportWithEmail :: Bool -- ^ Include email in final meta-data
|
||||||
|
, exportWithEntities :: Bool -- ^ Include MathML-like entities
|
||||||
, exportWithLatex :: TeXExport -- ^ Handling of raw TeX commands
|
, exportWithLatex :: TeXExport -- ^ Handling of raw TeX commands
|
||||||
, exportWithPlanning :: Bool -- ^ Keep planning info after headlines
|
, exportWithPlanning :: Bool -- ^ Keep planning info after headlines
|
||||||
, exportWithTags :: Bool -- ^ Keep tags as part of headlines
|
, exportWithTags :: Bool -- ^ Keep tags as part of headlines
|
||||||
|
@ -279,6 +280,7 @@ defaultExportSettings = ExportSettings
|
||||||
, exportWithAuthor = True
|
, exportWithAuthor = True
|
||||||
, exportWithCreator = True
|
, exportWithCreator = True
|
||||||
, exportWithEmail = True
|
, exportWithEmail = True
|
||||||
|
, exportWithEntities = True
|
||||||
, exportWithLatex = TeXExport
|
, exportWithLatex = TeXExport
|
||||||
, exportWithPlanning = False
|
, exportWithPlanning = False
|
||||||
, exportWithTags = True
|
, exportWithTags = True
|
||||||
|
|
|
@ -150,6 +150,12 @@ tests =
|
||||||
] =?>
|
] =?>
|
||||||
Pandoc nullMeta mempty
|
Pandoc nullMeta mempty
|
||||||
|
|
||||||
|
, "disable MathML-like entities" =:
|
||||||
|
T.unlines [ "#+OPTIONS: e:nil"
|
||||||
|
, "Icelandic letter: \\thorn"
|
||||||
|
] =?>
|
||||||
|
para "Icelandic letter: \\thorn"
|
||||||
|
|
||||||
, "disable inclusion of todo keywords" =:
|
, "disable inclusion of todo keywords" =:
|
||||||
T.unlines [ "#+OPTIONS: todo:nil"
|
T.unlines [ "#+OPTIONS: todo:nil"
|
||||||
, "** DONE todo export"
|
, "** DONE todo export"
|
||||||
|
|
Loading…
Reference in a new issue