是否有一个体面的、可定制的 HTML 到 Markdown Java API?
我想保存从各种来源抓取的文本,但不包含 HTML 标签,但也尽可能保留合理的结构。
Markdown 似乎是这个问题的解决方案(或者可能是 MultiMarkdown)。
有一个问题提供了从 HTML 转换为 Markdown 的建议,但我想要指定一些具体的事情:
- 所有链接(包括图像)仅在END处引用(即没有内联url)
- 没有嵌入的HTML(我什至还没有100%确定我想如何处理困难的HTML...但它不会被嵌入!)
所以我的问题如标题中所述:是否有一个体面的、可定制的 HTML 到 Markdown Java API?
I want to save text I scrape from various sources without the HTML tags that are on it, but also keeping as much of the structure as I reasonably can.
Markdown seems to be the solution to this (or possibly MultiMarkdown).
There is a question which offers a suggestion on converting from HTML to markdown, but I want to specify some specific things:
- ALL links (including images) are referenced at the END only (i.e. no inline urls)
- NO embeded HTML (I'm not even 100% sure yet how I'd like to deal with difficult HTML... but it won't be embeded!)
So my question is as stated in the title: Is there a decent, customisable, HTML to Markdown Java API?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试调整 HtmlCleaner ,它在 DOM 上提供了一个可行的接口:
这将允许您在 DOM 上构建输出流使用相当简单的 API 可以处理任何您想要的格式。
You could try adapting HtmlCleaner which provides a workable interface onto the DOM:
This would allow you to structure your output stream in any format that you want using a fairly simple API.
有一个很棒的 JS 库,名为 Turndown,你可以在线尝试此处。它可以部分定制。例如,可以在末尾引用链接。据我所知,没有嵌入 html,一切都被转换了。
我需要它用于 Java(作为链接的问题),所以我移植了它。 Java 库称为 CopyDown,它具有与 Turndown 相同的测试套件。
使用 gradle 安装:
然后使用它:
There is a great library for JS called Turndown, you can try it online here. It can be partially customized. For example, links can be referenced at the end. And as far as I know there is no embedded html, everything is transformed.
I needed it for Java (as the linked question), so I ported it. The library for Java is called CopyDown, it has the same test suite as Turndown.
To install with gradle:
Then to use it: