~ubuntu-branches/ubuntu/karmic/python-docutils/karmic

« back to all changes in this revision

Viewing changes to docutils/examples.py

  • Committer: Bazaar Package Importer
  • Author(s): martin f. krafft
  • Date: 2006-07-10 11:45:05 UTC
  • mfrom: (2.1.4 edgy)
  • Revision ID: james.westby@ubuntu.com-20060710114505-otkhqcslevewxmz5
Tags: 0.4-3
Added build dependency on python-central (closes: #377580).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Authors: David Goodger
2
2
# Contact: goodger@python.org
3
 
# Revision: $Revision: 1.4 $
4
 
# Date: $Date: 2004/05/06 16:15:29 $
 
3
# Revision: $Revision: 3598 $
 
4
# Date: $Date: 2005-06-27 13:19:35 +0200 (Mon, 27 Jun 2005) $
5
5
# Copyright: This module has been placed in the public domain.
6
6
 
7
7
"""
8
8
This module contains practical examples of Docutils client code.
9
9
 
10
 
Importing this module is not recommended; its contents are subject to change
11
 
in future Docutils releases.  Instead, it is recommended that you copy and
12
 
paste the parts you need into your own code, modifying as necessary.
 
10
Importing this module from client code is not recommended; its contents are
 
11
subject to change in future Docutils releases.  Instead, it is recommended
 
12
that you copy and paste the parts you need into your own code, modifying as
 
13
necessary.
13
14
"""
14
15
 
15
 
from docutils import core
 
16
from docutils import core, io
16
17
 
17
18
 
18
19
def html_parts(input_string, source_path=None, destination_path=None,
49
50
        writer_name='html', settings_overrides=overrides)
50
51
    return parts
51
52
 
52
 
def html_fragment(input_string, source_path=None, destination_path=None,
53
 
                  input_encoding='unicode', output_encoding='unicode',
54
 
                  doctitle=1, initial_header_level=1):
 
53
def html_body(input_string, source_path=None, destination_path=None,
 
54
              input_encoding='unicode', output_encoding='unicode',
 
55
              doctitle=1, initial_header_level=1):
55
56
    """
56
57
    Given an input string, returns an HTML fragment as a string.
57
58
 
58
 
    The return value is the contents of the <body> tag, less the title,
59
 
    subtitle, and docinfo.
 
59
    The return value is the contents of the <body> element.
60
60
 
61
61
    Parameters (see `html_parts()` for the remainder):
62
62
 
68
68
        destination_path=destination_path,
69
69
        input_encoding=input_encoding, doctitle=doctitle,
70
70
        initial_header_level=initial_header_level)
71
 
    fragment = parts['fragment']
 
71
    fragment = parts['html_body']
72
72
    if output_encoding != 'unicode':
73
73
        fragment = fragment.encode(output_encoding)
74
74
    return fragment
 
75
 
 
76
def internals(input_string, source_path=None, destination_path=None,
 
77
              input_encoding='unicode'):
 
78
    """
 
79
    Return the document tree and publisher, for exploring Docutils internals.
 
80
 
 
81
    Parameters: see `html_parts()`.
 
82
    """
 
83
    overrides = {'input_encoding': input_encoding}
 
84
    output, pub = core.publish_programmatically(
 
85
        source_class=io.StringInput, source=input_string,
 
86
        source_path=source_path,
 
87
        destination_class=io.NullOutput, destination=None,
 
88
        destination_path=destination_path,
 
89
        reader=None, reader_name='standalone',
 
90
        parser=None, parser_name='restructuredtext',
 
91
        writer=None, writer_name='null',
 
92
        settings=None, settings_spec=None, settings_overrides=overrides,
 
93
        config_section=None, enable_exit_status=None)
 
94
    return pub.writer.document, pub