11

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

Is this possible?

1
  • 1
    first off, why do you wish to print to the console? and what do you wish to print: html or markdown (or ascii or manpage etc.)? Commented May 24, 2011 at 16:54

2 Answers 2

21

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);
Sign up to request clarification or add additional context in comments.

4 Comments

-1 for recommending readFileSync. Please use asynchronous commands.
for scripts that exit after the first tic async is pointless. It's not like the Sync is inside a response handler.
+1 agreed, for one-offs like this, async offers nothing but complexity.
Of course you should always write async if its a server/service etc, but that was not the nature of the question - and might* have taken away the main point.
0
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.