Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.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 用于重新结构化文本的自定义指令?_Python_Restructuredtext - Fatal编程技术网

Python 用于重新结构化文本的自定义指令?

Python 用于重新结构化文本的自定义指令?,python,restructuredtext,Python,Restructuredtext,我正在尝试使用docutils的rst2html.py将rst文档转换为html 使用创建的外部超链接 `How to create Product <Django.url('reservation:manual:product:index')>`_ `如何创建产品`_ 转换为 <a class="reference external" href="Django.url('reservation:manual:product:index')">How to creat

我正在尝试使用docutils的rst2html.py将rst文档转换为html

使用创建的外部超链接

`How to create Product <Django.url('reservation:manual:product:index')>`_
`如何创建产品`_
转换为

<a class="reference external" href="Django.url('reservation:manual:product:index')">How to create Product</a>

我想修改rst2html.py(或相关文件),以便生成以下内容

<Link
to={Django.url('reservation:manual:product:index')}
>
</Link>

我不需要使用嵌入式URI格式来表示链接

似乎我可以创建一个自定义指令来指定解析/生成规则


但由于我对RST及其解析器的了解不多,我不确定是否可以在带有指令的句子中嵌入单词短语的链接。

我只想编写一个后处理器。假设Django URL不包含内部标记或可转义字符,如
&
,这里可以使用一个简单的正则表达式(尽管任务的一般性更复杂),例如:

重新导入
s=(‘头尾’)
r=re.sub(r'',
r’、s)
印刷品(r)
输出:

head <Link to={Django.url('reservation:manual:product:index')}></Link> tail
头尾

啊,好主意。谢谢!
head <Link to={Django.url('reservation:manual:product:index')}></Link> tail