Skip to content

Commit

Permalink
use MarkdownIt instead of marked
Browse files Browse the repository at this point in the history
  • Loading branch information
euclio committed Jan 12, 2015
1 parent 6d87aba commit 612000b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
37 changes: 21 additions & 16 deletions instant-markdown-d
@@ -1,7 +1,7 @@
#!/bin/sh
':' //; exec "`command -v nodejs || command -v node`" "$0"

var marked = require('marked');
var MarkdownIt = require('markdown-it');
var hljs = require('highlight.js');
var server = require('http').createServer(httpHandler),
exec = require('child_process').exec,
Expand All @@ -10,18 +10,29 @@ var server = require('http').createServer(httpHandler),
server,
socket;

marked.setOptions({
highlight: function(code, lang) {
if (lang) {
return hljs.highlight(lang, code).value;
} else {
return hljs.highlightAuto(code).value;
server.listen(8090);

var md = new MarkdownIt({
html: true,
linkify: true,
highlight: function(str, lang) {
if (lang && hljs.getLanguage(lang)) {
try {
return hljs.highlight(lang, str).value;
} catch (err) {
// Do nothing
}
}

try {
return hljs.highlightAuto(str).value;
} catch (err) {
// Do nothing
}
return '';
}
});

server.listen(8090);

function writeMarkdown(input, output) {
var body = '';
input.on('data', function(data) {
Expand All @@ -31,13 +42,7 @@ function writeMarkdown(input, output) {
}
});
input.on('end', function() {
marked(body, function(err, content) {
if (!err) {
output.emit('newContent', content);
} else {
console.error(err);
}
});
output.emit('newContent', md.render(body));
});
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"github-markdown-css": "^2.0.2",
"highlight.js": "^8.4.0",
"marked": "^0.3.2",
"markdown-it": "^3.0.3",
"send": "~0.1.0",
"socket.io": ""
}
Expand Down

0 comments on commit 612000b

Please sign in to comment.