@@ -38,6 +38,10 @@ module Text.Pandoc.Readers.Org.ParserState
3838 , trimInlinesF
3939 , runF
4040 , returnF
41+ , ExportSettingSetter
42+ , exportSubSuperscripts
43+ , setExportSubSuperscripts
44+ , modifyExportSettings
4145 ) where
4246
4347import Control.Monad (liftM, liftM2)
@@ -70,6 +74,12 @@ type OrgBlockAttributes = M.Map String String
7074-- link-type, the corresponding function transforms the given link string.
7175type OrgLinkFormatters = M.Map String (String -> String)
7276
77+-- | Export settings <http://orgmode.org/manual/Export-settings.html>
78+-- These settings can be changed via OPTIONS statements.
79+data ExportSettings = ExportSettings
80+ { exportSubSuperscripts :: Bool -- ^ TeX-like syntax for sub- and superscripts
81+ }
82+
7383-- | Org-mode parser state
7484data OrgParserState = OrgParserState
7585 { orgStateOptions :: ReaderOptions
@@ -77,6 +87,7 @@ data OrgParserState = OrgParserState
7787 , orgStateBlockAttributes :: OrgBlockAttributes
7888 , orgStateEmphasisCharStack :: [Char]
7989 , orgStateEmphasisNewlines :: Maybe Int
90+ , orgStateExportSettings :: ExportSettings
8091 , orgStateLastForbiddenCharPos :: Maybe SourcePos
8192 , orgStateLastPreCharPos :: Maybe SourcePos
8293 , orgStateLastStrPos :: Maybe SourcePos
@@ -119,6 +130,8 @@ instance HasHeaderMap OrgParserState where
119130 extractHeaderMap = orgStateHeaderMap
120131 updateHeaderMap f s = s{ orgStateHeaderMap = f (orgStateHeaderMap s) }
121132
133+instance Default ExportSettings where
134+ def = defaultExportSettings
122135
123136instance Default OrgParserState where
124137 def = defaultOrgParserState
@@ -130,6 +143,7 @@ defaultOrgParserState = OrgParserState
130143 , orgStateBlockAttributes = M.empty
131144 , orgStateEmphasisCharStack = []
132145 , orgStateEmphasisNewlines = Nothing
146+ , orgStateExportSettings = def
133147 , orgStateLastForbiddenCharPos = Nothing
134148 , orgStateLastPreCharPos = Nothing
135149 , orgStateLastStrPos = Nothing
@@ -142,6 +156,24 @@ defaultOrgParserState = OrgParserState
142156 , orgStateHeaderMap = M.empty
143157 }
144158
159+defaultExportSettings :: ExportSettings
160+defaultExportSettings = ExportSettings
161+ { exportSubSuperscripts = True
162+ }
163+
164+
165+--
166+-- Setter for exporting options
167+--
168+type ExportSettingSetter a = a -> ExportSettings -> ExportSettings
169+
170+setExportSubSuperscripts :: ExportSettingSetter Bool
171+setExportSubSuperscripts val es = es { exportSubSuperscripts = val }
172+
173+-- | Modify a parser state
174+modifyExportSettings :: ExportSettingSetter a -> a -> OrgParserState -> OrgParserState
175+modifyExportSettings setter val state =
176+ state { orgStateExportSettings = setter val . orgStateExportSettings $ state }
145177
146178--
147179-- Parser state reader