On Wednesday, January 29, 2003, at 02:16 PM, David Goodger wrote:
>> Now, I could make each function a title, like
>>
>> function_name(params):
>> **********************
>>
>> The docstring
>>
>> But I don't think I can get that to look like I want, even with
>> fancy CSS.
>
> What do you want it to look like?
I'm looking for something vaguely like the Python reference manual. I
like the reference manuals for the most part, except they don't have
very good indexes (which is something I really look forward to with
docutils/reST).
>> Not to mention that I don't know at what level (h1, h2, h3, etc)
>> the function definition will be -- it's largely orthogonal to other
>> structure. Hmm... what I'd really like is a directive, like:
>>
>> .. header:: function_name
>>
>> That would create an invisible sort of header, where it shows up in
>> the TOC and is a link target, but isn't otherwise displayed. Of
>> course, "function_name" always the name of the target, I've been
>> using "ClassName.function_name". So something like:
>>
>> .. header:: function_name
>> :anchor-name: ClassName.function_name
>>
>> Anyway, that's my initial thought. Maybe there's a different way to
>> do this.
>
> I don't think this is a good approach. It smells like a kludge: too
> single-purpose to be worthwhile, and very magical. How would this
> translate into elements in the doctree? The doctree must remain
> self-consistent and style-free (as much as possible).
>
> Although I still suspect you're letting style dictate structure, I'll
> try to help you out. But we must recognize that there are limits to
> reStructuredText, beyond which we have to consider alternatives.
> ReStructuredText is aimed at ordinary documents; it's not suitable for
> some really creative graphic design exercises, and I don't think it
> should be.
This is, or is supposed to be, the quintessential reStructuredText
document -- a programmer's reference. If the doctree is nice, then
with a little XSL or what-have-you anything is possible (though not
necessarily easy even then). But the preprocessor already feels like a
kludge, and adding a postprocessor feels even worse. But then I'm
anti-XML, so I'd feel that way ;) I prefer event-driven to a tree
representation, but whatever.
And layout does really matter -- that's a big part of why I don't like
the output of pydoc. I want the documentation to look right both in
the source and in the generated documentation. It's not an
unreasonable goal, and I don't think a difficult goal either.
> It seems that you're looking for finer-grained selectability, to be
> able to more precisely target styles. Currently we have two extremes:
> overly broad (a <div> element surrounds every section, but different
> "types" of sections are not distinct from each other), and overly
> precise (each <div> section element has a unique "id" attribute, which
> *could* be used in the stylesheet, but it would be a manual pain).
>
> Perhaps the "topic" directive would suit your purposes. See
> <http://docutils.sf.net/spec/rst/directives.html#topic>, and note that
> topics cannot contain subsections or subtopics. Currently, topics
> don't show up in the table of contents, but that could be remedied
> with a new option to the "contents" directive.
Yes, topics look good. I just tried using them, and with a little CSS
tweaking they seem alright. Though because of the use of <p> tags for
the title and body, the function title and parameter line is separated
from its docstring, which I would prefer not to have. I haven't seen
anything that lets you change the space between paragraphs with CSS,
which I've wanted to do often...
> Docutils uses an optional "class" attribute on all elements, which is
> carried all the way through the HTML writer. The class attribute can
> contain multiple values (space-separated). A new directive could be
> added that adds a class value to the enclosing element, and this class
> could be selected in the stylesheet. If the section *containing* the
> specialized function sections is given a class, say
> "function-container", the stylesheet could contain a style like this::
>
> div.function-container div { ... your styles here ... }
>
> I'll add these to the to-do list. Contributions are welcome!
Yes, that would work nicely, because then I wouldn't have to monopolize
topic:: for function definitions. I still haven't looked at the
internals of the parsing, but I'll try to look into it more -- it might
give me some insight into how the extractor should work as well.
Ian
|