ReST und Unterstreichen in Nikola

Manch­mal mag man was un­ter­strei­chen. *kur­si­v* bzw. <em>­­kur­­si­v</em> macht aber kur­si­v. Kla­r, das kann man per Sty­les­heet än­dern, aber was ist wenn man Bei­des braucht?

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

  • in plug­ins/un­der.plu­g­in:

    [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 plug­ins/un­der.­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 fi­les/as­sets/css/­cu­stom.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.