[IMP] extensions: icon_role odoo ui

closes odoo/documentation#9252

X-original-commit: a39903ca12
Signed-off-by: Samuel Lieber (sali) <sali@odoo.com>
This commit is contained in:
Sam Lieber (sali) 2024-04-29 17:21:10 -04:00
parent 6f4f511b34
commit 7e04e250b0
2 changed files with 10 additions and 7 deletions

View File

@ -216,18 +216,21 @@ Use the `command` markup to highlight a command.
Icons
-----
Use the `icon` markup to add a class name of an icon. The icon set used is *Font Awesome*. It is
recommended to accompany an icon with a :ref:`contributing/markups/guilabel` as a descriptor,
however, it is not mandatory.
Use the `icon` markup to add a class name of an icon. There are two icon sets used in Odoo:
`FontAwesome4 <https://fontawesome.com/v4/icons/>`_ and :doc:`Odoo UI
</developer/reference/user_interface/icons>`. It is recommended to accompany an icon with a
:ref:`contributing/markups/guilabel` as a descriptor, however, it is not mandatory.
.. list-table::
:class: o-showcase-table
* - The graph view is represented by the :icon:`fa-bar-chart` :guilabel:`(bar chart)` icon.
* - The graph view is represented by the :icon:`fa-area-chart` :guilabel:`(area chart)` icon. The
pivot view is represented by the :icon:`oi-view-pivot` icon.
* - .. code-block:: text
The graph view is represented by the :icon:`fa-bar-chart` :guilabel:`(bar chart)` icon.
The graph view is represented by the :icon:`fa-area-chart` :guilabel:`(area chart)` icon.
The pivot view is represented by the :icon:`oi-view-pivot` icon.
.. _contributing/lists:

View File

@ -115,12 +115,12 @@ def resolve(old_resolve, tree, docname, *args, **kwargs):
def icon_role(name, rawtext, text, lineno, inliner, options=None, content=None):
""" Implement an `icon` role for Odoo and Font Awesome icons. """
for icon_class in text.split():
if not icon_class.startswith('fa-'):
if not (icon_class.startswith('fa-') or icon_class.startswith('oi-')):
report_error = inliner.reporter.error(
f"'{icon_class}' is not a valid icon formatting class.", lineno=lineno
)
error_node = inliner.problematic(rawtext, rawtext, report_error)
return [error_node], [report_error]
icon_html = f'<i class="{text}"></i>'
icon_html = f'<i class="oi {text}"></i>' if text.startswith('oi-') else f'<i class="{text}"></i>'
node = nodes.raw('', icon_html, format='html')
return [node], []