chiark / gitweb /
plugins: new m.abbr plugin.
authorVladimír Vondruš <mosra@centrum.cz>
Thu, 14 Sep 2017 22:06:49 +0000 (00:06 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Wed, 11 Oct 2017 19:54:18 +0000 (21:54 +0200)
Makes the :abbr: directive syntax consistent with links. Also required
patching in m.htmlsanity.

pelican-plugins/m/abbr.py [new file with mode: 0644]
pelican-plugins/m/htmlsanity.py

diff --git a/pelican-plugins/m/abbr.py b/pelican-plugins/m/abbr.py
new file mode 100644 (file)
index 0000000..8c91c16
--- /dev/null
@@ -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)
index 8b68f3f3994886e8c4e29e3958c7e00e0df6326e..ac297e943c607d123edc76cdaf9f4e9906a9c775 100644 (file)
@@ -203,6 +203,16 @@ class SaneHtmlTranslator(HTMLTranslator):
         self.docinfo = self.body[start:]
         self.body = []
 
+    # Have <abbr> 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('</abbr>')
+
     # Remove useless cruft from images, such as width, height, scale; don't put
     # URI in alt text.
     def visit_image(self, node):