mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 01:53:26 +00:00
Simplify output of glossary parsing to more simple objects
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
})));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user