Sphinx,reStructuredText显示/隐藏代码段 [英] Sphinx, reStructuredText show/hide code snippets

查看:91
本文介绍了Sphinx,reStructuredText显示/隐藏代码段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 Sphinx reStructuredText



在我的文档中,有一些长代码段。我希望能够默认隐藏它们,并带有一个小的显示/隐藏按钮以将其展开(示例)。



是否有标准的方法?

解决方案

我认为最简单的方法是创建一个自定义Sphinx主题,在其中您告诉某些html元素具有此功能。



但是,如果您希望能够在reStructuredText标记中指定它,则需要




  • 将这样的东西包含在Sphinx本身中或

  • 在Sphinx / docutils扩展中实现它...以及然后创建一个了解此功能的Sphinx主题。



这会花费更多的精力,但会给您带来更大的灵活性。 / p>

I've been documenting a software package using Sphinx and reStructuredText.

Within my documents, there are some long code snippets. I want to be able to have them hidden as default, with a little "Show/Hide" button that would expand them (Example).

Is there a standard way to do that?

解决方案

I think the easiest way to do this would be to create a custom Sphinx theme in which you tell certain html elements to have this functionality. A little JQuery would go a long way here.

If, however you want to be able to specify this in your reStructuredText markup, you would need to either

  • get such a thing included in Sphinx itself or
  • implement it in a Sphinx/docutils extension...and then create a Sphinx theme which knew about this functionality.

This would be a bit more work, but would give you more flexibility.

这篇关于Sphinx,reStructuredText显示/隐藏代码段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆