diff options
-rw-r--r-- | src/Text/Pandoc/Writers/CommonMark.hs | 23 | ||||
-rw-r--r-- | test/command/gfm.md | 103 |
2 files changed, 118 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 diff --git a/test/command/gfm.md b/test/command/gfm.md new file mode 100644 index 000000000..c83fa96e3 --- /dev/null +++ b/test/command/gfm.md @@ -0,0 +1,103 @@ +gfm tests: + +``` +% pandoc -f gfm -t native +| Fruit | Price | +| ----- | ----: | +| apple | 0.13 | +| orange|1.12| +^D +[Table [] [AlignDefault,AlignRight] [0.0,0.0] + [[Plain [Str "Fruit"]] + ,[Plain [Str "Price"]]] + [[[Plain [Str "apple"]] + ,[Plain [Str "0.13"]]] + ,[[Plain [Str "orange"]] + ,[Plain [Str "1.12"]]]]] +``` + +``` +% pandoc -f gfm -t native +~~stricken out~~ +^D +[Para [Strikeout [Str "stricken",Space,Str "out"]]] +``` + +``` +% pandoc -f gfm -t native +# Header +## Header +# -foo-bar_baz +^D +[Header 1 ("header",[],[]) [Str "Header"] +,Header 2 ("header-1",[],[]) [Str "Header"] +,Header 1 ("-foo-bar_baz",[],[]) [Str "-foo-bar_baz"]] +``` + +``` +% pandoc -f gfm -t native +My:thumbsup:emoji:heart: +^D +[Para [Str "My\128077emoji\10084\65039"]] +``` + +``` +% pandoc -f gfm -t native +"hi" +^D +[Para [Str "\"hi\""]] +``` + +``` +% pandoc -f gfm+smart -t native +"hi" +^D +[Para [Str "\8220hi\8221"]] +``` + +``` +% pandoc -t gfm -f native +[Table [Str "The",Space,Str "caption."] [AlignDefault,AlignRight] [0.0,0.0] + [[Plain [Str "Fruit"]] + ,[Plain [Str "Price"]]] + [[[Plain [Str "apple"]] + ,[Plain [Str "0.13"]]] + ,[[Plain [Str "orange"]] + ,[Plain [Str "1.12"]]]]] +^D +| Fruit | Price | +| ------ | ----: | +| apple | 0.13 | +| orange | 1.12 | + +The caption. + + +``` + +``` +% pandoc -f gfm-smart -t gfm+smart +“hi” +^D +"hi" + + +``` + +``` +% pandoc -f gfm+smart -t gfm-smart +"hi" +^D +“hi” + + +``` + +``` +% pandoc -f gfm+smart -t gfm+smart +"hi" +^D +"hi" + + +``` |