git.iko.soy/typeable/pandoc
on master help sign in
Convert bullet and numbered lists in dokuwiki writer (#386)
5b04d06Clare Macrae
src/Text/Pandoc/Writers/DokuWiki.hs+25−6
@@ -167,7 +167,7 @@ blockToDokuWiki opts x@(BulletList items) = do
167 modify $ \s -> s { stUseTags = oldUseTags }
167 modify $ \s -> s { stUseTags = oldUseTags }
168 return $ "<ul>\n" ++ vcat contents ++ "</ul>\n"
168 return $ "<ul>\n" ++ vcat contents ++ "</ul>\n"
169 else do
169 else do
170− modify $ \s -> s { stListLevel = stListLevel s ++ "*" }
170+ modify $ \s -> s { stListLevel = stListLevel s ++ " " }
171 contents <- mapM (listItemToDokuWiki opts) items
171 contents <- mapM (listItemToDokuWiki opts) items
172 modify $ \s -> s { stListLevel = init (stListLevel s) }
172 modify $ \s -> s { stListLevel = init (stListLevel s) }
173 return $ vcat contents ++ if null listLevel then "\n" else ""
173 return $ vcat contents ++ if null listLevel then "\n" else ""
@@ -179,15 +179,18 @@ blockToDokuWiki opts x@(OrderedList attribs items) = do
179 if useTags
179 if useTags
180 then do
180 then do
181 modify $ \s -> s { stUseTags = True }
181 modify $ \s -> s { stUseTags = True }
182− contents <- mapM (listItemToDokuWiki opts) items
182+ contents <- mapM (orderedListItemToDokuWiki opts) items
183 modify $ \s -> s { stUseTags = oldUseTags }
183 modify $ \s -> s { stUseTags = oldUseTags }
184 return $ "<ol" ++ listAttribsToString attribs ++ ">\n" ++ vcat contents ++ "</ol>\n"
184 return $ "<ol" ++ listAttribsToString attribs ++ ">\n" ++ vcat contents ++ "</ol>\n"
185 else do
185 else do
186− modify $ \s -> s { stListLevel = stListLevel s ++ "#" }
186+ modify $ \s -> s { stListLevel = stListLevel s ++ " " }
187− contents <- mapM (listItemToDokuWiki opts) items
187+ contents <- mapM (orderedListItemToDokuWiki opts) items
188 modify $ \s -> s { stListLevel = init (stListLevel s) }
188 modify $ \s -> s { stListLevel = init (stListLevel s) }
189 return $ vcat contents ++ if null listLevel then "\n" else ""
189 return $ vcat contents ++ if null listLevel then "\n" else ""
190
190
191+-- TODO Need to decide how to make definition lists work on dokuwiki - I don't think there
192+-- is a specific representation of them.
193+-- TODO This creates double '; ; ' if there is a bullet or ordered list inside a definition list
191blockToDokuWiki opts x@(DefinitionList items) = do
194blockToDokuWiki opts x@(DefinitionList items) = do
192 oldUseTags <- get >>= return . stUseTags
195 oldUseTags <- get >>= return . stUseTags
193 listLevel <- get >>= return . stListLevel
196 listLevel <- get >>= return . stListLevel
@@ -217,7 +220,7 @@ listAttribsToString (startnum, numstyle, _) =
217 then " style=\"list-style-type: " ++ numstyle' ++ ";\""
220 then " style=\"list-style-type: " ++ numstyle' ++ ";\""
218 else "")
221 else "")
219
222
220−-- | Convert bullet or ordered list item (list of blocks) to DokuWiki.
223+-- | Convert bullet list item (list of blocks) to DokuWiki.
221listItemToDokuWiki :: WriterOptions -> [Block] -> State WriterState String
224listItemToDokuWiki :: WriterOptions -> [Block] -> State WriterState String
222listItemToDokuWiki opts items = do
225listItemToDokuWiki opts items = do
223 contents <- blockListToDokuWiki opts items
226 contents <- blockListToDokuWiki opts items
@@ -226,7 +229,23 @@ listItemToDokuWiki opts items = do
226 then return $ "<li>" ++ contents ++ "</li>"
229 then return $ "<li>" ++ contents ++ "</li>"
227 else do
230 else do
228 marker <- get >>= return . stListLevel
231 marker <- get >>= return . stListLevel
232+ -- This marker ++ marker is an awful hack to write 2 spaces per indentation level.
233+ -- I couldn't find a cleaner way of doing it.
229− return $ marker ++ " " ++ contents
234+ return $ marker ++ marker ++ "* " ++ contents
235+
236+-- | Convert ordered list item (list of blocks) to DokuWiki.
237+-- | TODO Emiminate dreadful duplication of text from listItemToDokuWiki
238+orderedListItemToDokuWiki :: WriterOptions -> [Block] -> State WriterState String
239+orderedListItemToDokuWiki opts items = do
240+ contents <- blockListToDokuWiki opts items
241+ useTags <- get >>= return . stUseTags
242+ if useTags
243+ then return $ "<li>" ++ contents ++ "</li>"
244+ else do
245+ marker <- get >>= return . stListLevel
246+ -- This marker ++ marker is an awful hack to write 2 spaces per indentation level.
247+ -- I couldn't find a cleaner way of doing it.
248+ return $ marker ++ marker ++ "- " ++ contents
230
249
231-- | Convert definition list item (label, list of blocks) to DokuWiki.
250-- | Convert definition list item (label, list of blocks) to DokuWiki.
232definitionListItemToDokuWiki :: WriterOptions
251definitionListItemToDokuWiki :: WriterOptions
tests/writer.dokuwiki+23−23
@@ -303,8 +303,8 @@ Blank line after term, indented marker, alternate markers:
303: computer
303: computer
304; orange
304; orange
305: orange fruit
305: orange fruit
306−;# sublist
306+; ; - sublist
307−;# sublist
307+; ; - sublist
308
308
309====== HTML Blocks ======
309====== HTML Blocks ======
310
310
@@ -468,21 +468,21 @@ Ellipses…and…and….
468
468
469====== LaTeX ======
469====== LaTeX ======
470
470
471−*
471+ *
472−* <math>2+2=4</math>
472+ * <math>2+2=4</math>
473−* <math>x \in y</math>
473+ * <math>x \in y</math>
474−* <math>\alpha \wedge \omega</math>
474+ * <math>\alpha \wedge \omega</math>
475−* <math>223</math>
475+ * <math>223</math>
476−* <math>p</math>-Tree
476+ * <math>p</math>-Tree
477−* Here’s some display math: <math>\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}</math>
477+ * Here’s some display math: <math>\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}</math>
478−* Here’s one that has a line break in it: <math>\alpha + \omega \times x^2</math>.
478+ * Here’s one that has a line break in it: <math>\alpha + \omega \times x^2</math>.
479
479
480These shouldn’t be math:
480These shouldn’t be math:
481
481
482−* To get the famous equation, write <code>$e = mc^2$</code>.
482+ * To get the famous equation, write <code>$e = mc^2$</code>.
483−* $22,000 is a //lot// of money. So is $34,000. (It worked if “lot” is emphasized.)
483+ * $22,000 is a //lot// of money. So is $34,000. (It worked if “lot” is emphasized.)
484−* Shoes ($20) and socks ($5).
484+ * Shoes ($20) and socks ($5).
485−* Escaped <code>$</code>: $73 //this should be emphasized// 23$.
485+ * Escaped <code>$</code>: $73 //this should be emphasized// 23$.
486
486
487Here’s a LaTeX table:
487Here’s a LaTeX table:
488
488
@@ -494,11 +494,11 @@ Here’s a LaTeX table:
494
494
495Here is some unicode:
495Here is some unicode:
496
496
497−* I hat: Î
497+ * I hat: Î
498−* o umlaut: ö
498+ * o umlaut: ö
499−* section: §
499+ * section: §
500−* set membership: ∈
500+ * set membership: ∈
501−* copyright: ©
501+ * copyright: ©
502
502
503AT&amp;T has an ampersand in their name.
503AT&amp;T has an ampersand in their name.
504
504
@@ -606,9 +606,9 @@ Here’s an [[script?foo=1&bar=2|inline link in pointy braces]].
606
606
607With an ampersand: http://example.com/?foo=1&bar=2
607With an ampersand: http://example.com/?foo=1&bar=2
608
608
609−* In a list?
609+ * In a list?
610−* http://example.com/
610+ * http://example.com/
611−* It should.
611+ * It should.
612
612
613An e-mail address: [[mailto:nobody@nowhere.net|nobody@nowhere.net]]
613An e-mail address: [[mailto:nobody@nowhere.net|nobody@nowhere.net]]
614
614
@@ -646,7 +646,7 @@ If you want, you can indent every line, but you can also be lazy and just indent
646<blockquote>Notes can go in quotes.<ref>In quote.
646<blockquote>Notes can go in quotes.<ref>In quote.
647</ref>
647</ref>
648</blockquote>
648</blockquote>
649−# And in list items.<ref>In list.</ref>
649+ - And in list items.<ref>In list.</ref>
650
650
651This paragraph should not be part of the note, as it is not indented.
651This paragraph should not be part of the note, as it is not indented.
652
652