Everything is clear(er) now. Thanks :-)
Just a last question before changing everything,
In my code, I extract some fields like keywords from dom just before producing html.
I use :

parser.parse(text, doc)
dom = doc.asdom()
for f in dom.getElementsByTagName('field'):
  #do things

Will I still be able to do something similar with the standard API easily ?
in other words, publish_programmatically or no publish_programmatically ?

Thanks,

On Mon, Feb 23, 2009 at 5:57 PM, David Goodger <goodger@python.org> wrote:
On Mon, Feb 23, 2009 at 11:43, Rayene Ben Rayana
> Thanks for the answer David.
>
> I am using standard versions of docutils and python. By standard I mean the
> ones provided by macports with no modifications.
>
> python version is 2.6.1
> docutils version is 0.5
>
> But you are right when you said that I modified the default configuration.
> here is a minimal code that reproduces the problem:
>
> a ReST file named a.rst  contains just :
> RFC 1234
>
> a Python script :
>
> import docutils.parsers.rst
> text = open('a.rst').read()
> parser = docutils.parsers.rst.Parser()
> doc = docutils.utils.new_document('doc')
> doc.settings.tab_width = 4
> doc.settings.pep_references = 1
> doc.settings.rfc_references = 1
> parser.parse(text, doc)

The problem is that you're not using one of the standard front-end
tools (rst2html.py, etc.). Your code doesn't use the Docutils public
API. You really should be using one of the publisher convenience
functions, described here:
http://docutils.sourceforge.net/docs/api/publisher.html

The order of setup is important, and you're missing a step: setting up
the components and thus, the runtime settings. Docutils consists of
several components (reader, parser, writer, etc.), each of which may
define its own runtime settings. Docutils components are be assembled
at runtime.

My advice: use the convenience functions. That's the public API.

> The problem was partially solved by forcing
> doc.settings.rfc_references = 0
>
> With doc.settings.rfc_references = 0, a file containing a bare RFC 1234
> string is parsed normally. But the problem remains when using the text role
> :RFC:`1234`.
>
> Then, I had the idea to add :
> doc.settings.rfc_base_url = 'http://www.ietf.org/rfc/'
>
> Which solved the problem. This is when I understood that my problem came
> from the fact that my default configuration is incomplete. In fact :
>
> import docutils.parsers.rst
> doc = docutils.utils.new_document('doc')
> print(dir (doc.settings))
>
> gives:
>
> ['__cmp__', '__doc__', '__init__', '__module__', '__repr__', '__str__',
> '_config_files', '_destination', '_disable_config', '_source', '_update',
> '_update_careful', '_update_loose', 'auto_id_prefix', 'config', 'copy',
> 'datestamp', 'debug', 'dump_internals', 'dump_pseudo_xml', 'dump_settings',
> 'dump_transforms', 'ensure_value', 'error_encoding',
> 'error_encoding_error_handler', 'exit_status_level', 'expose_internals',
> 'footnote_backlinks', 'generator', 'halt_level', 'id_prefix',
> 'input_encoding', 'input_encoding_error_handler', 'language_code',
> 'output_encoding', 'output_encoding_error_handler', 'read_file',
> 'read_module', 'record_dependencies', 'report_level', 'sectnum_xform',
> 'source_link', 'source_url', 'strict_visitor', 'strip_classes',
> 'strip_comments', 'strip_elements_with_classes', 'title', 'toc_backlinks',
> 'traceback', 'update', 'warning_stream']
>
> As you can see, rfc_references (among others) is missing.

The above does not include parser, reader, or writer settings. Those
come from the components.

> Right now,  I don't know if the problem comes from my code (i.e. I have to
> tell new_document() to use the default conf explicitely) or if it comes from
> the distribution (macports).

It's your code :-)

--