git.iko.soy/typeable/pandoc
on master help sign in
CommonMark writer: support `hard_line_breaks`, `smart`.

Add tests.

commitb6f7c4930bf13ab9b25b18869f3bde5f87144497 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 8 Aug 2017, 13:17 (9 years ago) parentccd4f13
2 files changed+118−8
src/Text/Pandoc/Writers/CommonMark.hs+15−8 test/command/gfm.md+103
src/Text/Pandoc/Writers/CommonMark.hs+15−8
@@ -55,10 +55,7 @@ writeCommonMark opts (Pandoc meta blocks) = do
5555 notes' = if null notes
5656 then []
5757 else [OrderedList (1, Decimal, Period) $ reverse notes]
58− let blocks'' = if writerWrapText opts == WrapNone
59− then walk softBreakToSpace blocks'
60− else blocks'
61− main <- blocksToCommonMark opts (blocks'' ++ notes')
58+ main <- blocksToCommonMark opts (blocks' ++ notes')
6259 metadata <- metaToJSON opts
6360 (blocksToCommonMark opts)
6461 (inlinesToCommonMark opts)
@@ -232,10 +229,16 @@ inlinesToNodes :: WriterOptions -> [Inline] -> [Node]
232229inlinesToNodes opts = foldr (inlineToNodes opts) []
233230
234231inlineToNodes :: WriterOptions -> Inline -> [Node] -> [Node]
235−inlineToNodes _ (Str s) = (node (TEXT (T.pack s)) [] :)
232+inlineToNodes opts (Str s) = (node (TEXT (T.pack s')) [] :)
233+ where s' = if isEnabled Ext_smart opts
234+ then unsmartify opts s
235+ else s
236236inlineToNodes _ Space = (node (TEXT (T.pack " ")) [] :)
237237inlineToNodes _ LineBreak = (node LINEBREAK [] :)
238−inlineToNodes _ SoftBreak = (node SOFTBREAK [] :)
238+inlineToNodes opts SoftBreak
239+ | isEnabled Ext_hard_line_breaks opts = (node LINEBREAK [] :)
240+ | writerWrapText opts == WrapNone = (node (TEXT " ") [] :)
241+ | otherwise = (node SOFTBREAK [] :)
239242inlineToNodes opts (Emph xs) = (node EMPH (inlinesToNodes opts xs) :)
240243inlineToNodes opts (Strong xs) = (node STRONG (inlinesToNodes opts xs) :)
241244inlineToNodes opts (Strikeout xs) =
@@ -264,8 +267,12 @@ inlineToNodes opts (Quoted qt ils) =
264267 ((node (TEXT start) [] :
265268 inlinesToNodes opts ils ++ [node (TEXT end) []]) ++)
266269 where (start, end) = case qt of
267− SingleQuote -> (T.pack "‘", T.pack "’")
268− DoubleQuote -> (T.pack "“", T.pack "”")
270+ SingleQuote
271+ | isEnabled Ext_smart opts -> ("'","'")
272+ | otherwise -> ("‘", "’")
273+ DoubleQuote
274+ | isEnabled Ext_smart opts -> ("\"", "\"")
275+ | otherwise -> ("“", "”")
269276inlineToNodes _ (Code _ str) = (node (CODE (T.pack str)) [] :)
270277inlineToNodes _ (Math mt str) =
271278 case mt of
test/command/gfm.mdnew file+103
@@ -0,0 +1,103 @@
1+gfm tests:
2+
3+```
4+% pandoc -f gfm -t native
5+| Fruit | Price |
6+| ----- | ----: |
7+| apple | 0.13 |
8+| orange|1.12|
9+^D
10+[Table [] [AlignDefault,AlignRight] [0.0,0.0]
11+ [[Plain [Str "Fruit"]]
12+ ,[Plain [Str "Price"]]]
13+ [[[Plain [Str "apple"]]
14+ ,[Plain [Str "0.13"]]]
15+ ,[[Plain [Str "orange"]]
16+ ,[Plain [Str "1.12"]]]]]
17+```
18+
19+```
20+% pandoc -f gfm -t native
21+~~stricken out~~
22+^D
23+[Para [Strikeout [Str "stricken",Space,Str "out"]]]
24+```
25+
26+```
27+% pandoc -f gfm -t native
28+# Header
29+## Header
30+# -foo-bar_baz
31+^D
32+[Header 1 ("header",[],[]) [Str "Header"]
33+,Header 2 ("header-1",[],[]) [Str "Header"]
34+,Header 1 ("-foo-bar_baz",[],[]) [Str "-foo-bar_baz"]]
35+```
36+
37+```
38+% pandoc -f gfm -t native
39+My:thumbsup:emoji:heart:
40+^D
41+[Para [Str "My\128077emoji\10084\65039"]]
42+```
43+
44+```
45+% pandoc -f gfm -t native
46+"hi"
47+^D
48+[Para [Str "\"hi\""]]
49+```
50+
51+```
52+% pandoc -f gfm+smart -t native
53+"hi"
54+^D
55+[Para [Str "\8220hi\8221"]]
56+```
57+
58+```
59+% pandoc -t gfm -f native
60+[Table [Str "The",Space,Str "caption."] [AlignDefault,AlignRight] [0.0,0.0]
61+ [[Plain [Str "Fruit"]]
62+ ,[Plain [Str "Price"]]]
63+ [[[Plain [Str "apple"]]
64+ ,[Plain [Str "0.13"]]]
65+ ,[[Plain [Str "orange"]]
66+ ,[Plain [Str "1.12"]]]]]
67+^D
68+| Fruit | Price |
69+| ------ | ----: |
70+| apple | 0.13 |
71+| orange | 1.12 |
72+
73+The caption.
74+
75+
76+```
77+
78+```
79+% pandoc -f gfm-smart -t gfm+smart
80+“hi”
81+^D
82+"hi"
83+
84+
85+```
86+
87+```
88+% pandoc -f gfm+smart -t gfm-smart
89+"hi"
90+^D
91+“hi”
92+
93+
94+```
95+
96+```
97+% pandoc -f gfm+smart -t gfm+smart
98+"hi"
99+^D
100+"hi"
101+
102+
103+```