Sphinx Readthedocs 主题字体真棒集成

Sphinx Readthedocs theme Font-awesome integration

我知道这可能是一个非常愚蠢的问题,但我没能在网上找到任何关于潜在解决方案的信息。

我正在使用 Sphinx 1.4 and the sphinx_rtd_theme 为我的 Django 项目生成一些文档。我一直在尝试寻找一种方法来在 .rst 文件中使用超棒的字体图标,但没有找到任何方法。我查看了 sphinx_rtd_theme 源文件并且 fa-* 图标包含在 theme.css 文件中。但是,我不知道实际包含它们的方法。

它是指令、解释文本还是类似的东西?我已经尝试了 iconfonticonfa 以及 none工作了。

如有任何帮助,我们将不胜感激。

我知道我可以使用原始 HTML,但我想尽可能避免这种情况。

可以使用Sphinx的rst-class指令,如下:

.. rst-class:: fa fa-fontawesome

   the font awsome flag will be attached to this paragraph

rst-class 将为指定的下一个元素设置 class 属性。

以下代码仅呈现图标:

.. rst-class:: fa fa-font-awesome

   |

当然,您也可以使用自定义 classes 进一步设置元素的样式。

为了使图标在 HTML 上可用,Latex 从 https://fontawesome.com/download 下载 FontAwesome Web 包,将 font-awesome/svgs/solid 包含到您的项目 _static 文件夹中,并使用如下所示的图像指令:

The |fa-bars| function is to toggle the left Sidebar Menu between being collapsed behind the button or displayed on the screen.

.. |fa-bars| image:: _static/font-awesome/svgs/solid/bars.svg
:width: 20px
:alt: hamburguer button

结果:

<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
The <i class="fa fa-bars"></i> function is to toggle the left Sidebar Menu between being collapsed behind the button or displayed on the screen.

我刚刚在学习 Sphinx 并且有同样的问题,但是使用原始 HTML 对我来说很好。也许这个解决方案对外面的人有帮助...

conf.py 文件中,将 link 添加到您的 Fontawesome 套件代码 URL

html_js_files = [
    'https://kit.fontawesome.com/##########.js',
]

然后,通过原始 HTML 指令在 Sphinx 中使用 fontawesome 图标

.. |fa-fort-awesome| raw:: html

   <i class="fab fa-fort-awesome"></i>

Here is some text |fa-fort-awesome| with the icon in the middle.

这是它呈现为 HTML...

的方式

你也可以使用https://sphinx-panels.readthedocs.io/en/latest/#inline-icons:

:fa:`bars`
:fa:`spinner,text-white bg-primary fa-2x,style=fa`