git.iko.soy/typeable/pandoc
on master help sign in
Make the `smart` extension affect the Markdown writer.

Thus, to "unsmartify" something that has been parsed as smart by pandoc, you can use `-t markdown+smart`, and straight quotes will be produced instead of curly quotes, etc. Example: % pandoc -f latex -t markdown+smart ``hi''---ok ^D "hi"---ok

commit412ed3f1321a49d3c3b2119ebd28705376bbd551 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 15 Jan 2017, 11:56 (10 years ago) parent5bf9125
2 files changed+41−17
MANUAL.txt+12−11 src/Text/Pandoc/Writers/Markdown.hs+29−6
MANUAL.txt+12−11
@@ -3383,17 +3383,18 @@ example, `markdown+hard_line_breaks` is Markdown with hard line breaks.
33833383
33843384#### Extension: `smart` ####
33853385
3386−Produce typographically correct output, converting straight
3387−quotes to curly quotes, `---` to em-dashes, `--` to en-dashes,
3388−and `...` to ellipses. Nonbreaking spaces are inserted after
3389−certain abbreviations, such as "Mr." (Note: This option is
3390−selected automatically when the output format is `latex` or
3391−`context`, unless `--no-tex-ligatures` is used. It has no
3392−effect for `latex` input.)
3393−
3394−Note: if your LaTeX template or any included header file call
3395−for the [`csquotes`] package, pandoc will detect this
3396−automatically and use `\enquote{...}` for quoted text.
3386+Interpret straight quotes as curly quotes, `---` as em-dashes,
3387+`--` as en-dashes, and `...` as ellipses. Nonbreaking spaces are
3388+inserted after certain abbreviations, such as "Mr."
3389+
3390+Notes:
3391+
3392+ * This extension option is selected automatically when the
3393+ output format is `latex` or `context`, unless
3394+ `--no-tex-ligatures` is used. It has no effect for `latex` input.
3395+ * If your LaTeX template or any included header file call
3396+ for the [`csquotes`] package, pandoc will detect this
3397+ automatically and use `\enquote{...}` for quoted text.
33973398
33983399#### Extension: `old_dashes` ####
33993400
src/Text/Pandoc/Writers/Markdown.hs+29−6
@@ -280,7 +280,10 @@ escapeString opts = escapeStringUsing markdownEscapes
280280 (if isEnabled Ext_tex_math_dollars opts
281281 then ('$':)
282282 else id) $
283− "\\`*_[]#"
283+ "\\`*_[]#" ++
284+ if isEnabled Ext_smart opts
285+ then "\"'"
286+ else ""
284287
285288-- | Construct table of contents from list of header blocks.
286289tableOfContents :: PandocMonad m => WriterOptions -> [Block] -> m Doc
@@ -949,10 +952,14 @@ inlineToMarkdown opts (SmallCaps lst) = do
949952 else inlineListToMarkdown opts $ capitalize lst
950953inlineToMarkdown opts (Quoted SingleQuote lst) = do
951954 contents <- inlineListToMarkdown opts lst
952− return $ "‘" <> contents <> "’"
955+ return $ if isEnabled Ext_smart opts
956+ then "'" <> contents <> "'"
957+ else "‘" <> contents <> "’"
953958inlineToMarkdown opts (Quoted DoubleQuote lst) = do
954959 contents <- inlineListToMarkdown opts lst
955− return $ "“" <> contents <> "”"
960+ return $ if isEnabled Ext_smart opts
961+ then "\"" <> contents <> "\""
962+ else "“" <> contents <> "”"
956963inlineToMarkdown opts (Code attr str) = do
957964 let tickGroups = filter (\s -> '`' `elem` s) $ group str
958965 let longest = if null tickGroups
@@ -969,9 +976,13 @@ inlineToMarkdown opts (Code attr str) = do
969976 else return $ text (marker ++ spacer ++ str ++ spacer ++ marker) <> attrs
970977inlineToMarkdown opts (Str str) = do
971978 isPlain <- asks envPlain
972− if isPlain
973− then return $ text str
974− else return $ text $ escapeString opts str
979+ let str' = (if isEnabled Ext_smart opts
980+ then unsmartify opts
981+ else id) $
982+ if isPlain
983+ then str
984+ else escapeString opts str
985+ return $ text str'
975986inlineToMarkdown opts (Math InlineMath str) =
976987 case writerHTMLMathMethod opts of
977988 WebTeX url ->
@@ -1126,3 +1137,15 @@ makeMathPlainer = walk go
11261137 go (Emph xs) = Span nullAttr xs
11271138 go x = x
11281139
1140+unsmartify :: WriterOptions -> String -> String
1141+unsmartify opts ('\8217':xs) = '\'' : unsmartify opts xs
1142+unsmartify opts ('\8230':xs) = "..." ++ unsmartify opts xs
1143+unsmartify opts ('\8211':xs)
1144+ | isEnabled Ext_old_dashes opts = '-' : unsmartify opts xs
1145+ | otherwise = "--" ++ unsmartify opts xs
1146+unsmartify opts ('\8212':xs)
1147+ | isEnabled Ext_old_dashes opts = "--" ++ unsmartify opts xs
1148+ | otherwise = "---" ++ unsmartify opts xs
1149+unsmartify opts (x:xs) = x : unsmartify opts xs
1150+unsmartify _ [] = []
1151+