From: Vladimír Vondruš Date: Thu, 14 Sep 2017 22:06:49 +0000 (+0200) Subject: plugins: new m.abbr plugin. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=f71b1d5486518eb5177a91cfc2caf6a4f81d4c9b;p=blog.git plugins: new m.abbr plugin. Makes the :abbr: directive syntax consistent with links. Also required patching in m.htmlsanity. --- diff --git a/pelican-plugins/m/abbr.py b/pelican-plugins/m/abbr.py new file mode 100644 index 00000000..8c91c164 --- /dev/null +++ b/pelican-plugins/m/abbr.py @@ -0,0 +1,12 @@ +from . import parse_link +from docutils import nodes +from docutils.parsers import rst + +def abbr(name, rawtext, text, lineno, inliner, options={}, content=[]): + abbr, title = parse_link(text) + if not title: + return [nodes.abbreviation(abbr, abbr)], [] + return [nodes.abbreviation(abbr, abbr, title=title)], [] + +def register(): + rst.roles.register_local_role('abbr', abbr) diff --git a/pelican-plugins/m/htmlsanity.py b/pelican-plugins/m/htmlsanity.py index 8b68f3f3..ac297e94 100644 --- a/pelican-plugins/m/htmlsanity.py +++ b/pelican-plugins/m/htmlsanity.py @@ -203,6 +203,16 @@ class SaneHtmlTranslator(HTMLTranslator): self.docinfo = self.body[start:] self.body = [] + # Have properly with title + def visit_abbreviation(self, node): + attrs = {} + if node.hasattr('title'): + attrs['title'] = node['title'] + self.body.append(self.starttag(node, 'abbr', '', **attrs)) + + def depart_abbreviation(self, node): + self.body.append('') + # Remove useless cruft from images, such as width, height, scale; don't put # URI in alt text. def visit_image(self, node):