重组文本的自定义指令?
Custom directive for restuctured text?
我正在尝试使用 docutils 的 rst2html.py 将第一个文档转换为 html。
使用
创建的外部超级 link
`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 格式来表达 link。
看来我可以创建自定义指令来指定 parsing/generating 规则。
但由于我对 RST 及其解析器的了解不多,我不确定是否可以在带有指令的句子中为词组嵌入 link。
我会简单地编写一个 post-处理器。假设 Django URL 没有内部标记或可转义字符,如 &
和 "
,一个简单的正则表达式将在这里完成(尽管任务的一般诅咒甚至稍微复杂一点),如:
import re
s = ('head <a class="reference external" href="'
"Django.url('reservation:manual:product:index')"
'">How to create Product</a> tail')
r = re.sub(r'<a class=".*?" href="(Django[.]url[(].*?[)])">.*?</a>',
r'<Link to={}></Link>', s)
print(r)
输出:
head <Link to={Django.url('reservation:manual:product:index')}></Link> tail
我正在尝试使用 docutils 的 rst2html.py 将第一个文档转换为 html。
使用
创建的外部超级 link`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 格式来表达 link。
看来我可以创建自定义指令来指定 parsing/generating 规则。
但由于我对 RST 及其解析器的了解不多,我不确定是否可以在带有指令的句子中为词组嵌入 link。
我会简单地编写一个 post-处理器。假设 Django URL 没有内部标记或可转义字符,如 &
和 "
,一个简单的正则表达式将在这里完成(尽管任务的一般诅咒甚至稍微复杂一点),如:
import re
s = ('head <a class="reference external" href="'
"Django.url('reservation:manual:product:index')"
'">How to create Product</a> tail')
r = re.sub(r'<a class=".*?" href="(Django[.]url[(].*?[)])">.*?</a>',
r'<Link to={}></Link>', s)
print(r)
输出:
head <Link to={Django.url('reservation:manual:product:index')}></Link> tail