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.
8
8
This module contains practical examples of Docutils client code.
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
15
from docutils import core
16
from docutils import core, io
18
19
def html_parts(input_string, source_path=None, destination_path=None,
49
50
writer_name='html', settings_overrides=overrides)
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):
56
57
Given an input string, returns an HTML fragment as a string.
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.
61
61
Parameters (see `html_parts()` for the remainder):
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)
76
def internals(input_string, source_path=None, destination_path=None,
77
input_encoding='unicode'):
79
Return the document tree and publisher, for exploring Docutils internals.
81
Parameters: see `html_parts()`.
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