diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-08-08 13:17:29 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-08-08 13:18:27 -0700 |
commit | b6f7c4930bf13ab9b25b18869f3bde5f87144497 (patch) | |
tree | 3efff76830e441472a226c2be145e176e78a314f /src/Text/Pandoc | |
parent | ccd4f13a4accf0366072a93b2843706e60a89a5e (diff) | |
download | pandoc-b6f7c4930bf13ab9b25b18869f3bde5f87144497.tar.gz |
CommonMark writer: support `hard_line_breaks`, `smart`.
Add tests.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Writers/CommonMark.hs | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/Text/Pandoc/Writers/CommonMark.hs b/src/Text/Pandoc/Writers/CommonMark.hs index b268f5315..20a22e051 100644 --- a/src/Text/Pandoc/Writers/CommonMark.hs +++ b/src/Text/Pandoc/Writers/CommonMark.hs @@ -55,10 +55,7 @@ writeCommonMark opts (Pandoc meta blocks) = do notes' = if null notes then [] else [OrderedList (1, Decimal, Period) $ reverse notes] - let blocks'' = if writerWrapText opts == WrapNone - then walk softBreakToSpace blocks' - else blocks' - main <- blocksToCommonMark opts (blocks'' ++ notes') + main <- blocksToCommonMark opts (blocks' ++ notes') metadata <- metaToJSON opts (blocksToCommonMark opts) (inlinesToCommonMark opts) @@ -232,10 +229,16 @@ inlinesToNodes :: WriterOptions -> [Inline] -> [Node] inlinesToNodes opts = foldr (inlineToNodes opts) [] inlineToNodes :: WriterOptions -> Inline -> [Node] -> [Node] -inlineToNodes _ (Str s) = (node (TEXT (T.pack s)) [] :) +inlineToNodes opts (Str s) = (node (TEXT (T.pack s')) [] :) + where s' = if isEnabled Ext_smart opts + then unsmartify opts s + else s inlineToNodes _ Space = (node (TEXT (T.pack " ")) [] :) inlineToNodes _ LineBreak = (node LINEBREAK [] :) -inlineToNodes _ SoftBreak = (node SOFTBREAK [] :) +inlineToNodes opts SoftBreak + | isEnabled Ext_hard_line_breaks opts = (node LINEBREAK [] :) + | writerWrapText opts == WrapNone = (node (TEXT " ") [] :) + | otherwise = (node SOFTBREAK [] :) inlineToNodes opts (Emph xs) = (node EMPH (inlinesToNodes opts xs) :) inlineToNodes opts (Strong xs) = (node STRONG (inlinesToNodes opts xs) :) inlineToNodes opts (Strikeout xs) = @@ -264,8 +267,12 @@ inlineToNodes opts (Quoted qt ils) = ((node (TEXT start) [] : inlinesToNodes opts ils ++ [node (TEXT end) []]) ++) where (start, end) = case qt of - SingleQuote -> (T.pack "‘", T.pack "’") - DoubleQuote -> (T.pack "“", T.pack "”") + SingleQuote + | isEnabled Ext_smart opts -> ("'","'") + | otherwise -> ("‘", "’") + DoubleQuote + | isEnabled Ext_smart opts -> ("\"", "\"") + | otherwise -> ("“", "”") inlineToNodes _ (Code _ str) = (node (CODE (T.pack str)) [] :) inlineToNodes _ (Math mt str) = case mt of |