【发布时间】:2018-08-29 05:37:06
【问题描述】:
我喜欢编写 HTML,并且倾向于使用很少的 JavaScript 编写平面网站。我一直在思考编写一种使用 XPath 和 XMLNS 来引用其他文档的新“语言”的想法。
我一直在尝试如何编写我的 HTML,然后我会运行一个构建工具来扩展和构建完整的文档。
有没有这样的工具?我宁愿重用或学习已经存在的工具。我怀疑我错过了一个明显或常见的工具,它已经做了类似的事情。
示例
这通常是我希望编写 HTML 的方式(或 HTMPL,因为它是模板,所以我一直这么称呼它)。
index.htmpl
<html xmlns:custom="card.htmpl">
<custom:card img="/path/to/image.jpg">
<title>Title content here</title>
This is the card
</custom:card>
</html>
card.htmpl
<div class="card">
<img src="[[//card@img]]" />
<div class="title">The title is: [[//card/title/text()]]</div>
<div class="content">[[//card/text()]]</div>
</div>
结果
去掉多余的空格
<html>
<div>
<img src="/path/to/image.jpg" />
<div class="title">The title is: Title content here</div>
<div class="content">This is the card</div>
</div>
</html>
【问题讨论】:
-
立即让我想起 XSLT...
标签: html xml xpath templating