这在从 Markdown 转换为 HTML 时会派上用场,例如,如果需要防止评论出现在最终的 HTML 源代码中。
示例输入my.md
:
# Contract Cancellation
Dear Contractor X, due to delays in our imports, we would like to ...
<!--
... due to a general shortage in the Y market
TODO make sure to verify this before we include it here
-->
best,
me <!-- ... or should i be more formal here? -->
示例输出 my-filtered.md
:
# Contract Cancellation
Dear Contractor X, due to delays in our imports, we would like to ...
best,
me
在 Linux 上,我会做这样的事情:
cat my.md | remove_html_comments > my-filtered.md
我还能够编写处理一些常见情况的 AWK 脚本,
但据我所知,无论是 AWK 还是任何其他用于简单文本操作的常用工具(如 sed
)都无法胜任这项工作。需要使用 HTML 解析器。
如何编写合适的 remove_html_comments
脚本,使用什么工具?
最佳答案
我从您的评论中看出您主要使用 Pandoc。
Pandoc version 2.0 ,2017 年 10 月 29 日发布,adds a new option --strip-comments
. related issue为这一变化提供了一些背景信息。
升级到最新版本并在您的命令中添加 --strip-comments
应该在转换过程中删除 HTML 注释。
关于html - 从 Markdown 文件中删除 HTML 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46952210/