HTML to Markdown with Java

前端 未结 5 2042
臣服心动
臣服心动 2020-12-04 06:52

is there an easy way to transform HTML into markdown with JAVA?

I am currently using the Java MarkdownJ library to transform markdown to html.

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-04 07:31

    Use this XSLT.

    If you need help using XSLT and Java here's a code snippet:

    public static void main(String[] args) throws Exception {
    
            File xsltFile = new File("mardownXSLT.xslt");
    
            Source xmlSource = new StreamSource(new StringReader(theHTML));
            Source xsltSource = new StreamSource(xsltFile);
    
            TransformerFactory transFact =
                    TransformerFactory.newInstance();
            Transformer trans = transFact.newTransformer(xsltSource);
    
            StringWriter result = new StringWriter();
            trans.transform(xmlSource, new StreamResult(result));
        }
    

提交回复
热议问题