diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-01-21 10:18:15 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-12-22 11:46:14 +0100 |
commit | a81a503ff0bbbf66f6fefb7090f8516071ae817a (patch) | |
tree | 5a255d8453a3c4705083c6a6a4eba2f76fee7acf /packages/gitbook-asciidoc/lib | |
parent | 11893255d1167382b16871d2ca831c90a40af57d (diff) | |
download | gitbook-a81a503ff0bbbf66f6fefb7090f8516071ae817a.zip gitbook-a81a503ff0bbbf66f6fefb7090f8516071ae817a.tar.gz gitbook-a81a503ff0bbbf66f6fefb7090f8516071ae817a.tar.bz2 |
Add base to parse asciidoc
Diffstat (limited to 'packages/gitbook-asciidoc/lib')
-rwxr-xr-x | packages/gitbook-asciidoc/lib/glossary.js | 7 | ||||
-rwxr-xr-x | packages/gitbook-asciidoc/lib/index.js | 8 | ||||
-rwxr-xr-x | packages/gitbook-asciidoc/lib/langs.js | 22 | ||||
-rwxr-xr-x | packages/gitbook-asciidoc/lib/page.js | 17 | ||||
-rwxr-xr-x | packages/gitbook-asciidoc/lib/readme.js | 18 | ||||
-rwxr-xr-x | packages/gitbook-asciidoc/lib/summary.js | 20 | ||||
-rw-r--r-- | packages/gitbook-asciidoc/lib/utils/convert.js | 21 |
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; |