Simplify output of glossary parsing to more simple objects

This commit is contained in:
Aaron O'Mullan
2014-08-15 12:09:36 -07:00
parent e0aed828e0
commit cbe4e9edec
2 changed files with 14 additions and 3 deletions
+8 -3
View File
@@ -28,9 +28,14 @@ function groups(nodes) {
function parseGlossary(src) {
var nodes = kramed.lexer(src);
var entries = groups(nodes);
return entries;
return groups(nodes)
.map(function(pair) {
// Simplify each group to a simple object with name/description
return {
name: pair[0].text,
description: pair[1].text,
};
});
}
module.exports = parseGlossary;
+6
View File
@@ -11,4 +11,10 @@ describe('Glossary parsing', function () {
it('should only get heading + paragraph pairs', function() {
assert.equal(LEXED.length, 5);
});
it('should output simple name/description objects', function() {
assert.equal(true, !(LEXED.some(function(e) {
return !Boolean(e.name && e.description);
})));
});
});