Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用rst2html5.py仅获取html正文_Python_Python Sphinx_Restructuredtext_Docutils - Fatal编程技术网

Python 使用rst2html5.py仅获取html正文

Python 使用rst2html5.py仅获取html正文,python,python-sphinx,restructuredtext,docutils,Python,Python Sphinx,Restructuredtext,Docutils,与 其中foo.rst为 rst2html5.py foo.rst --math-output=MathJax > foo.html 我得到了一个独立的html页面foo.html。如果我只是想修改html的主体,例如,这样我就可以插入到另一个html模板中呢 我知道我可以做类似的事情 The area of a circle is :math:`A_\text{c} = (\pi/4) d^2`. .. math:: \frac{ \sum_{t=0}^{N}f

其中
foo.rst

rst2html5.py foo.rst  --math-output=MathJax > foo.html
我得到了一个独立的html页面
foo.html
。如果我只是想修改html的主体,例如,这样我就可以插入到另一个html模板中呢

我知道我可以做类似的事情

The area of a circle is :math:`A_\text{c} = (\pi/4) d^2`.

.. math::

         \frac{ \sum_{t=0}^{N}f(t,k) }{N}
然后获取
文档['body']
,但这不会以MathJax方式处理math指令

也就是说,我希望这具尸体

from docutils import core
text = open('foo.rst').read()
document = core.publish_parts(text, writer_name='html5')
圆的面积是\(a\text{c}=(\pi/4)d^2\)

\开始{等式*} \frac{\sum{t=0}{N}f(t,k)}{N} \结束{方程*} 而不是通常的情况

<p>The area of a circle is <span class="math">\(A_\text{c} = (\pi/4) d^2\)</span>.</p>
<div class="math">
\begin{equation*}
\frac{ \sum_{t=0}^{N}f(t,k) }{N}
\end{equation*}
</div>
圆的面积是Ac = (π ⁄ 4) d2

(N)⎲⎳t = 0f(t, k) )/(N)
首先,如果您使用rst2html5:

<p>The area of a circle is <span class="formula"><i>A</i><sub><span class="text">c</span></sub> = (<i>π</i> ⁄ 4)<i>d</i><sup>2</sup></span>.</p>
<div class="formula">
<span class="fraction"><span class="ignored">(</span><span class="numerator"><span class="limits"><sup class="limit"><i>N</i></sup><span class="limit">⎲</span><span class="limit">⎳</span><sub class="limit"><i>t</i> = 0</sub></span><i>f</i>(<i>t</i>, <i>k</i>)</span><span class="ignored">)/(</span><span class="denominator"><i>N</i></span><span class="ignored">)</span></span>
</div>
然后,您可以使用这段代码来获取主体:

pip install rst2html5
您将得到以下结果:

from docutils.core import publish_parts
from rst2html5_ import HTML5Writer
text = r'''
The area of a circle is :math:`A_\text{c} = (\pi/4) d^2`.

.. math::

       \frac{ \sum_{t=0}^{N}f(t,k) }{N}
'''
body = publish_parts(writer=HTML5Writer(), source=text)['body']
圆的面积是
\(A_uuext{c}=(\pi/4)d^2\)

\(\frac{\sum{t=0}{N}f(t,k)}{N}\)
<p>The area of a circle is
    <span class="math">\(A_   ext{c} = (\pi/4) d^2\)</span>
.</p>
<span class="math">\(\frac{ \sum_{t=0}^{N}f(t,k) }{N}\)</span>