ReST und Unterstreichen in Nikola

Manchmal mag man was unterstreichen. *kursiv* bzw. <em>­kur­si­v</em> macht aber kursiv. Klar, das kann man per Stylesheet ändern, aber was ist wenn man Beides braucht?

In mei­nem Blog­sys­tem (Ni­ko­la) geht das so:

  • in plugins/under.plugin:

    [Core]
    name = rest_under
    module = under
    
    [Nikola]
    compiler = rest
    plugincategory = CompilerExtension
    
    [Documentation]
    author = Matthias Urlichs
    version = 0.1
    website = https://matthias.urlichs.de/
    description = UnderLine the marked text
    
  • in plugins/under.py:

    # -*- coding: utf-8 -*-
    
    # Copyright © 2015 Matthias Urlichs
    
    """reST role for underlining."""
    
    from docutils import nodes
    from docutils.parsers.rst import roles
    
    from nikola.plugin_categories import RestExtension
    
    class Plugin(RestExtension):
    
        """Plugin for doc role."""
    
        name = 'rest_under'
    
        def set_site(self, site):
            """Set Nikola site."""
            roles.register_canonical_role('u', under_role)
            return super(Plugin, self).set_site(site)
    
    
    def under_role(name, rawtext, text, lineno, inliner,
                 options={}, content=[]):
        """Generate a underline-class emphasis."""
        options = dict(**options)
        options['classes'] = ['underline']
        return [nodes.emphasis(rawtext, text, *content, **options)],[]
    
  • in files/assets/css/custom.css:

    em.underline { font-style: normal; text-decoration: underline; }
    
  • … und schon kannst du un­ter­strei­chen.

    … und schon kannst du :u:`unterstreichen`.
    

Bit­te sehr.