5 :Author: engelbert gruber
6 :Contact: grubert@users.sourceforge.net
8 :Web site: http://docutils.sourceforge.net/
15 This might become a document sometime, is now a FAQ, collected
16 from docutils-develop@lists.sourceforge.net.
18 This should give help in making a writer for the python docutils.
19 Writers are backends writing to a dedicated format.
26 Writers produce the final output (HTML, XML, TeX, etc.). Writers translate
27 the internal document tree structure into the final data format, possibly
28 running Writer-specific transforms first.
32 * Run transforms over the doctree(s).
33 * Translate doctree(s) into specific output formats.
34 * Transform references into format-native forms.
35 * Write the translated output to the destination I/O.
39 By the time the document gets to the Writer, it should be in
40 final form. The Writer's job is simply (and only) to translate from
41 the Docutils doctree structure to the target format. Some small
42 transforms may be required, but they should be local and
49 Next to come. This should be a writer module where everything is done
59 It is legal and does not hint to missing functionality, when a
60 method only implements pass, it just means that this calls information
61 is not used, the actual content is usually produced between ``visit_*``
62 and ``depart_*`` calls. e.g.::
64 def visit_Text(self, node):
65 self.body.append(self.encode(node.astext()))
67 def depart_Text(self, node):
70 As long as there is no need for termination depart_Text is ok.
75 If derived from NodeVisitor
77 * unknown_visit, unknown_departure
79 Deriving from SparseNodeVisitor means everything might pass.
81 GenericNodeVisitor adds
83 * default_visit, default_depart.
85 unimplemented_visit( self, node) seams to be there for both.
87 Each might raise NotImplementedError(describe_here),
92 html pages are more like papyrus rolls, if one wants to go more usual
93 paper formats some things are different or not.
102 In latex2e writer this looks awful to me, but as i understand this ensures
103 that e.g. http addresses are not only text.
105 Maybe this is due to the fact that self.docinfo is used, if one would remove
106 it context might be unecessary.
110 def visit_docinfo_item (...):
113 ##self.head.append('\\%s{%s}\n'
114 ## % (name, self.attval(node.astext())))
115 self.docinfo.append('\\textbf{%s} &\n\t' % name)
116 self.context.append(' \\\\\n')
117 self.context.append(self.docinfo)
118 self.context.append(len(self.body))
119 ##raise nodes.SkipNode
121 def depart_docinfo_item(self, node):
122 size = self.context.pop()
123 dest = self.context.pop()
124 tail = self.context.pop()
125 tail = self.body[size:] + [tail]