Skip to content

Commit

Permalink
examples: escape HTML in markdown example
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed May 24, 2016
1 parent fd48bfe commit e3dd191
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions examples/markdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
* Module dependencies.
*/

var escapeHtml = require('escape-html');
var express = require('../..');
var fs = require('fs');
var md = require('marked').parse;
var marked = require('marked');

var app = module.exports = express();

Expand All @@ -13,15 +14,10 @@ var app = module.exports = express();
app.engine('md', function(path, options, fn){
fs.readFile(path, 'utf8', function(err, str){
if (err) return fn(err);
try {
var html = md(str);
html = html.replace(/\{([^}]+)\}/g, function(_, name){
return options[name] || '';
});
fn(null, html);
} catch(err) {
fn(err);
}
var html = marked.parse(str).replace(/\{([^}]+)\}/g, function(_, name){
return escapeHtml(options[name] || '');
});
fn(null, html);
});
});

Expand Down

0 comments on commit e3dd191

Please sign in to comment.