Class HtmlToMarkdownConverter
- java.lang.Object
-
- com.composum.ai.backend.base.service.chat.impl.HtmlToMarkdownConverter
-
public class HtmlToMarkdownConverter extends Object
A quick HTML markdown converter that handles the tags [a, strong, code, em, p, br, u, ul, li, ol] used in rich text editor. Not threadsafe, use only once.We do not want to use a library since the libraries doing this have many parts and are quite some work to deploy, and we only need to convert a few tags from richtext editors. Original generated by ChatGPT with "Please make an HTML to Markdown converter that handles the tags [a, strong, code, em, p, br, u, ul, li, ol] . Use the jsoup library for that." but some heavy rewrite.
-
-
Field Summary
Fields Modifier and Type Field Description protected StringBuilder
sb
-
Constructor Summary
Constructors Constructor Description HtmlToMarkdownConverter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
convert(String html)
protected void
convertChildren(org.jsoup.nodes.Node node)
protected void
ensureEmptyOrEndsWith(String suffix)
We ensure sb is either empty or that it ends with the given suffix.protected void
insertText(String text)
Split text into lines to add indentation before each line.
-
-
-
Field Detail
-
sb
protected StringBuilder sb
-
-
Method Detail
-
insertText
protected void insertText(String text)
Split text into lines to add indentation before each line.
-
convertChildren
protected void convertChildren(org.jsoup.nodes.Node node)
-
-