17
by Jonathan Lange
LICENSE it as MIT. |
1 |
# Copyright (c) 2007-2010 testdoc authors. See LICENSE for details.
|
2 |
||
5
by jml@canonical.com
Split out the formatter code into a separate module. |
3 |
"""Formatters for creating documents.
|
4 |
||
5 |
A formatter is an object which accepts an output stream (usually a file or
|
|
6 |
standard output) and then provides a structured way for writing to that stream.
|
|
7 |
All formatters should provide 'title', 'section', 'subsection' and 'paragraph'
|
|
8 |
methods which write to the stream.
|
|
9 |
"""
|
|
10 |
||
11 |
||
12 |
class WikiFormatter(object): |
|
13 |
"""Moin formatter."""
|
|
14 |
||
15 |
def __init__(self, stream): |
|
16 |
self.stream = stream |
|
17 |
||
18 |
def writeln(self, line): |
|
19 |
self.stream.write('%s\n' % (line,)) |
|
20 |
||
21 |
def title(self, name): |
|
22 |
self.writeln('= %s =\n' % (name,)) |
|
23 |
||
24 |
def section(self, name): |
|
11.1.1
by Andrew Bennetts
Put a blank line before section headings. |
25 |
self.writeln('') |
5
by jml@canonical.com
Split out the formatter code into a separate module. |
26 |
self.writeln('== %s ==\n' % (name,)) |
27 |
||
28 |
def subsection(self, name): |
|
29 |
self.writeln('=== %s ===\n' % (name,)) |
|
30 |
||
31 |
def paragraph(self, text): |
|
32 |
self.writeln('%s\n' % (text.strip(),)) |