Skip to content

Instantly share code, notes, and snippets.

@chjj
Created August 18, 2011 22:46
Show Gist options
  • Select an option

  • Save chjj/1155469 to your computer and use it in GitHub Desktop.

Select an option

Save chjj/1155469 to your computer and use it in GitHub Desktop.
two paragraphs
var fs = require('fs')
, marked = require('marked');
var text = fs.readFileSync(__dirname + '/test.md', 'utf8');
var two = function(str) {
var tokens = marked.lexer(str)
, paragraphs = 0
, i = 0
, token;
while (token = tokens[i++]) {
if (token.type !== 'text') {
if (token.type === 'space') {
if (++paragraphs === 2) break;
} else {
break;
}
}
}
tokens.length = i;
return marked.parser(tokens);
};
console.log(two(text));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment