diff options
author | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-08-11 18:57:39 -0700 |
---|---|---|
committer | Aaron O'Mullan <aaron.omullan@friendco.de> | 2014-08-11 18:57:39 -0700 |
commit | 323facbdc8beea33179c7167e4ab4e8d7fe3eb98 (patch) | |
tree | 8b0ab8e7fa485f0949de420ffcbb7d45ec3001a7 /lib/parse | |
parent | 2a61c858e47c43891f5c6515b013f429f836e36f (diff) | |
download | gitbook-323facbdc8beea33179c7167e4ab4e8d7fe3eb98.zip gitbook-323facbdc8beea33179c7167e4ab4e8d7fe3eb98.tar.gz gitbook-323facbdc8beea33179c7167e4ab4e8d7fe3eb98.tar.bz2 |
Add glossary parser
Diffstat (limited to 'lib/parse')
-rw-r--r-- | lib/parse/glossary.js | 36 | ||||
-rw-r--r-- | lib/parse/index.js | 1 |
2 files changed, 37 insertions, 0 deletions
diff --git a/lib/parse/glossary.js b/lib/parse/glossary.js new file mode 100644 index 0000000..65473cf --- /dev/null +++ b/lib/parse/glossary.js @@ -0,0 +1,36 @@ +var _ = require('lodash'); +var kramed = require('kramed'); + +// Get all the pairs of header + paragraph in a list of nodes +function groups(nodes) { + // A list of next nodes + var next = nodes.slice(1).concat(null); + + return _.reduce(nodes, function(accu, node, idx) { + // Skip + if(!( + node.type === 'heading' && + (next[idx] && next[idx].type === 'paragraph') + )) { + return accu; + } + + // Add group + accu.push([ + node, + next[idx] + ]); + + return accu; + }, []); +} + +function parseGlossary(src) { + var nodes = kramed.lexer(src); + + var entries = groups(nodes); + + return entries; +} + +module.exports = parseGlossary; diff --git a/lib/parse/index.js b/lib/parse/index.js index 0ebb03a..c8c15e6 100644 --- a/lib/parse/index.js +++ b/lib/parse/index.js @@ -1,5 +1,6 @@ module.exports = { summary: require('./summary'), + glossary: require('./glossary'), langs: require('./langs'), page: require('./page'), lex: require('./lex'), |