java markdown协作_使用Java实现的一款Markdown解析器md2x

使用Java实现的一款Markdown解析器md2x

前段时间在写自己的博客程序的时候,在前台使用了marked.js来解析自己的markdown文章,然后发现在进入文章页面的时候总会闪烁一下(前台解析会耗费一定的时间),所以自己就参考了marked.js的源码,使用java实现了一给markdown解析器在后台使用,这里拿出来分享一下?。

下面是项目的介绍:

md2x

Md2x 是一款运行于Java平台上的轻量级markdown解析器,能够通过简单的调用方式将markdown标记解析为HTML标记。在代码的设计与实现参考了marked.js 的源码,使用了marked.js中的 正则表达式来分析markdown文档进行,以及相似的方法进行解析渲染,编写它的最初目的就是为了在Java中还原一个marked.js。

如何使用Md2x

通过引入Md2x的jar包到你项目当中,你可以通过简单的调用将markdown转换为html

引入md2x的jar包

1. 创建Md2x的实例,调用实例的parse方法

解析markdown字符串

Md2x md2x=new Md2x();

md2x.parse(src);

解析markdown文件

File file=new File(“test.md”)

Md2x md2x=new Md2x();

md2x.parse(file);

你可以对解析器进行一些设置,通过向构造函数中传入Options设置对象。Options对象的默认值与marked.js的默认设置一致。 比如,为解析后的分级标题添加id前缀

Options options=new Opitio

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要用Java开发一个Markdown编辑,可以使用JavaFX图形化界面库来实现。而要集成Editor.md,可以在JavaFX中嵌入WebView组件,然后加载Editor.md的HTML页面即可。 以下是实现步骤: 1. 在JavaFX中创建一个WebView组件 ``` WebView webView = new WebView(); ``` 2. 通过WebView组件加载Editor.md的HTML页面 ``` String htmlContent = "<html><head><link rel=\"stylesheet\" href=\"https://pandao.github.io/editor.md/css/editormd.min.css\"/></head><body><textarea id=\"editor\"></textarea><script src=\"https://pandao.github.io/editor.md/lib/marked.min.js\"></script><script src=\"https://pandao.github.io/editor.md/lib/prettify.min.js\"></script><script src=\"https://pandao.github.io/editor.md/lib/raphael.min.js\"></script><script src=\"https://pandao.github.io/editor.md/lib/underscore.min.js\"></script><script src=\"https://pandao.github.io/editor.md/lib/sequence-diagram.min.js\"></script><script src=\"https://pandao.github.io/editor.md/lib/flowchart.min.js\"></script><script src=\"https://pandao.github.io/editor.md/lib/jquery.min.js\"></script><script src=\"https://pandao.github.io/editor.md/editormd.min.js\"></script><script type=\"text/javascript\">var testEditor = editormd(\"editor\", {});</script></body></html>"; webView.getEngine().loadContent(htmlContent); ``` 3. 将WebView组件添加到JavaFX的场景中 ``` Scene scene = new Scene(webView); stage.setScene(scene); stage.show(); ``` 这样就可以实现一个简单的Markdown编辑,并集成了Editor.md的功能。当然,还需要实现一些逻辑来获取编辑中的内容并进行解析和保存等操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值