git.iko.soy/typeable/pandoc
on master help sign in
Org reader: fix smart parsing behavior

Parsing of smart quotes and special characters can either be enabled via the `smart` language extension or the `'` and `-` export options. Smart parsing is active if either the extension or export option is enabled. Only smart parsing of special characters (like ellipses and en and em dashes) is enabled by default, while smart quotes are disabled. This means that all smart parsing features will be enabled by adding the `smart` language extension. Fine-grained control is possible by leaving the language extension disabled. In that case, smart parsing is controlled via the aforementioned export OPTIONS only. Previously, all smart parsing was disabled unless the language extension was enabled.

commit7a09b7b21dbbee34332047d07eae88fe152340b8 authorAlbert Krewinkel <albert@zeitkraut.de> dateThu 18 May 2017, 23:12 (9 years ago) parent118c8dd
3 files changed+17−12
src/Text/Pandoc/Readers/Org/Inlines.hs+14−9 src/Text/Pandoc/Readers/Org/ParserState.hs+1−1 test/Tests/Readers/Org.hs+2−2
src/Text/Pandoc/Readers/Org/Inlines.hs+14−9
@@ -862,24 +862,29 @@ macro = try $ do
862862
863863smart :: PandocMonad m => OrgParser m (F Inlines)
864864smart = do
865− guardEnabled Ext_smart
866865 doubleQuoted <|> singleQuoted <|>
867866 choice (map (return <$>) [orgApostrophe, orgDash, orgEllipses])
868867 where
869868 orgDash = do
870− guard =<< getExportSetting exportSpecialStrings
869+ guardOrSmartEnabled =<< getExportSetting exportSpecialStrings
871870 dash <* updatePositions '-'
872871 orgEllipses = do
873− guard =<< getExportSetting exportSpecialStrings
872+ guardOrSmartEnabled =<< getExportSetting exportSpecialStrings
874873 ellipses <* updatePositions '.'
875− orgApostrophe =
876− (char '\'' <|> char '\8217') <* updateLastPreCharPos
877− <* updateLastForbiddenCharPos
878− *> return (B.str "\x2019")
874+ orgApostrophe = do
875+ guardEnabled Ext_smart
876+ (char '\'' <|> char '\8217') <* updateLastPreCharPos
877+ <* updateLastForbiddenCharPos
878+ return (B.str "\x2019")
879+
880+guardOrSmartEnabled :: PandocMonad m => Bool -> OrgParser m ()
881+guardOrSmartEnabled b = do
882+ smartExtension <- extensionEnabled Ext_smart <$> getOption readerExtensions
883+ guard (b || smartExtension)
879884
880885singleQuoted :: PandocMonad m => OrgParser m (F Inlines)
881886singleQuoted = try $ do
882− guard =<< getExportSetting exportSmartQuotes
887+ guardOrSmartEnabled =<< getExportSetting exportSmartQuotes
883888 singleQuoteStart
884889 updatePositions '\''
885890 withQuoteContext InSingleQuote $
@@ -891,7 +896,7 @@ singleQuoted = try $ do
891896-- in the same paragraph.
892897doubleQuoted :: PandocMonad m => OrgParser m (F Inlines)
893898doubleQuoted = try $ do
894− guard =<< getExportSetting exportSmartQuotes
899+ guardOrSmartEnabled =<< getExportSetting exportSmartQuotes
895900 doubleQuoteStart
896901 updatePositions '"'
897902 contents <- mconcat <$> many (try $ notFollowedBy doubleQuoteEnd >> inline)
src/Text/Pandoc/Readers/Org/ParserState.hs+1−1
@@ -252,7 +252,7 @@ defaultExportSettings = ExportSettings
252252 , exportDrawers = Left ["LOGBOOK"]
253253 , exportEmphasizedText = True
254254 , exportHeadlineLevels = 3
255− , exportSmartQuotes = True
255+ , exportSmartQuotes = False
256256 , exportSpecialStrings = True
257257 , exportSubSuperscripts = True
258258 , exportWithAuthor = True
test/Tests/Readers/Org.hs+2−2
@@ -961,8 +961,8 @@ tests =
961961 ]
962962
963963 , "Not a Horizontal Rule" =:
964− "----- five dashes" =?>
965− (para $ spcSep [ "-----", "five", "dashes" ])
964+ "----- em and en dash" =?>
965+ para "\8212\8211 em and en dash"
966966
967967 , "Comment Block" =:
968968 unlines [ "#+BEGIN_COMMENT"