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

Parsing of special strings (like '...' as ellipsis or '--' as en dash) can be toggled using the `-` option.

commitf56792927fbcebfd25593c488476fee69d078b48 authorAlbert Krewinkel <albert@zeitkraut.de> dateFri 3 Jun 2016, 11:10 (10 years ago) parentd4de845
4 files changed+36−12
src/Text/Pandoc/Readers/Org/Blocks.hs+1−1 src/Text/Pandoc/Readers/Org/Inlines.hs+8−4 src/Text/Pandoc/Readers/Org/ParserState.hs+14−6 src/Text/Pandoc/Readers/Org/Parsing.hs+13−1
src/Text/Pandoc/Readers/Org/Blocks.hs+1−1
@@ -502,7 +502,7 @@ exportSetting = choice
502502 [ booleanSetting "^" setExportSubSuperscripts
503503 , booleanSetting "'" setExportSmartQuotes
504504 , booleanSetting "*" setExportEmphasizedText
505− , ignoredSetting "-"
505+ , booleanSetting "-" setExportSpecialStrings
506506 , ignoredSetting ":"
507507 , ignoredSetting "<"
508508 , ignoredSetting "\\n"
src/Text/Pandoc/Readers/Org/Inlines.hs+8−4
@@ -728,8 +728,12 @@ smart = do
728728 doubleQuoted <|> singleQuoted <|>
729729 choice (map (return <$>) [orgApostrophe, orgDash, orgEllipses])
730730 where
731− orgDash = dash <* updatePositions '-'
732− orgEllipses = ellipses <* updatePositions '.'
731+ orgDash = do
732+ guard =<< getExportSetting exportSpecialStrings
733+ dash <* updatePositions '-'
734+ orgEllipses = do
735+ guard =<< getExportSetting exportSpecialStrings
736+ ellipses <* updatePositions '.'
733737 orgApostrophe =
734738 (char '\'' <|> char '\8217') <* updateLastPreCharPos
735739 <* updateLastForbiddenCharPos
@@ -737,7 +741,7 @@ smart = do
737741
738742singleQuoted :: OrgParser (F Inlines)
739743singleQuoted = try $ do
740− guard . exportSmartQuotes . orgStateExportSettings =<< getState
744+ guard =<< getExportSetting exportSmartQuotes
741745 singleQuoteStart
742746 updatePositions '\''
743747 withQuoteContext InSingleQuote $
@@ -749,7 +753,7 @@ singleQuoted = try $ do
749753-- in the same paragraph.
750754doubleQuoted :: OrgParser (F Inlines)
751755doubleQuoted = try $ do
752− guard . exportSmartQuotes . orgStateExportSettings =<< getState
756+ guard =<< getExportSetting exportSmartQuotes
753757 doubleQuoteStart
754758 updatePositions '"'
755759 contents <- mconcat <$> many (try $ notFollowedBy doubleQuoteEnd >> inline)
src/Text/Pandoc/Readers/Org/ParserState.hs+14−6
@@ -45,6 +45,7 @@ module Text.Pandoc.Readers.Org.ParserState
4545 , setExportDrawers
4646 , setExportEmphasizedText
4747 , setExportSmartQuotes
48+ , setExportSpecialStrings
4849 , setExportSubSuperscripts
4950 , modifyExportSettings
5051 , optionsToParserState
@@ -84,8 +85,9 @@ data ExportSettings = ExportSettings
8485 -- ^ Specify drawer names which should be exported. @Left@ names are
8586 -- explicitly excluded from the resulting output while @Right@ means that
8687 -- only the listed drawer names should be included.
87− , exportEmphasizedText :: Bool -- ^ Parse emphasized text.
88− , exportSmartQuotes :: Bool -- ^ Parse quotes, ellipses, apostrophs smartly
88+ , exportEmphasizedText :: Bool -- ^ Parse emphasized text
89+ , exportSmartQuotes :: Bool -- ^ Parse quotes smartly
90+ , exportSpecialStrings :: Bool -- ^ Parse ellipses and dashes smartly
8991 , exportSubSuperscripts :: Bool -- ^ TeX-like syntax for sub- and superscripts
9092 }
9193
@@ -160,6 +162,7 @@ defaultExportSettings = ExportSettings
160162 { exportDrawers = Left ["LOGBOOK"]
161163 , exportEmphasizedText = True
162164 , exportSmartQuotes = True
165+ , exportSpecialStrings = True
163166 , exportSubSuperscripts = True
164167 }
165168
@@ -182,15 +185,20 @@ setExportDrawers val es = es { exportDrawers = val }
182185setExportEmphasizedText :: ExportSettingSetter Bool
183186setExportEmphasizedText val es = es { exportEmphasizedText = val }
184187
188+-- | Set export options for parsing of smart quotes.
189+setExportSmartQuotes :: ExportSettingSetter Bool
190+setExportSmartQuotes val es = es { exportSmartQuotes = val }
191+
192+-- | Set export options for parsing of special strings (like em/en dashes or
193+-- ellipses).
194+setExportSpecialStrings :: ExportSettingSetter Bool
195+setExportSpecialStrings val es = es { exportSpecialStrings = val }
196+
185197-- | Set export options for sub/superscript parsing. The short syntax will
186198-- not be parsed if this is set set to @False@.
187199setExportSubSuperscripts :: ExportSettingSetter Bool
188200setExportSubSuperscripts val es = es { exportSubSuperscripts = val }
189201
190−-- | Set export options for parsing of smart quotes.
191−setExportSmartQuotes :: ExportSettingSetter Bool
192−setExportSmartQuotes val es = es { exportSmartQuotes = val }
193−
194202-- | Modify a parser state
195203modifyExportSettings :: ExportSettingSetter a -> a -> OrgParserState -> OrgParserState
196204modifyExportSettings setter val state =
src/Text/Pandoc/Readers/Org/Parsing.hs+13−1
@@ -37,6 +37,7 @@ module Text.Pandoc.Readers.Org.Parsing
3737 , skipSpaces1
3838 , inList
3939 , withContext
40+ , getExportSetting
4041 , updateLastForbiddenCharPos
4142 , updateLastPreCharPos
4243 , orgArgKey
@@ -174,9 +175,13 @@ withContext context parser = do
174175 return result
175176
176177--
177−-- Parser state update functions
178+-- Parser state functions
178179--
179180
181+-- | Get an export setting.
182+getExportSetting :: (ExportSettings -> a) -> OrgParser a
183+getExportSetting s = s . orgStateExportSettings <$> getState
184+
180185-- | Set the current position as the last position at which a forbidden char
181186-- was found (i.e. a character which is not allowed at the inner border of
182187-- markup).
@@ -190,13 +195,20 @@ updateLastPreCharPos :: OrgParser ()
190195updateLastPreCharPos = getPosition >>= \p ->
191196 updateState $ \s -> s{ orgStateLastPreCharPos = Just p}
192197
198+--
199+-- Org key-value parsing
200+--
201+
202+-- | Read the key of a plist style key-value list.
193203orgArgKey :: OrgParser String
194204orgArgKey = try $
195205 skipSpaces *> char ':'
196206 *> many1 orgArgWordChar
197207
208+-- | Read the value of a plist style key-value list.
198209orgArgWord :: OrgParser String
199210orgArgWord = many1 orgArgWordChar
200211
212+-- | Chars treated as part of a word in plists.
201213orgArgWordChar :: OrgParser Char
202214orgArgWordChar = alphaNum <|> oneOf "-_"