gergelypolonkai-web-jekyll/my_plugins/custom_roles.py

20 lines
551 B
Python

from docutils import nodes
from docutils.parsers import rst
def keyboard_role(name, rawtext, text, lineno, inliner, options=None, content=None):
return [nodes.raw('', f'<kbd>{text}</kbd>', format='html')], []
def superscript_role(name, rawtext, text, lineno, inliner, options=None, content=None):
return [nodes.raw('', f'<sup>{text}</sup>', format='html')], []
def register_roles():
rst.roles.register_local_role('kbd', keyboard_role)
rst.roles.register_local_role('sup', superscript_role)
def register():
register_roles()