git.iko.soy/typeable/pandoc
on master help sign in
Org reader: support smart quotes export option
952a7daAlbert Krewinkel
src/Text/Pandoc/Readers/Org.hs+3−2
@@ -29,7 +29,7 @@ module Text.Pandoc.Readers.Org ( readOrg ) where
29
29
30import Text.Pandoc.Readers.Org.Blocks ( blockList, meta )
30import Text.Pandoc.Readers.Org.Blocks ( blockList, meta )
31import Text.Pandoc.Readers.Org.Parsing ( OrgParser, readWithM )
31import Text.Pandoc.Readers.Org.Parsing ( OrgParser, readWithM )
32−import Text.Pandoc.Readers.Org.ParserState ( OrgParserState (..) )
32+import Text.Pandoc.Readers.Org.ParserState ( optionsToParserState )
33
33
34import Text.Pandoc.Definition
34import Text.Pandoc.Definition
35import Text.Pandoc.Error
35import Text.Pandoc.Error
@@ -42,7 +42,8 @@ import Control.Monad.Reader ( runReader )
42readOrg :: ReaderOptions -- ^ Reader options
42readOrg :: ReaderOptions -- ^ Reader options
43 -> String -- ^ String to parse (assuming @'\n'@ line endings)
43 -> String -- ^ String to parse (assuming @'\n'@ line endings)
44 -> Either PandocError Pandoc
44 -> Either PandocError Pandoc
45−readOrg opts s = flip runReader def $ readWithM parseOrg def{ orgStateOptions = opts } (s ++ "\n\n")
45+readOrg opts s = flip runReader def $
46+ readWithM parseOrg (optionsToParserState opts) (s ++ "\n\n")
46
47
47--
48--
48-- Parser
49-- Parser
src/Text/Pandoc/Readers/Org/Blocks.hs+1−1
@@ -500,7 +500,7 @@ addLinkFormat key formatter = updateState $ \s ->
500exportSetting :: OrgParser ()
500exportSetting :: OrgParser ()
501exportSetting = choice
501exportSetting = choice
502 [ booleanSetting "^" setExportSubSuperscripts
502 [ booleanSetting "^" setExportSubSuperscripts
503− , ignoredSetting "'"
503+ , booleanSetting "'" setExportSmartQuotes
504 , ignoredSetting "*"
504 , ignoredSetting "*"
505 , ignoredSetting "-"
505 , ignoredSetting "-"
506 , ignoredSetting ":"
506 , ignoredSetting ":"
src/Text/Pandoc/Readers/Org/Inlines.hs+2
@@ -730,6 +730,7 @@ smart = do
730
730
731singleQuoted :: OrgParser (F Inlines)
731singleQuoted :: OrgParser (F Inlines)
732singleQuoted = try $ do
732singleQuoted = try $ do
733+ guard . exportSmartQuotes . orgStateExportSettings =<< getState
733 singleQuoteStart
734 singleQuoteStart
734 updatePositions '\''
735 updatePositions '\''
735 withQuoteContext InSingleQuote $
736 withQuoteContext InSingleQuote $
@@ -741,6 +742,7 @@ singleQuoted = try $ do
741-- in the same paragraph.
742-- in the same paragraph.
742doubleQuoted :: OrgParser (F Inlines)
743doubleQuoted :: OrgParser (F Inlines)
743doubleQuoted = try $ do
744doubleQuoted = try $ do
745+ guard . exportSmartQuotes . orgStateExportSettings =<< getState
744 doubleQuoteStart
746 doubleQuoteStart
745 updatePositions '"'
747 updatePositions '"'
746 contents <- mconcat <$> many (try $ notFollowedBy doubleQuoteEnd >> inline)
748 contents <- mconcat <$> many (try $ notFollowedBy doubleQuoteEnd >> inline)
src/Text/Pandoc/Readers/Org/ParserState.hs+22−9
@@ -42,9 +42,11 @@ module Text.Pandoc.Readers.Org.ParserState
42 , returnF
42 , returnF
43 , ExportSettingSetter
43 , ExportSettingSetter
44 , ExportSettings (..)
44 , ExportSettings (..)
45− , setExportSubSuperscripts
46 , setExportDrawers
45 , setExportDrawers
46+ , setExportSmartQuotes
47+ , setExportSubSuperscripts
47 , modifyExportSettings
48 , modifyExportSettings
49+ , optionsToParserState
48 ) where
50 ) where
49
51
50import Control.Monad (liftM, liftM2)
52import Control.Monad (liftM, liftM2)
@@ -77,11 +79,12 @@ type OrgLinkFormatters = M.Map String (String -> String)
77-- | Export settings <http://orgmode.org/manual/Export-settings.html>
79-- | Export settings <http://orgmode.org/manual/Export-settings.html>
78-- These settings can be changed via OPTIONS statements.
80-- These settings can be changed via OPTIONS statements.
79data ExportSettings = ExportSettings
81data ExportSettings = ExportSettings
80− { exportSubSuperscripts :: Bool -- ^ TeX-like syntax for sub- and superscripts
81− , exportDrawers :: Either [String] [String]
82+ { exportDrawers :: Either [String] [String]
82 -- ^ Specify drawer names which should be exported. @Left@ names are
83 -- ^ Specify drawer names which should be exported. @Left@ names are
83 -- explicitly excluded from the resulting output while @Right@ means that
84 -- explicitly excluded from the resulting output while @Right@ means that
84 -- only the listed drawer names should be included.
85 -- only the listed drawer names should be included.
86+ , exportSmartQuotes :: Bool -- ^ Parse quotes, ellipses, apostrophs smartly
87+ , exportSubSuperscripts :: Bool -- ^ TeX-like syntax for sub- and superscripts
85 }
88 }
86
89
87-- | Org-mode parser state
90-- | Org-mode parser state
@@ -152,25 +155,35 @@ defaultOrgParserState = OrgParserState
152
155
153defaultExportSettings :: ExportSettings
156defaultExportSettings :: ExportSettings
154defaultExportSettings = ExportSettings
157defaultExportSettings = ExportSettings
155− { exportSubSuperscripts = True
156− , exportDrawers = Left ["LOGBOOK"]
158+ { exportDrawers = Left ["LOGBOOK"]
159+ , exportSmartQuotes = True
160+ , exportSubSuperscripts = True
157 }
161 }
158
162
163+optionsToParserState :: ReaderOptions -> OrgParserState
164+optionsToParserState opts =
165+ def { orgStateOptions = opts }
166+
159
167
160--
168--
161-- Setter for exporting options
169-- Setter for exporting options
162--
170--
163type ExportSettingSetter a = a -> ExportSettings -> ExportSettings
171type ExportSettingSetter a = a -> ExportSettings -> ExportSettings
164
172
173+-- | Set export options for drawers. See the @exportDrawers@ in ADT
174+-- @ExportSettings@ for details.
175+setExportDrawers :: ExportSettingSetter (Either [String] [String])
176+setExportDrawers val es = es { exportDrawers = val }
177+
165-- | Set export options for sub/superscript parsing. The short syntax will
178-- | Set export options for sub/superscript parsing. The short syntax will
166-- not be parsed if this is set set to @False@.
179-- not be parsed if this is set set to @False@.
167setExportSubSuperscripts :: ExportSettingSetter Bool
180setExportSubSuperscripts :: ExportSettingSetter Bool
168setExportSubSuperscripts val es = es { exportSubSuperscripts = val }
181setExportSubSuperscripts val es = es { exportSubSuperscripts = val }
169
182
170−-- | Set export options for drawers. See the @exportDrawers@ in ADT
183+-- | Set export options for sub/superscript parsing. The short syntax will
171−-- @ExportSettings@ for details.
184+-- not be parsed if this is set set to @False@.
172−setExportDrawers :: ExportSettingSetter (Either [String] [String])
185+setExportSmartQuotes :: ExportSettingSetter Bool
173−setExportDrawers val es = es { exportDrawers = val }
186+setExportSmartQuotes val es = es { exportSmartQuotes = val }
174
187
175-- | Modify a parser state
188-- | Modify a parser state
176modifyExportSettings :: ExportSettingSetter a -> a -> OrgParserState -> OrgParserState
189modifyExportSettings :: ExportSettingSetter a -> a -> OrgParserState -> OrgParserState