Last active
October 6, 2020 10:08
-
-
Save janw/96f4d866f4cf7c1a2b9afa197223554f to your computer and use it in GitHub Desktop.
Font Awesome role for sphinx documentation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Place in docs/_ext | |
# | |
# Add to conf.py: | |
# sys.path.append(os.path.abspath("./_ext") | |
# extensions = [ | |
# # ... | |
# 'fontawesome', | |
# ] | |
# | |
from docutils.nodes import emphasis | |
from docutils.parsers.rst.roles import set_classes | |
def fa(role, rawtext, text, lineno, inliner, options={}, content=[]): | |
"""Adds an `:fa:` role to docs to insert an icon from Font Awesome. | |
The extension assumes that fontawesome assets are already included in the | |
document build, for example by using the `sphinx_rtd_theme` theme, which | |
uses Font Awesome as well. | |
""" | |
classes = ["fa"] | |
for x in text.split(","): | |
classes.append('fa-{}'.format(x)) | |
options.update({'classes': classes}) | |
set_classes(options) | |
node = emphasis(**options) | |
return [node], [] | |
def setup(app): | |
app.add_role('fa', fa) | |
return {'version': "0.1"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment