.. title: ReST und Unterstreichen in Nikola
.. slug: restful-underline
.. date: 2015-08-24 12:02:51+02:00
.. tags: web,python
.. category:
.. link:
.. description:
.. type: text
Manchmal mag man was unterstreichen. ``*kursiv*`` bzw. ``kursiv`` macht aber kursiv. Klar, das kann man per Stylesheet ändern, aber was ist wenn man Beides braucht?
In meinem Blogsystem (`Nikola `_) geht das so:
.. TEASER_END
* in ``plugins/under.plugin``:
.. code-block::
[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``:
.. code-block:: python
# -*- 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``:
.. code-block:: css
em.underline { font-style: normal; text-decoration: underline; }
* … und schon kannst du :u:`unterstreichen`.
.. code-block:: rest
… und schon kannst du :u:`unterstreichen`.
Bitte sehr.