Class 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.

    • Constructor Detail

      • HtmlToMarkdownConverter

        public HtmlToMarkdownConverter()
    • 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)
      • ensureEmptyOrEndsWith

        protected void ensureEmptyOrEndsWith​(@Nonnull
                                             String suffix)
        We ensure sb is either empty or that it ends with the given suffix.