From f14396011e7a22c84f37104a7c97de530aec76f5 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 5 Nov 2018 09:55:15 -0800 Subject: CommonMark writer: make sure --ascii affects quotes, super/subscript. --- src/Text/Pandoc/Writers/CommonMark.hs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Writers/CommonMark.hs b/src/Text/Pandoc/Writers/CommonMark.hs index e590ceac8..c007f7734 100644 --- a/src/Text/Pandoc/Writers/CommonMark.hs +++ b/src/Text/Pandoc/Writers/CommonMark.hs @@ -264,19 +264,21 @@ inlineToNodes opts (Superscript xs) = then ((node (HTML_INLINE (T.pack "")) [] : inlinesToNodes opts xs ++ [node (HTML_INLINE (T.pack "")) []]) ++ ) else case traverse toSuperscriptInline xs of - Nothing -> + Just xs' | not (writerPreferAscii opts) + -> (inlinesToNodes opts xs' ++) + _ -> ((node (TEXT (T.pack "^(")) [] : inlinesToNodes opts xs ++ [node (TEXT (T.pack ")")) []]) ++ ) - Just xs' -> (inlinesToNodes opts xs' ++) inlineToNodes opts (Subscript xs) = if isEnabled Ext_raw_html opts then ((node (HTML_INLINE (T.pack "")) [] : inlinesToNodes opts xs ++ [node (HTML_INLINE (T.pack "")) []]) ++ ) else case traverse toSubscriptInline xs of - Nothing -> + Just xs' | not (writerPreferAscii opts) + -> (inlinesToNodes opts xs' ++) + _ -> ((node (TEXT (T.pack "_(")) [] : inlinesToNodes opts xs ++ [node (TEXT (T.pack ")")) []]) ++ ) - Just xs' -> (inlinesToNodes opts xs' ++) inlineToNodes opts (SmallCaps xs) = if isEnabled Ext_raw_html opts then ((node (HTML_INLINE (T.pack "")) [] @@ -297,14 +299,18 @@ inlineToNodes opts (RawInline fmt xs) = (node (CUSTOM_INLINE (T.pack xs) T.empty) [] :) | otherwise = id inlineToNodes opts (Quoted qt ils) = - ((node (TEXT start) [] : - inlinesToNodes opts ils ++ [node (TEXT end) []]) ++) + ((node (HTML_INLINE start) [] : + inlinesToNodes opts ils ++ [node (HTML_INLINE end) []]) ++) where (start, end) = case qt of SingleQuote | isEnabled Ext_smart opts -> ("'","'") + | writerPreferAscii opts -> + ("‘", "’") | otherwise -> ("‘", "’") DoubleQuote | isEnabled Ext_smart opts -> ("\"", "\"") + | writerPreferAscii opts -> + ("“", "”") | otherwise -> ("“", "”") inlineToNodes _ (Code _ str) = (node (CODE (T.pack str)) [] :) inlineToNodes opts (Math mt str) = -- cgit v1.2.3