是有一个简单的方法来改变HTML到降价JAVA?

我目前正在使用的Java MarkdownJ 图书馆改变降到html。

import com.petebevin.markdown.MarkdownProcessor;
...
public static String getHTML(String markdown) {
    MarkdownProcessor markdown_processor = new MarkdownProcessor();
    return markdown_processor.markdown(markdown);
}

public static String getMarkdown(String html) {
/* TODO Ask stackoverflow */
}
有帮助吗?

解决方案

使用这个 XSLT.

如果你需要帮助使用XSLT和爪哇这是一段代码:

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));
    }

其他提示

我碰到的话转换HTML。 参见: http://remark.overzealous.com/manual/index.html 它取决于JSoup,一个强大的Java图书馆的工作与现实世界HTML。

我工作上的相同的问题,并尝试一些不同的技术。

回答上述可能的工作。你可以使用 jTidy库 要做的初始清理工作,并将从HTML XHTML。你使用 XSLT样式表 联系以上。

不幸的是,没有图书馆,有一站式的功能这样做。你可以尝试使用Python脚本 html2text 与Script,但我还没有尝试过这个!

如果您使用大规模毁灭性武器的编辑,并希望得到的降价码在服务器上,使用这些选项之前装的 wmd.js 脚本:

wmd_options = {
        // format sent to the server.  can also be "HTML"
        output: "Markdown",

        // line wrapping length for lists, blockquotes, etc.
        lineLength: 40,

        // toolbar buttons.  Undo and redo get appended automatically.
        buttons: "bold italic | link blockquote code image | ol ul heading hr",

        // option to automatically add WMD to the first textarea found.
        autostart: true
    };
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top