chiark / gitweb /
m.htmlsanity: style footnotes with our CSS classes.
authorVladimír Vondruš <mosra@centrum.cz>
Fri, 29 Mar 2019 09:57:02 +0000 (10:57 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Fri, 29 Mar 2019 12:44:31 +0000 (13:44 +0100)
pelican-plugins/m/htmlsanity.py
pelican-plugins/m/test/htmlsanity_content/page.html
pelican-plugins/m/test/htmlsanity_content/page.rst

index 86af90a7c504fc82426d7244264f03f56db4880b..df73ebc5cf13301cf7f45879dd6e0e08fee2e1e9 100644 (file)
@@ -443,6 +443,44 @@ class SaneHtmlTranslator(HTMLTranslator):
     def depart_line(self, node):
         self.body.append('<br />\n')
 
+    # Footnote list. Replacing the classes with just .m-footnote.
+    def visit_footnote(self, node):
+        if not self.in_footnote_list:
+            self.body.append('<dl class="m-footnote">\n')
+            self.in_footnote_list = True
+
+    def depart_footnote(self, node):
+        self.body.append('</dd>\n')
+        if not isinstance(node.next_node(descend=False, siblings=True),
+                          nodes.footnote):
+            self.body.append('</dl>\n')
+            self.in_footnote_list = False
+
+    # Footnote reference
+    def visit_footnote_reference(self, node):
+        href = '#' + node['refid']
+        self.body.append(self.starttag(node, 'a', '', CLASS='m-footnote', href=href))
+
+    def depart_footnote_reference(self, node):
+        self.body.append('</a>')
+
+    # Footnote and citation labels
+    def visit_label(self, node):
+        self.body.append(self.starttag(node.parent, 'dt', ''))
+
+    def depart_label(self, node):
+        if self.settings.footnote_backlinks:
+            backrefs = node.parent['backrefs']
+            if len(backrefs) == 1:
+                self.body.append('</a>')
+        self.body.append('.</dt>\n<dd><span class="m-footnote">')
+        if len(backrefs) == 1:
+            self.body.append('<a href="#{}">^</a>'.format(backrefs[0]))
+        else:
+            self.body.append('^ ')
+            self.body.append(format(' '.join('<a href="#{}">{}</a>'.format(ref, chr(ord('a') + i)) for i, ref in enumerate(backrefs))))
+        self.body.append('</span> ')
+
     def visit_line_block(self, node):
         self.body.append(self.starttag(node, 'p'))
 
index 3c1322060f726195465efbc8456b9469a089e399..3a7dc574dc053b4ef962e6a6466abeb8dfcf4137 100644 (file)
@@ -26,8 +26,8 @@
 <aside class="contents m-block m-default" id="contents">
 <h3>Contents</h3>
 <ul>
-<li><a href="#section-title" id="id3">Section title</a><ul>
-<li><a href="#section-title-with-link" id="id4">Section title with link</a></li>
+<li><a href="#section-title" id="id6">Section title</a><ul>
+<li><a href="#section-title-with-link" id="id7">Section title with link</a></li>
 </ul>
 </li>
 </ul>
@@ -74,14 +74,16 @@ content<br />
 <dd>Description of term 2</dd>
 </dl>
 <section id="section-title">
-<h2><a class="toc-backref" href="#id3">Section title</a></h2>
+<h2><a class="toc-backref" href="#id6">Section title</a></h2>
 <p>An <em>emphasised text</em>, <strong>strong text</strong> and a <code>literal</code>. Link to
 <a href="https://google.com">Google</a>, <a href="#a-heading">the heading below</a> or just an
 URL as-is: <a href="https://mcss.mosra.cz/">https://mcss.mosra.cz/</a>. <a href="mailto:mosra&#64;centrum.cz">E-mail</a>. A footnote
-reference: <a class="footnote-reference brackets" href="#id2" id="id1">1</a></p>
-<dl class="footnote brackets">
-<dt class="label" id="id2"><span class="brackets"><a class="fn-backref" href="#id1">1</a></span></dt>
-<dd>A footnote description</dd>
+reference on a single thing <a class="m-footnote" href="#id4" id="id1">1</a> and more things <a class="m-footnote" href="#id4" id="id2">1</a> <a class="m-footnote" href="#id5" id="id3">2</a></p>
+<dl class="m-footnote">
+<dt id="id4">1.</dt>
+<dd><span class="m-footnote">^ <a href="#id1">a</a> <a href="#id2">b</a></span> A footnote description</dd>
+<dt id="id5">2</a>.</dt>
+<dd><span class="m-footnote"><a href="#id3">^</a></span> Second thing description</dd>
 </dl>
 <section id="section-title-with-link">
 <h3><a href="#section-title-with-link">Section title with link</a></h3>
index e0fd5b2f2a99ba04cc402542b1082b1bd9e3a65d..156d8f967cb8c3e6377b25bbd6bc94b4423e5ec4 100644 (file)
@@ -48,9 +48,10 @@ Section title
 An *emphasised text*, **strong text** and a ``literal``. Link to
 `Google <https://google.com>`_, `the heading below <#a-heading>`_ or just an
 URL as-is: https://mcss.mosra.cz/. `E-mail <mosra@centrum.cz>`_. A footnote
-reference: [1]_
+reference on a single thing [1]_ and more things [1]_ [2]_
 
 .. [1] A footnote description
+.. [2] Second thing description
 
 `Section title with link`_
 --------------------------