mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Add support for abbreviations to reST translator (fixes #395).
This commit is contained in:
parent
be2f04f082
commit
636fd6cc38
4 changed files with 39 additions and 4 deletions
|
|
@ -63,6 +63,18 @@ def render_node_to_html(document, node):
|
|||
return visitor.astext()
|
||||
|
||||
|
||||
class PelicanHTMLTranslator(HTMLTranslator):
|
||||
|
||||
def visit_abbreviation(self, node):
|
||||
attrs = {}
|
||||
if node.hasattr('explanation'):
|
||||
attrs['title'] = node['explanation']
|
||||
self.body.append(self.starttag(node, 'abbr', '', **attrs))
|
||||
|
||||
def depart_abbreviation(self, node):
|
||||
self.body.append('</abbr>')
|
||||
|
||||
|
||||
class RstReader(Reader):
|
||||
enabled = bool(docutils)
|
||||
file_extensions = ['rst']
|
||||
|
|
@ -92,6 +104,7 @@ class RstReader(Reader):
|
|||
pub = docutils.core.Publisher(
|
||||
destination_class=docutils.io.StringOutput)
|
||||
pub.set_components('standalone', 'restructuredtext', 'html')
|
||||
pub.writer.translator_class = PelicanHTMLTranslator
|
||||
pub.process_programmatic_settings(None, extra_params, None)
|
||||
pub.set_source(source_path=filename)
|
||||
pub.publish()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue