summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-asciidoc/lib
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gitbook-asciidoc/lib')
-rwxr-xr-xpackages/gitbook-asciidoc/lib/glossary.js7
-rwxr-xr-xpackages/gitbook-asciidoc/lib/index.js8
-rwxr-xr-xpackages/gitbook-asciidoc/lib/langs.js22
-rwxr-xr-xpackages/gitbook-asciidoc/lib/page.js17
-rwxr-xr-xpackages/gitbook-asciidoc/lib/readme.js18
-rwxr-xr-xpackages/gitbook-asciidoc/lib/summary.js20
-rw-r--r--packages/gitbook-asciidoc/lib/utils/convert.js21
7 files changed, 113 insertions, 0 deletions
diff --git a/packages/gitbook-asciidoc/lib/glossary.js b/packages/gitbook-asciidoc/lib/glossary.js
new file mode 100755
index 0000000..dec645d
--- /dev/null
+++ b/packages/gitbook-asciidoc/lib/glossary.js
@@ -0,0 +1,7 @@
+var _ = require('lodash');
+
+function parseGlossary(src) {
+ return [];
+}
+
+module.exports = parseGlossary;
diff --git a/packages/gitbook-asciidoc/lib/index.js b/packages/gitbook-asciidoc/lib/index.js
new file mode 100755
index 0000000..ac8339a
--- /dev/null
+++ b/packages/gitbook-asciidoc/lib/index.js
@@ -0,0 +1,8 @@
+
+module.exports = {
+ summary: require("./summary"),
+ glossary: require("./glossary"),
+ langs: require("./langs"),
+ readme: require("./readme"),
+ page: require("./page")
+};
diff --git a/packages/gitbook-asciidoc/lib/langs.js b/packages/gitbook-asciidoc/lib/langs.js
new file mode 100755
index 0000000..86da75a
--- /dev/null
+++ b/packages/gitbook-asciidoc/lib/langs.js
@@ -0,0 +1,22 @@
+var _ = require("lodash");
+var parseEntries = require("./summary").entries;
+
+
+var parseLangs = function(content) {
+ var entries = parseEntries(content);
+
+ return _.chain(entries)
+ .filter(function(entry) {
+ return Boolean(entry.path);
+ })
+ .map(function(entry) {
+ return {
+ title: entry.title,
+ path: entry.path,
+ lang: entry.path.replace("/", "")
+ };
+ })
+ .value();
+};
+
+module.exports = parseLangs;
diff --git a/packages/gitbook-asciidoc/lib/page.js b/packages/gitbook-asciidoc/lib/page.js
new file mode 100755
index 0000000..2bcfe61
--- /dev/null
+++ b/packages/gitbook-asciidoc/lib/page.js
@@ -0,0 +1,17 @@
+var Q = require('q');
+var _ = require('lodash');
+
+var convert = require('./utils/convert');
+
+function parsePage(src) {
+ return {
+ sections: [
+ {
+ type: "normal",
+ content: convert(src)
+ }
+ ]
+ };
+}
+
+module.exports = parsePage;
diff --git a/packages/gitbook-asciidoc/lib/readme.js b/packages/gitbook-asciidoc/lib/readme.js
new file mode 100755
index 0000000..6ca1a83
--- /dev/null
+++ b/packages/gitbook-asciidoc/lib/readme.js
@@ -0,0 +1,18 @@
+var _ = require('lodash');
+var cheerio = require('cheerio');
+
+var convert = require('./utils/convert');
+
+function parseReadme(src) {
+ var html = convert(src);
+ $ = cheerio.load(html);
+
+ return {
+ title: $("h1:first-child").text().trim(),
+ description: $("div.paragraph").first().text().trim()
+ };
+}
+
+
+// Exports
+module.exports = parseReadme;
diff --git a/packages/gitbook-asciidoc/lib/summary.js b/packages/gitbook-asciidoc/lib/summary.js
new file mode 100755
index 0000000..67e11f3
--- /dev/null
+++ b/packages/gitbook-asciidoc/lib/summary.js
@@ -0,0 +1,20 @@
+var _ = require('lodash');
+var cheerio = require('cheerio');
+
+var convert = require('./utils/convert');
+
+function parseSummary(src, entryPoint) {
+ var html = convert(src);
+ $ = cheerio.load(html);
+ console.log(html);
+ return [];
+}
+
+function parseEntries (src) {
+ return [];
+}
+
+
+// Exports
+module.exports = parseSummary;
+module.exports.entries = parseEntries;
diff --git a/packages/gitbook-asciidoc/lib/utils/convert.js b/packages/gitbook-asciidoc/lib/utils/convert.js
new file mode 100644
index 0000000..8a19638
--- /dev/null
+++ b/packages/gitbook-asciidoc/lib/utils/convert.js
@@ -0,0 +1,21 @@
+var asciidoctor = require('asciidoctor.js')();
+var opal = asciidoctor.Opal;
+
+var processor = null;
+var useExtensions = true;
+
+if (useExtensions) {
+ processor = asciidoctor.Asciidoctor(true);
+} else {
+ processor = asciidoctor.Asciidoctor();
+}
+
+
+var convert = function(content) {
+ var options = opal.hash2(['attributes'], {'attributes': 'showtitle'});
+
+ var html = processor.$convert(content, options);
+ return html;
+};
+
+module.exports = convert;