summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-html/src/glossary.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gitbook-html/src/glossary.js')
-rwxr-xr-xpackages/gitbook-html/src/glossary.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/packages/gitbook-html/src/glossary.js b/packages/gitbook-html/src/glossary.js
new file mode 100755
index 0000000..a4269fe
--- /dev/null
+++ b/packages/gitbook-html/src/glossary.js
@@ -0,0 +1,30 @@
+const dom = require('./dom');
+
+/**
+ * Parse an HTML content into a list of glossary entry.
+ *
+ * @param {String} html
+ * @return {Array} entries
+ */
+function parseGlossary(html) {
+ const $ = dom.parse(html);
+
+ const entries = [];
+
+ $('h2').each(function() {
+ const $heading = $(this);
+ const $next = $heading.next();
+ const $p = $next.is('p') ? $next.first() : $next.find('p').first();
+
+ const entry = {};
+
+ entry.name = $heading.text();
+ entry.description = $p.text();
+
+ entries.push(entry);
+ });
+
+ return entries;
+}
+
+module.exports = parseGlossary;