How to print out a markdown file on the console us

2020-03-01 20:15发布

问题:

I have a README.md (markdown syntax) that I want to print out to the console using node.js.

Is this possible?

回答1:

First install markdown-js (https://github.com/evilstreak/markdown-js)

$ npm install markdown-js

Then make a javascript:

var markdown = require("markdown-js");
var fs = require("fs");

var str = fs.readFileSync("filename.md", "utf8");

var result = markdown.makeHtml(str);

console.log(result);


回答2:

npm i -g marky-markdown
marky-markdown input.md > output.html
cat output.html

npmjs display pages use Maruku markdown. If you want to see how they will be displayed use the npm package marky-markdown as this is what npmjs uses. A full description is available on their blog.