[Grok-dev] Re: To a multipage html tutorial
Philipp von Weitershausen
philipp at weitershausen.de
Sun Apr 8 20:07:05 EDT 2007
On 8 Apr 2007, at 01:20 , Darryl Cousins wrote:
>> It's also a hack because docutils provides a DOM-like
>> representation of
>> a parsed document and a way to only publish parts of the DOM. You
>> therefore simply walk each top-level section in the node tree and
>> publish them individually.
>> More information is given in the docutils docs. You probably
>> want to
>> pay close attention to the "Modifying the Document Tree Before It Is
>> Written" section. Basically, walking a document's sections could look
>> like this::
>>>>> import docutils.core
>>>>> source = open('tutorial.txt').read()
>>>>> document = docutils.core.publish_doctree(source)
>>>>> for node in document:
>> ... if node.tagname == 'section':
>> ... # do something here...
> I did try in this manner. But in order to create a seperate document
> tree for each section it seemed to me that I needed the source rest
> (perhaps there is another approach?). Unfortunately though the source
> rest is not available from the document it seems.
>>> What is missing here however is a contents listing of the entire
>>> document. Back into the docutils internals but without success.
>> The contents listing is just another node in the document tree and
>> likely be rendered separately. The tricky part will be to adjust the
>> links to the different output pages. Perhaps this is best done in a
>> post-processing step.
> Yes, so it seemed to me also.
Perhaps this is the way to go for the whole split up: do a post-
processing after the HTML generation. Using elementtree or lxml it
shouldn't be that difficult to duplicate the tutorial.html document,
each time with a different top level section showing. There woudn't
be a need to learn the docutils API (which apparently doesn't provide
the features we want anyway), we would be working with standard HTML
More information about the Grok-dev