25
25
<h2>Inputs and Outputs</h2>
27
<p>Lore works by reading the HTML source of your document, and producing
28
whatever output the user specifies on the command line. If the HTML document
29
is well-formed XML that meets a certain minimum standard, Lore will be able to
30
to produce some output. All Lore extensions will be written to redefine the
31
<em>input</em>, and most will redefine the output in some way. The name of
32
the default input is <q>lore</q>. When you write your extension, you will
33
come up with a new name for your input, telling Lore what rules to use to
27
<p>Lore works by reading the HTML source of your document, and
28
producing whatever output the user specifies on the command line. If
29
the HTML document is well-formed XML that meets a certain minimum
30
standard, Lore will be able to to produce some output. All Lore
31
extensions will be written to redefine the <em>input</em>, and most
32
will redefine the output in some way. The name of the default input
33
is <q>lore</q>. When you write your extension, you will come up with
34
a new name for your input, telling Lore what rules to use to process
36
37
<p>Lore can produce XHTML, LaTeX, and DocBook document formats, which can be
37
38
displayed directly if you have a user agent capable of viewing them, or
91
92
<a href="listings/lore/factory.py-1" class="py-listing">Listing 2: The Input
94
<p>In Listing 2, we create a subclass of ProcessingFunctionFactory. This
95
class provides a hook for you, a class variable named
96
<code>latexSpitters</code>. This variable tells Lore
97
what new class will be generating LaTeX from your input format. We redefine
98
<code>latexSpitters</code> to <code>MyLatexSpitter</code> in the subclass
100
class knows what to do with the new input we have already defined. Last, you
101
must define the module-level variable <code
102
class="py-src-identifier">factory</code>. It should be an instance with
104
interface as <code class="py-src-identifier">ProcessingFunctionFactory</code>
105
(e.g. an instance of a subclass, in this case, <code
106
class="py-src-identifier">MyProcessingFunctionFactory</code>).</p>
95
<p>In Listing 2, we create a subclass of ProcessingFunctionFactory.
96
This class provides a hook for you, a class variable
97
named <code>latexSpitters</code>. This variable tells Lore what new
98
class will be generating LaTeX from your input format. We
99
redefine <code>latexSpitters</code> to <code>MyLatexSpitter</code> in
100
the subclass because this class knows what to do with the new input we
101
have already defined. Last, you must define the module-level
102
variable <code class="py-src-identifier">factory</code>. It should be
103
an instance with the same interface
104
as <code class="py-src-identifier">ProcessingFunctionFactory</code>
105
(e.g. an instance of a subclass, in this
106
case, <code class="py-src-identifier">MyProcessingFunctionFactory</code>).</p>
108
108
<p>Now let's actually write some code to generate the LaTeX. Doing this
109
109
requires at least a familiarity with the LaTeX language. Search Google for
113
113
<a href="listings/lore/spitters.py-1" class="py-listing">Listing 3:
116
<p>The method <code>visitNode_span_productname</code> is
117
our handler for <span> tags with the <code>class="productname"</code>
118
identifier. Lore knows to try methods <code>visitNode_span_*</code> and
119
<code>visitNode_div_*</code> whenever it encounters a new
120
class in one of these tags. This is why the class names have to be valid
116
<p>The method <code>visitNode_span_productname</code> is our handler
117
for <span> tags with the <code>class="productname"</code>
118
identifier. Lore knows to try methods <code>visitNode_span_*</code>
119
and <code>visitNode_div_*</code> whenever it encounters a new class in
120
one of these tags. This is why the class names have to be valid
121
121
Python identifiers.</p>
123
123
<p>Now let's see what Lore does with these new classes with the following