git.iko.soy/typeable/pandoc
on master help sign in
Convert bullet and numbered lists in dokuwiki writer (#386)
commit5b04d063a1637a24a3bb495718046c1f29525fea authorClare Macrae <clare.macrae@googlemail.com> dateFri 26 Jul 2013, 06:19 (13 years ago) parent97d81c8
2 files changed+48−29
src/Text/Pandoc/Writers/DokuWiki.hs+25−6 tests/writer.dokuwiki+23−23
src/Text/Pandoc/Writers/DokuWiki.hs+25−6
@@ -167,7 +167,7 @@ blockToDokuWiki opts x@(BulletList items) = do
167167 modify $ \s -> s { stUseTags = oldUseTags }
168168 return $ "<ul>\n" ++ vcat contents ++ "</ul>\n"
169169 else do
170− modify $ \s -> s { stListLevel = stListLevel s ++ "*" }
170+ modify $ \s -> s { stListLevel = stListLevel s ++ " " }
171171 contents <- mapM (listItemToDokuWiki opts) items
172172 modify $ \s -> s { stListLevel = init (stListLevel s) }
173173 return $ vcat contents ++ if null listLevel then "\n" else ""
@@ -179,15 +179,18 @@ blockToDokuWiki opts x@(OrderedList attribs items) = do
179179 if useTags
180180 then do
181181 modify $ \s -> s { stUseTags = True }
182− contents <- mapM (listItemToDokuWiki opts) items
182+ contents <- mapM (orderedListItemToDokuWiki opts) items
183183 modify $ \s -> s { stUseTags = oldUseTags }
184184 return $ "<ol" ++ listAttribsToString attribs ++ ">\n" ++ vcat contents ++ "</ol>\n"
185185 else do
186− modify $ \s -> s { stListLevel = stListLevel s ++ "#" }
187− contents <- mapM (listItemToDokuWiki opts) items
186+ modify $ \s -> s { stListLevel = stListLevel s ++ " " }
187+ contents <- mapM (orderedListItemToDokuWiki opts) items
188188 modify $ \s -> s { stListLevel = init (stListLevel s) }
189189 return $ vcat contents ++ if null listLevel then "\n" else ""
190190
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
191194blockToDokuWiki opts x@(DefinitionList items) = do
192195 oldUseTags <- get >>= return . stUseTags
193196 listLevel <- get >>= return . stListLevel
@@ -217,7 +220,7 @@ listAttribsToString (startnum, numstyle, _) =
217220 then " style=\"list-style-type: " ++ numstyle' ++ ";\""
218221 else "")
219222
220−-- | Convert bullet or ordered list item (list of blocks) to DokuWiki.
223+-- | Convert bullet list item (list of blocks) to DokuWiki.
221224listItemToDokuWiki :: WriterOptions -> [Block] -> State WriterState String
222225listItemToDokuWiki opts items = do
223226 contents <- blockListToDokuWiki opts items
@@ -226,7 +229,23 @@ listItemToDokuWiki opts items = do
226229 then return $ "<li>" ++ contents ++ "</li>"
227230 else do
228231 marker <- get >>= return . stListLevel
229− return $ marker ++ " " ++ contents
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.
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
230249
231250-- | Convert definition list item (label, list of blocks) to DokuWiki.
232251definitionListItemToDokuWiki :: WriterOptions
tests/writer.dokuwiki+23−23
@@ -303,8 +303,8 @@ Blank line after term, indented marker, alternate markers:
303303: computer
304304; orange
305305: orange fruit
306−;# sublist
307−;# sublist
306+; ; - sublist
307+; ; - sublist
308308
309309====== HTML Blocks ======
310310
@@ -468,21 +468,21 @@ Ellipses…and…and….
468468
469469====== LaTeX ======
470470
471−*
472−* <math>2+2=4</math>
473−* <math>x \in y</math>
474−* <math>\alpha \wedge \omega</math>
475−* <math>223</math>
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>
478−* Here’s one that has a line break in it: <math>\alpha + \omega \times x^2</math>.
471+ *
472+ * <math>2+2=4</math>
473+ * <math>x \in y</math>
474+ * <math>\alpha \wedge \omega</math>
475+ * <math>223</math>
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>
478+ * Here’s one that has a line break in it: <math>\alpha + \omega \times x^2</math>.
479479
480480These shouldn’t be math:
481481
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.)
484−* Shoes ($20) and socks ($5).
485−* Escaped <code>$</code>: $73 //this should be emphasized// 23$.
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.)
484+ * Shoes ($20) and socks ($5).
485+ * Escaped <code>$</code>: $73 //this should be emphasized// 23$.
486486
487487Here’s a LaTeX table:
488488
@@ -494,11 +494,11 @@ Here’s a LaTeX table:
494494
495495Here is some unicode:
496496
497−* I hat: Î
498−* o umlaut: ö
499−* section: §
500−* set membership: ∈
501−* copyright: ©
497+ * I hat: Î
498+ * o umlaut: ö
499+ * section: §
500+ * set membership: ∈
501+ * copyright: ©
502502
503503AT&amp;T has an ampersand in their name.
504504
@@ -606,9 +606,9 @@ Here’s an [[script?foo=1&bar=2|inline link in pointy braces]].
606606
607607With an ampersand: http://example.com/?foo=1&bar=2
608608
609−* In a list?
610−* http://example.com/
611−* It should.
609+ * In a list?
610+ * http://example.com/
611+ * It should.
612612
613613An e-mail address: [[mailto:nobody@nowhere.net|nobody@nowhere.net]]
614614
@@ -646,7 +646,7 @@ If you want, you can indent every line, but you can also be lazy and just indent
646646<blockquote>Notes can go in quotes.<ref>In quote.
647647</ref>
648648</blockquote>
649−# And in list items.<ref>In list.</ref>
649+ - And in list items.<ref>In list.</ref>
650650
651651This paragraph should not be part of the note, as it is not indented.
652652