Add <target> to one more testcase (see r8206).
[docutils.git] / sandbox / mwh / advopostwriter.py
blobe2f98be0d3357cc22a4054a6ce37204d6f2b4962
1 from docutils.writers import html4css1
2 from docutils import nodes
4 class Writer(html4css1.Writer):
5 W_init = html4css1.Writer.__init__
6 def __init__(self):
7 self.W_init()
8 self.translator_class = MyHTMLTranslator
10 def find_visible_child(node, starting_index, direction):
11 if direction == "forwards":
12 step = 1
13 end = len(node)
14 else:
15 step = -1
16 end = -1
17 for i in range(starting_index, end, step):
18 if not isinstance(node[i], nodes.Invisible):
19 return node[i]
20 else:
21 return None
23 class MyHTMLTranslator(html4css1.HTMLTranslator):
24 def visit_title(self, node):
25 self.body.append(self.starttag(node, 'b', '',
26 STYLE="font-variant: small-caps"))
27 self.context.append('</b>\n')
28 def visit_document(self, node):
29 pass
30 def depart_document(self, node):
31 pass
32 def visit_paragraph(self, node):
33 if isinstance(node.parent, nodes.section):
34 index = node.parent.index(node)
35 prev = find_visible_child(node.parent, index - 1, "backwards")
36 if isinstance(prev, nodes.title):
37 self.body.append(self.starttag(node, 'blockquote', '\n'))
38 else:
39 self.body.append('<p>\n')
40 else:
41 html4css1.HTMLTranslator.visit_paragraph(self, node)
43 def depart_paragraph(self, node):
44 if isinstance(node.parent, nodes.section):
45 index = node.parent.index(node)
46 next = find_visible_child(node.parent, index + 1, "forwards")
47 if not next:
48 self.body.append('\n</blockquote>\n')
49 else:
50 self.body.append("\n");
51 else:
52 # this tends to include "</p>"s which advogato then
53 # discards. I don't care that much...
54 html4css1.HTMLTranslator.depart_paragraph(self, node)
56 def visit_section(self, node):
57 pass
58 def depart_section(self, node):
59 pass