1
# $Id: __init__.py 6328 2010-05-23 21:20:29Z gbrandl $
2
# Author: David Goodger <goodger@python.org>
3
# Copyright: This module has been placed in the public domain.
9
__docformat__ = 'reStructuredText'
17
from docutils import frontend, nodes, utils, writers
18
from docutils.writers import html4css1
21
class Writer(html4css1.Writer):
23
default_stylesheet = 'pep.css'
25
default_stylesheet_path = utils.relative_path(
26
os.path.join(os.getcwd(), 'dummy'),
27
os.path.join(os.path.dirname(__file__), default_stylesheet))
29
default_template = 'template.txt'
31
default_template_path = utils.relative_path(
32
os.path.join(os.getcwd(), 'dummy'),
33
os.path.join(os.path.dirname(__file__), default_template))
35
settings_spec = html4css1.Writer.settings_spec + (
36
'PEP/HTML-Specific Options',
37
'For the PEP/HTML writer, the default value for the --stylesheet-path '
38
'option is "%s", and the default value for --template is "%s". '
39
'See HTML-Specific Options above.'
40
% (default_stylesheet_path, default_template_path),
41
(('Python\'s home URL. Default is "http://www.python.org".',
43
{'default': 'http://www.python.org', 'metavar': '<URL>'}),
44
('Home URL prefix for PEPs. Default is "." (current directory).',
46
{'default': '.', 'metavar': '<URL>'}),
48
(frontend.SUPPRESS_HELP,
50
{'action': 'store_true', 'validator': frontend.validate_boolean}),))
52
settings_default_overrides = {'stylesheet_path': default_stylesheet_path,
53
'template': default_template_path,}
55
relative_path_settings = (html4css1.Writer.relative_path_settings
58
config_section = 'pep_html writer'
59
config_section_dependencies = ('writers', 'html4css1 writer')
62
html4css1.Writer.__init__(self)
63
self.translator_class = HTMLTranslator
65
def interpolation_dict(self):
66
subs = html4css1.Writer.interpolation_dict(self)
67
settings = self.document.settings
68
pyhome = settings.python_home
69
subs['pyhome'] = pyhome
70
subs['pephome'] = settings.pep_home
72
subs['pepindex'] = '.'
74
subs['pepindex'] = pyhome + '/dev/peps'
75
index = self.document.first_child_matching_class(nodes.field_list)
76
header = self.document[index]
77
self.pepnum = header[0][1].astext()
78
subs['pep'] = self.pepnum
79
if settings.no_random:
83
subs['banner'] = random.randrange(64)
85
subs['pepnum'] = '%04i' % int(self.pepnum)
87
subs['pepnum'] = self.pepnum
88
self.title = header[1][1].astext()
89
subs['title'] = self.title
90
subs['body'] = ''.join(
91
self.body_pre_docinfo + self.docinfo + self.body)
94
def assemble_parts(self):
95
html4css1.Writer.assemble_parts(self)
96
self.parts['title'] = [self.title]
97
self.parts['pepnum'] = self.pepnum
100
class HTMLTranslator(html4css1.HTMLTranslator):
102
def depart_field_list(self, node):
103
html4css1.HTMLTranslator.depart_field_list(self, node)
104
if 'rfc2822' in node['classes']:
105
self.body.append('<hr />\n')