implement bullet list

This commit is contained in:
Elan Ruusamäe 2012-06-20 00:23:36 +02:00
parent a8123bee1a
commit b4286ab450
2 changed files with 25 additions and 6 deletions

View file

@ -32,3 +32,17 @@ fourth line
sixth line! sixth line!
}}} }}}
= Bullet list =
{{{
* item 1
* item 2, with gap
* item 3
* item 3.1
}}}
* item 1
* item 2, with gap
* item 3
* item 3.1

View file

@ -26,6 +26,8 @@ class Formatter(FormatterBase):
self.in_pre = 0 self.in_pre = 0
self._text = None # XXX does not work with links in headings!!!!! self._text = None # XXX does not work with links in headings!!!!!
self.bullet_depth = 0
def _escape(self, text, extra_mapping={"'": "'", '"': """}): def _escape(self, text, extra_mapping={"'": "'", '"': """}):
return saxutils.escape(text, extra_mapping) return saxutils.escape(text, extra_mapping)
@ -107,13 +109,16 @@ class Formatter(FormatterBase):
return result + ['<ol>', '</ol>\n'][not on] return result + ['<ol>', '</ol>\n'][not on]
def bullet_list(self, on, **kw): def bullet_list(self, on, **kw):
result = '' # fill: ' * '
if self.in_p: if on:
result = self.paragraph(0) self.bullet_depth += 1
return result + ['<ul>', '</ul>\n'][not on] else:
self.bullet_depth -= 1
return ['\n', ''][not on]
def listitem(self, on, **kw): def listitem(self, on, **kw):
return ['<li>', '</li>\n'][not on] return [(' ' * self.bullet_depth * 2) + '* ', '\n'][not on]
def code(self, on, **kw): def code(self, on, **kw):
""" `typewriter` or {{{typerwriter}}, for code blocks i hope codeblock works """ """ `typewriter` or {{{typerwriter}}, for code blocks i hope codeblock works """
@ -133,7 +138,7 @@ class Formatter(FormatterBase):
result = '' result = ''
if self.in_p: if self.in_p:
result = self.paragraph(0) result = self.paragraph(0)
return result + ['<file>', '</file>'][not on] return result + ['<file>', '</file>\n'][not on]
def paragraph(self, on, **kw): def paragraph(self, on, **kw):
FormatterBase.paragraph(self, on) FormatterBase.paragraph(self, on)