git.iko.soy/typeable/pandoc
on master help sign in
Org reader: support smart quotes export option

Reading of smart quotes can be toggled using the `'` option.

commit952a7dac589107cc19e606ff9cf29dfbb33002bc authorAlbert Krewinkel <albert@zeitkraut.de> dateThu 2 Jun 2016, 22:17 (10 years ago) parent729fca3
4 files changed+28−12
src/Text/Pandoc/Readers/Org.hs+3−2 src/Text/Pandoc/Readers/Org/Blocks.hs+1−1 src/Text/Pandoc/Readers/Org/Inlines.hs+2 src/Text/Pandoc/Readers/Org/ParserState.hs+22−9
src/Text/Pandoc/Readers/Org.hs+3−2
@@ -29,7 +29,7 @@ module Text.Pandoc.Readers.Org ( readOrg ) where
2929
3030import Text.Pandoc.Readers.Org.Blocks ( blockList, meta )
3131import Text.Pandoc.Readers.Org.Parsing ( OrgParser, readWithM )
32−import Text.Pandoc.Readers.Org.ParserState ( OrgParserState (..) )
32+import Text.Pandoc.Readers.Org.ParserState ( optionsToParserState )
3333
3434import Text.Pandoc.Definition
3535import Text.Pandoc.Error
@@ -42,7 +42,8 @@ import Control.Monad.Reader ( runReader )
4242readOrg :: ReaderOptions -- ^ Reader options
4343 -> String -- ^ String to parse (assuming @'\n'@ line endings)
4444 -> 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")
4647
4748--
4849-- Parser
src/Text/Pandoc/Readers/Org/Blocks.hs+1−1
@@ -500,7 +500,7 @@ addLinkFormat key formatter = updateState $ \s ->
500500exportSetting :: OrgParser ()
501501exportSetting = choice
502502 [ booleanSetting "^" setExportSubSuperscripts
503− , ignoredSetting "'"
503+ , booleanSetting "'" setExportSmartQuotes
504504 , ignoredSetting "*"
505505 , ignoredSetting "-"
506506 , ignoredSetting ":"
src/Text/Pandoc/Readers/Org/Inlines.hs+2
@@ -730,6 +730,7 @@ smart = do
730730
731731singleQuoted :: OrgParser (F Inlines)
732732singleQuoted = try $ do
733+ guard . exportSmartQuotes . orgStateExportSettings =<< getState
733734 singleQuoteStart
734735 updatePositions '\''
735736 withQuoteContext InSingleQuote $
@@ -741,6 +742,7 @@ singleQuoted = try $ do
741742-- in the same paragraph.
742743doubleQuoted :: OrgParser (F Inlines)
743744doubleQuoted = try $ do
745+ guard . exportSmartQuotes . orgStateExportSettings =<< getState
744746 doubleQuoteStart
745747 updatePositions '"'
746748 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
4242 , returnF
4343 , ExportSettingSetter
4444 , ExportSettings (..)
45− , setExportSubSuperscripts
4645 , setExportDrawers
46+ , setExportSmartQuotes
47+ , setExportSubSuperscripts
4748 , modifyExportSettings
49+ , optionsToParserState
4850 ) where
4951
5052import Control.Monad (liftM, liftM2)
@@ -77,11 +79,12 @@ type OrgLinkFormatters = M.Map String (String -> String)
7779-- | Export settings <http://orgmode.org/manual/Export-settings.html>
7880-- These settings can be changed via OPTIONS statements.
7981data ExportSettings = ExportSettings
80− { exportSubSuperscripts :: Bool -- ^ TeX-like syntax for sub- and superscripts
81− , exportDrawers :: Either [String] [String]
82+ { exportDrawers :: Either [String] [String]
8283 -- ^ Specify drawer names which should be exported. @Left@ names are
8384 -- explicitly excluded from the resulting output while @Right@ means that
8485 -- 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
8588 }
8689
8790-- | Org-mode parser state
@@ -152,25 +155,35 @@ defaultOrgParserState = OrgParserState
152155
153156defaultExportSettings :: ExportSettings
154157defaultExportSettings = ExportSettings
155− { exportSubSuperscripts = True
156− , exportDrawers = Left ["LOGBOOK"]
158+ { exportDrawers = Left ["LOGBOOK"]
159+ , exportSmartQuotes = True
160+ , exportSubSuperscripts = True
157161 }
158162
163+optionsToParserState :: ReaderOptions -> OrgParserState
164+optionsToParserState opts =
165+ def { orgStateOptions = opts }
166+
159167
160168--
161169-- Setter for exporting options
162170--
163171type ExportSettingSetter a = a -> ExportSettings -> ExportSettings
164172
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+
165178-- | Set export options for sub/superscript parsing. The short syntax will
166179-- not be parsed if this is set set to @False@.
167180setExportSubSuperscripts :: ExportSettingSetter Bool
168181setExportSubSuperscripts val es = es { exportSubSuperscripts = val }
169182
170−-- | Set export options for drawers. See the @exportDrawers@ in ADT
171−-- @ExportSettings@ for details.
172−setExportDrawers :: ExportSettingSetter (Either [String] [String])
173−setExportDrawers val es = es { exportDrawers = val }
183+-- | Set export options for sub/superscript parsing. The short syntax will
184+-- not be parsed if this is set set to @False@.
185+setExportSmartQuotes :: ExportSettingSetter Bool
186+setExportSmartQuotes val es = es { exportSmartQuotes = val }
174187
175188-- | Modify a parser state
176189modifyExportSettings :: ExportSettingSetter a -> a -> OrgParserState -> OrgParserState