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
= ('template',)
57 config_section
= 'pep_html writer'
58 config_section_dependencies
= ('writers', 'html4css1 writer')
61 html4css1
.Writer
.__init
__(self
)
62 self
.translator_class
= HTMLTranslator
64 def interpolation_dict(self
):
65 subs
= html4css1
.Writer
.interpolation_dict(self
)
66 settings
= self
.document
.settings
67 pyhome
= settings
.python_home
68 subs
['pyhome'] = pyhome
69 subs
['pephome'] = settings
.pep_home
71 subs
['pepindex'] = '.'
73 subs
['pepindex'] = pyhome
+ '/dev/peps'
74 index
= self
.document
.first_child_matching_class(nodes
.field_list
)
75 header
= self
.document
[index
]
76 self
.pepnum
= header
[0][1].astext()
77 subs
['pep'] = self
.pepnum
78 if settings
.no_random
:
82 subs
['banner'] = random
.randrange(64)
84 subs
['pepnum'] = '%04i' % int(self
.pepnum
)
86 subs
['pepnum'] = self
.pepnum
87 self
.title
= header
[1][1].astext()
88 subs
['title'] = self
.title
89 subs
['body'] = ''.join(
90 self
.body_pre_docinfo
+ self
.docinfo
+ self
.body
)
93 def assemble_parts(self
):
94 html4css1
.Writer
.assemble_parts(self
)
95 self
.parts
['title'] = [self
.title
]
96 self
.parts
['pepnum'] = self
.pepnum
99 class HTMLTranslator(html4css1
.HTMLTranslator
):
101 def depart_field_list(self
, node
):
102 html4css1
.HTMLTranslator
.depart_field_list(self
, node
)
103 if 'rfc2822' in node
['classes']:
104 self
.body
.append('<hr />\n')