8000 [ADD] extensions: icon_role font awesome · odoo/documentation@e335133 · GitHub
[go: up one dir, main page]

Skip to content

Commit e335133

Browse files
committed
[ADD] extensions: icon_role font awesome
closes #9056 X-original-commit: 8bec283 Signed-off-by: Samuel Lieber (sali) <sali@odoo.com>
1 parent ba801d1 commit e335133

File tree

7 files changed

+960
-0
lines changed

7 files changed

+960
-0
lines changed

content/contributing/documentation/rst_cheat_sheet.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,24 @@ Use the `command` markup to highlight a command.
211211
Run the command :command:`make clean html` to delete existing built files and build the
212212
documentation to HTML.
213213

214+
.. _contributing/markups/icons:
215+
216+
Icons
217+
-----
218+
219+
Use the `icon` markup to add a class name of an icon. The icon set used is *Font Awesome*. It is
220+
recommended to accompany an icon with a :ref:`contributing/markups/guilabel` as a descriptor,
221+
however, it is not mandatory.
222+
223+
.. list-table::
224+
:class: o-showcase-table
225+
226+
* - The graph view is represented by the :icon:`fa-bar-chart` :guilabel:`(bar chart)` icon.
227+
228+
* - .. code-block:: text
229+
230+
The graph view is represented by the :icon:`fa-bar-chart` :guilabel:`(bar chart)` icon.
231+
214232
.. _contributing/lists:
215233

216234
Lists

extensions/odoo_theme/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from docutils import nodes
2+
from docutils.parsers.rst import roles
23
from sphinx import addnodes
34
from sphinx.environment.adapters import toctree
45

@@ -16,6 +17,8 @@ def setup(app):
1617
app.add_js_file('js/page_toc.js')
1718
app.add_js_file('js/switchers.js')
1819

20+
roles.register_canonical_role('icon', icon_role)
21+
1922
return {
2023
'parallel_read_safe': True,
2124
'parallel_write_safe': True
@@ -107,3 +110,17 @@ def _set_docname_as_class(_reference_node, _node_docname):
107110
if resolved_toc: # `resolve` returns None if the depth of the TOC to resolve is too high
108111
_update_toctree_nodes(resolved_toc)
109112
return resolved_toc
113+
114+
115+
def icon_role(name, rawtext, text, lineno, inliner, options=None, content=None):
116+
""" Implement an `icon` role for Odoo and Font Awesome icons. """
117+
for icon_class in text.split():
118+
if not icon_class.startswith('fa-'):
119+
report_error = inliner.reporter.error(
120+
f"'{icon_class}' is not a valid icon formatting class.", lineno=lineno
121+
)
122+
error_node = inliner.problematic(rawtext, rawtext, report_error)
123+
return [error_node], [report_error]
124+
icon_html = f'<i class="{text}"></i>'
125+
node = nodes.raw('', icon_html, format='html')
126+
return [node], []
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)
0