Strip tags from shortdesc (et al.) when parsing

This strips markup from elements with id attributes that we care about: title, shortdesc, tags.  This will only work for people who use `npm install && npm start` to browse examples.  The other example parser doesn't strip this markup, so it should still not be used in these elements.
This commit is contained in:
Tim Schaub
2014-04-04 10:00:23 -06:00
parent 2a4300085e
commit 6fc915ba7b
+10 -6
View File
@@ -49,21 +49,25 @@ function parseExamples(examplePaths, callback) {
tags: '' tags: ''
}; };
var key; var key;
var openTag;
var parser = new Parser({ var parser = new Parser({
onopentag: function(name, attrs) { onopentag: function(tag, attrs) {
if (attrs.id in info) { if (attrs.id in info) {
key = attrs.id; key = attrs.id;
} else { openTag = tag;
key = undefined;
} }
}, },
ontext: function(text) { ontext: function(text) {
if (key) { if (key) {
info[key] = text.replace(/\n/g, '').trim(); info[key] += text.replace(/\n/g, '').trim() + ' ';
} }
}, },
onclosetag: function(name) { onclosetag: function(tag) {
key = undefined; if (tag === openTag) {
info[key] = info[key].trim();
key = undefined;
openTag = undefined;
}
}, },
onerror: function(err2) { onerror: function(err2) {
var message = 'Trouble parsing ' + examplePath + '\n' + err2.message; var message = 'Trouble parsing ' + examplePath + '\n' + err2.message;