Browse Source

Add config option to choose the anchor target.

Alberto Donato 8 years ago
parent
commit
b2fa769535
2 changed files with 17 additions and 2 deletions
  1. 3 0
      headerid/README.rst
  2. 14 2
      headerid/headerid.py

+ 3 - 0
headerid/README.rst

@@ -5,6 +5,9 @@ This plugin adds an anchor to each heading so you can deep-link to headers.
 It is intended for formats such as reStructuredText that do not natively
 generate these anchors.
 
+The ``HEADERID_LINK_CHAR`` config can be set to use a different char from ``*``
+for anchor text.
+
 For Markdown, this plugin is less relevant since the Python-Markdown library
 includes a Table of Contents extension that will generate link anchors.
 To enable the ``toc`` extension, add a line similar to the following example

+ 14 - 2
headerid/headerid.py

@@ -3,7 +3,19 @@ from pelican.readers import PelicanHTMLTranslator
 from pelican import signals
 from docutils import nodes
 
+LINK_CHAR = '*'
+
+
+def init_headerid(sender):
+    global LINK_CHAR
+    char = sender.settings.get('HEADERID_LINK_CHAR')
+    if char:
+        LINK_CHAR = char
+
 def register():
+    signals.initialized.connect(init_headerid)
+
+
     class HeaderIDPatchedPelicanHTMLTranslator(PelicanHTMLTranslator):
         def depart_title(self, node):
             close_tag = self.context[-1]
@@ -13,7 +25,7 @@ def register():
                 # add permalink anchor
                 if close_tag.startswith('</h'):
                     self.body.append(
-                        '<a class="headerlink" href="#%s" title="Permalink to this headline">*</a>' % anchor_name
-                    )
+                        '<a class="headerlink" href="#%s" title="Permalink to this headline">%s</a>' %
+                        (anchor_name, LINK_CHAR))
             PelicanHTMLTranslator.depart_title(self, node)
     readers.PelicanHTMLTranslator = HeaderIDPatchedPelicanHTMLTranslator