summaryrefslogtreecommitdiffstats
path: root/lib/parse/glossary.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/parse/glossary.js')
-rw-r--r--lib/parse/glossary.js36
1 files changed, 36 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;