I created a super small extention to add the role "icon" in my doc. The idea is to write down the following :
I'm a folder :icon:`fa fa-folder`
I adapted some code find online and came up with the following:
from docutils import nodes
def icon_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
"""add inline icons
Returns 2 part tuple containing list of nodes to insert into the
document and a list of system messages. Both are allowed to be
empty.
:param name: The role name used in the document.
:param rawtext: The entire markup snippet, with role.
:param text: The text marked with the role.
:param lineno: The line number where rawtext appears in the input.
:param inliner: The inliner instance that called us.
:param options: Directive options for customization.
:param content: The directive content for customization.
"""
node =nodes.reference()
html = f"<i class=\"{text}\"></i>"
node = nodes.raw('', html, format='html')
return [node], []
def setup(app):
"""Install the plugin.
:param app: Sphinx application context.
"""
app.add_role('icon', icon_role)
return
The problem is that the role is not taken into account in my pdf output, it remains blank. Is there extra code I should add to make it work in latex as well ?