Java使用PegDown将markdown文件转成html格式

maven依赖:

	<dependency>
	    <groupId>org.pegdown</groupId>
	    <artifactId>pegdown</artifactId>
	    <version>1.6.0</version>
	</dependency>

示例代码:

package com.zifeiy.page;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import org.pegdown.PegDownProcessor;

public class PageGenerator {
	
	public void generateHtml(File mdFile) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(mdFile), "UTF-8"));
        String line = null;
        String mdContent = "";
        while ((line = br.readLine()) != null) {
            mdContent += line + "\r\n";
        }
        PegDownProcessor pdp = new PegDownProcessor(Integer.MAX_VALUE);
        String htmlContent = pdp.markdownToHtml(mdContent);
        System.out.println(htmlContent);
	}
	
	
	public static void main(String[] args) throws IOException {
		PageGenerator pageGenerator = new PageGenerator();
		pageGenerator.generateHtml(new File("D:\\projects\\zifeiy.github.io\\笔记\\20181125我的第一篇博客.md"));
	}
	
}
posted @ 2018-11-25 20:52  zifeiy  阅读(4833)  评论(0编辑  收藏  举报