From c15568c652583d55bf0b290e3f5999056fa9bd5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 20 Jun 2012 00:38:14 +0200 Subject: [PATCH] implement also numbered list --- syntaxreference.txt | 17 +++++++++++++++++ text_dokuwiki.py | 25 +++++++++++++++---------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/syntaxreference.txt b/syntaxreference.txt index 5b51252..624a763 100644 --- a/syntaxreference.txt +++ b/syntaxreference.txt @@ -46,3 +46,20 @@ sixth line! * item 2, with gap * item 3 * item 3.1 += Numbered list = +{{{ + 1. item 1 + i. item 1 + i. item 2 +}}} + 1. item 1 + i. item 1 + i. item 2 +{{{ + 1. item 2 + a. item 1 + a. item 2 +}}} + 1. item 2 + a. item 1 + a. item 2 diff --git a/text_dokuwiki.py b/text_dokuwiki.py index 525e1c7..58d6ac1 100644 --- a/text_dokuwiki.py +++ b/text_dokuwiki.py @@ -26,7 +26,8 @@ class Formatter(FormatterBase): self.in_pre = 0 self._text = None # XXX does not work with links in headings!!!!! - self.bullet_depth = 0 + self.list_depth = 0 + self.list_type = None def _escape(self, text, extra_mapping={"'": "'", '"': """}): return saxutils.escape(text, extra_mapping) @@ -103,22 +104,26 @@ class Formatter(FormatterBase): return ['**', '**'][not on] def number_list(self, on, type=None, start=None, **kw): - result = '' - if self.in_p: - result = self.paragraph(0) - return result + ['
    ', '
\n'][not on] + # list type not supported + if on: + self.list_depth += 1 + self.list_type = '-' + else: + self.list_depth -= 1 + + return ['', '\n'][on] def bullet_list(self, on, **kw): - # fill: ' * ' if on: - self.bullet_depth += 1 + self.list_depth += 1 + self.list_type = '*' else: - self.bullet_depth -= 1 + self.list_depth -= 1 - return ['\n', ''][not on] + return ['', '\n'][on] def listitem(self, on, **kw): - return [(' ' * self.bullet_depth * 2) + '* ', '\n'][not on] + return [(' ' * self.list_depth * 2) + self.list_type + ' ', '\n'][not on] def code(self, on, **kw): """ `typewriter` or {{{typerwriter}}, for code blocks i hope codeblock works """