如何让 restructedText 添加一个类到每个 html
标签?
我正在使用 Django 的标记包将 restructedText 转换为 html。有没有办法自定义 HTML 编写器以向每个
标记添加类属性?
我可以为每个段落使用 class 指令,但我'我想自动化这个过程。
例如,我想要将这个重组文本:
hello
=====
A paragraph of text.
转换为这个html。
<h1>hello</h1>
<p class="specialClass">A paragraph of text.</p>
我想插入类的原因是因为我正在使用 连字符库,它的工作原理是添加具有“hyphenate”类的所有标签的连字符。我可以将连字符类添加到容器标记,但随后所有子级都会继承连字符类。我可以使用 javascript 动态添加类,但我认为可能有一种简单的方法可以使用 restructedText 来完成此操作。
谢谢你的帮助,
乔
I'm using Django's markup package to transform restructuredText into html. Is there a way to customize the HTML writer to add a class attribute to each <p>
tag?
I could use the class directive for each paragraph, but I'd like to automate this process.
For example, I want this restructured text:
hello
=====
A paragraph of text.
To be converted to this html.
<h1>hello</h1>
<p class="specialClass">A paragraph of text.</p>
The reason I want to insert classes is because I'm using the hyphenator library which works by adding hyphens to all tags with a "hyphenate" class. I could add the hyphenate class to the container tag, but then all the children would inherit the hyphenate class. I could use javascript to dynamically add the class, but I thought there might be a simple way to do it with restructuredText.
Thanks for the help,
Joe
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 this 作为参考..
然后像这样使用它:
Subclass the built-in
html4css1
writer, using this as a reference..Then use it like this:
您没有说明为什么要向每个段落添加一个类,但采用不同的方法可能会更容易。例如,如果您尝试设置段落样式,则可以使用不同的 CSS 技术来选择输出中的所有段落:
CSS:
HTML:
Update: 由于您尝试使用 hyphenator.js,我建议使用其 < code>selectorfunction 设置以不同方式选择元素:
You don't say why you want to add a class to every paragraph, but it might be easier to take a different approach. For example, if you are trying to style the paragraphs, you can use a different CSS technique to select all the paragraphs in the output:
CSS:
HTML:
Update: since you are trying to use hyphenator.js, I would suggest using its
selectorfunction
setting to select the elements differently: