From cbe4e9edec3a1751030ad40a28e25df20fde2b08 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Fri, 15 Aug 2014 12:09:36 -0700 Subject: [PATCH] Simplify output of glossary parsing to more simple objects --- lib/parse/glossary.js | 11 ++++++++--- test/glossary.js | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/parse/glossary.js b/lib/parse/glossary.js index 65473cf03..6286783bd 100644 --- a/lib/parse/glossary.js +++ b/lib/parse/glossary.js @@ -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; diff --git a/test/glossary.js b/test/glossary.js index c60fa4557..bf40e162b 100644 --- a/test/glossary.js +++ b/test/glossary.js @@ -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); + }))); + }); });