removed obsolete issues (many of them fixed with AE)
[docutils.git] / sandbox / grubert / making_a_writer.txt
blob4d76b517075862daf4a272e47c0d6dc79dd114b8
1 ===============
2 Making a writer
3 ===============
5 :Author: engelbert gruber
6 :Contact: grubert@users.sourceforge.net
7 :Date: $Date$
8 :Web site: http://docutils.sourceforge.net/
10 .. contents::
12 Introduction
13 ============
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.
21 General description
22 ===================
24 from PEP-0258:
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.
30         Responsibilities:
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.
37 or in other words
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
43   format-specific.
46 The smallest writer
47 ===================
49 Next to come. This should be a writer module where everything is done 
50 in unimplemented.
53 Methods
54 =======
56 Empty methods
57 -------------
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):
68         pass
70 As long as there is no need for termination depart_Text is ok.
72 Fallback methods
73 ----------------
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), 
89 General Problems
90 ----------------
92 html pages are more like papyrus rolls, if one wants to go more usual
93 paper formats some things are different or not.
95 * page headings
96 * page numbers
99 Problems
100 --------
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 (...):
111         ...
112         else:
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]
126         del self.body[size:]
127         dest.extend(tail)
130 Notes on Classes
131 ----------------
133 To be completed.