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 })
|
||||
, complementableListSetting "d" (\val es -> es { exportDrawers = val })
|
||||
, ignoredSetting "date"
|
||||
, ignoredSetting "e"
|
||||
, booleanSetting "e" (\val es -> es { exportWithEntities = val })
|
||||
, booleanSetting "email" (\val es -> es { exportWithEmail = val })
|
||||
, ignoredSetting "f"
|
||||
, integerSetting "H" (\val es -> es { exportHeadlineLevels = val })
|
||||
|
|
|
@ -790,9 +790,12 @@ inlineLaTeX :: PandocMonad m => OrgParser m (F Inlines)
|
|||
inlineLaTeX = try $ do
|
||||
cmd <- inlineLaTeXCommand
|
||||
texOpt <- getExportSetting exportWithLatex
|
||||
allowEntities <- getExportSetting exportWithEntities
|
||||
ils <- parseAsInlineLaTeX cmd texOpt
|
||||
maybe mzero returnF $
|
||||
parseAsMathMLSym cmd `mplus` parseAsMath cmd texOpt `mplus` ils
|
||||
parseAsMathMLSym allowEntities cmd `mplus`
|
||||
parseAsMath cmd texOpt `mplus`
|
||||
ils
|
||||
where
|
||||
parseAsInlineLaTeX :: PandocMonad m
|
||||
=> Text -> TeXExport -> OrgParser m (Maybe Inlines)
|
||||
|
@ -801,10 +804,15 @@ inlineLaTeX = try $ do
|
|||
TeXIgnore -> return (Just mempty)
|
||||
TeXVerbatim -> return (Just $ B.str cs)
|
||||
|
||||
parseAsMathMLSym :: Text -> Maybe Inlines
|
||||
parseAsMathMLSym cs = B.str <$> MathMLEntityMap.getUnicode (clean cs)
|
||||
parseAsMathMLSym :: Bool -> Text -> Maybe Inlines
|
||||
parseAsMathMLSym allowEntities cs = do
|
||||
-- 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 = def{ stateOptions = def{ readerExtensions =
|
||||
|
|
|
@ -257,6 +257,7 @@ data ExportSettings = ExportSettings
|
|||
, exportWithAuthor :: Bool -- ^ Include author in final meta-data
|
||||
, exportWithCreator :: Bool -- ^ Include creator 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
|
||||
, exportWithPlanning :: Bool -- ^ Keep planning info after headlines
|
||||
, exportWithTags :: Bool -- ^ Keep tags as part of headlines
|
||||
|
@ -279,6 +280,7 @@ defaultExportSettings = ExportSettings
|
|||
, exportWithAuthor = True
|
||||
, exportWithCreator = True
|
||||
, exportWithEmail = True
|
||||
, exportWithEntities = True
|
||||
, exportWithLatex = TeXExport
|
||||
, exportWithPlanning = False
|
||||
, exportWithTags = True
|
||||
|
|
|
@ -150,6 +150,12 @@ tests =
|
|||
] =?>
|
||||
Pandoc nullMeta mempty
|
||||
|
||||
, "disable MathML-like entities" =:
|
||||
T.unlines [ "#+OPTIONS: e:nil"
|
||||
, "Icelandic letter: \\thorn"
|
||||
] =?>
|
||||
para "Icelandic letter: \\thorn"
|
||||
|
||||
, "disable inclusion of todo keywords" =:
|
||||
T.unlines [ "#+OPTIONS: todo:nil"
|
||||
, "** DONE todo export"
|
||||
|
|
Loading…
Reference in a new issue