I want the same functionality mention in Sphinx, reStructuredText show/hide code snippets. But there is no code shared on that post.
我想要Sphinx中提到的相同功能,structuredtext show/hide代码片段。但这篇文章没有共享代码。
1 个解决方案
#1
6
SQLAlchemy docs
The SQLAlchemy documentation uses a special extension (https://bitbucket.org/zzzeek/zzzeeksphinx/).
SQLAlchemy文档使用了一个特殊的扩展(https://bitbucket.org/zzzeek/zzzeek/zzzeeksphinx/)。
The documentation source contains markup with custom options and tokens, like in this example:
文档源包含带有自定义选项和令牌的标记,例如在本例中:
.. sourcecode:: python+sql
{sql}>>> engine.execute("select 1").scalar()
select 1
()
{stop}1
This is processed by a special Pygments lexer (PythonWithSQLLexer
) and Pygments formatter (PopupSQLFormatter
) in order to generate a "popup" <div>
with the code snippet and the link that shows/hides it. The source code is in sqlformatter.py.
它由一个特殊的Pygments lexer (PythonWithSQLLexer)和Pygments formatter (PopupSQLFormatter)处理,以便生成带有代码片段和显示/隐藏它的链接的“弹出”
The show/hide toggling is handled by jQuery magic in init.js.
这个show/hide toggle是由jQuery magic在init中处理的。
The Mako templating system is used to generate the HTML pages (the default templating system in Sphinx is Jinja). This is configured by subclassing TemplateBridge
in mako.py.
Mako模板系统用于生成HTML页面(Sphinx中的默认模板系统是Jinja)。这是通过在mako.py中子类化TemplateBridge来配置的。
In the template file layout.mako, the paths to CSS and JavaScript files (including init.js) are specified. For more on Sphinx templating, see http://sphinx-doc.org/templating.html.
在模板文件布局中。指定CSS和JavaScript文件(包括init.js)的路径。更多关于Sphinx模板的信息,请参见http://sphinx- doc.org/templat.html。
Python docs
Many code examples in the Python documentation feature a "button" that toggles display of interactive prompts (>>>
, ...
) and output in doctest-style code snippets. With prompts and output out of the way, the code can be more easily copied and pasted. Here are several examples: http://docs.python.org/library/datetime.html#module-datetime.
Python文档中的许多代码示例都有一个“按钮”,可以在doctest风格的代码片段中显示交互式提示(>>>,…)和输出。有了提示符和输出,就可以更容易地复制和粘贴代码。这里有几个例子:http://docs.python.org/library/datetime.html#module-datetime。
The feature is implemented in copybutton.js.
该特性是在copybutton.js中实现的。
#1
6
SQLAlchemy docs
The SQLAlchemy documentation uses a special extension (https://bitbucket.org/zzzeek/zzzeeksphinx/).
SQLAlchemy文档使用了一个特殊的扩展(https://bitbucket.org/zzzeek/zzzeek/zzzeeksphinx/)。
The documentation source contains markup with custom options and tokens, like in this example:
文档源包含带有自定义选项和令牌的标记,例如在本例中:
.. sourcecode:: python+sql
{sql}>>> engine.execute("select 1").scalar()
select 1
()
{stop}1
This is processed by a special Pygments lexer (PythonWithSQLLexer
) and Pygments formatter (PopupSQLFormatter
) in order to generate a "popup" <div>
with the code snippet and the link that shows/hides it. The source code is in sqlformatter.py.
它由一个特殊的Pygments lexer (PythonWithSQLLexer)和Pygments formatter (PopupSQLFormatter)处理,以便生成带有代码片段和显示/隐藏它的链接的“弹出”
The show/hide toggling is handled by jQuery magic in init.js.
这个show/hide toggle是由jQuery magic在init中处理的。
The Mako templating system is used to generate the HTML pages (the default templating system in Sphinx is Jinja). This is configured by subclassing TemplateBridge
in mako.py.
Mako模板系统用于生成HTML页面(Sphinx中的默认模板系统是Jinja)。这是通过在mako.py中子类化TemplateBridge来配置的。
In the template file layout.mako, the paths to CSS and JavaScript files (including init.js) are specified. For more on Sphinx templating, see http://sphinx-doc.org/templating.html.
在模板文件布局中。指定CSS和JavaScript文件(包括init.js)的路径。更多关于Sphinx模板的信息,请参见http://sphinx- doc.org/templat.html。
Python docs
Many code examples in the Python documentation feature a "button" that toggles display of interactive prompts (>>>
, ...
) and output in doctest-style code snippets. With prompts and output out of the way, the code can be more easily copied and pasted. Here are several examples: http://docs.python.org/library/datetime.html#module-datetime.
Python文档中的许多代码示例都有一个“按钮”,可以在doctest风格的代码片段中显示交互式提示(>>>,…)和输出。有了提示符和输出,就可以更容易地复制和粘贴代码。这里有几个例子:http://docs.python.org/library/datetime.html#module-datetime。
The feature is implemented in copybutton.js.
该特性是在copybutton.js中实现的。