SOURCE

var str = "# abc\n"
	+ "```\n"
	+ "123\n"
	+ "```\n"
	+ "";
//console.log();
tranMDToHTMLLine(str);

function tranMDToHTML(md) {
	//md = md.replace(/(.+)\n\s*(={2,}|-{2,})\s*$/g, "<div class='archor'>$1</div><hr>");
	var pre = new RegExp("`{3}\n((.|\n)*?)`{3}", "g");
	var arr, str;				// arr结果数组,str处理字符串
	var html = "";	// 存放生成html
	var mdIndex = 0; //当前md处理位置
	while ((arr = pre.exec(md)) != null)
	{
		if (mdIndex <= arr.index)
		{
			// 中间不被<pre>包含的字符串
			//str = tranMDToHTMLLine(md.substring(mdIndex, arr.index - mdIndex));
			//html += str;
		}
		if (mdIndex == arr.index)
		{
			// <pre>加入pre标签
			str = "<pre>" + arr[1] + "</pre>";
			html += str;
			// 记录
			mdIndex += arr[0].length;
		}
	}
	if (mdIndex <= arr.index)
	{
		// 中间不被<pre>包含的字符串
		//str = tranMDToHTMLLine(md.substring(mdIndex, arr.index - mdIndex));
		//html += str;
	}
	md = md.replace(/\t/g, "    ");
	md = md.replace(/ /g, "&nbsp;");
	md = md.replace(/\n/g, "<br>");
	return html;
}

function tranMDToHTMLLine(md) {
	var exp = {
		h: {
			exp: new RegExp("#+\\s(.+)\n", "g"),
			array: []
			},
		title: new RegExp("(.+)\n\\s=+\\s", "g"),
		titleSmall: new RegExp("(.+)\n\\s-+\\s", "g")
		
	};
	var arr, str;				// arr结果数组,str处理字符串
	var html = "";	// 存放生成html
	var mdIndex = 0; //当前md处理位置
	while ((arr = exp.exec(md)) != null)
	{
		
	}
	console.log(exp.h.exec(md));
	return html;
}
console 命令行工具 X clear

                    
>
console