summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-asciidoc/lib/summary.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-20 15:31:29 +0100
committerSamy Pessé <samypesse@gmail.com>2016-12-22 11:46:22 +0100
commit147679a42257660d70a9ef6ac6216fabf1d67582 (patch)
tree4dfd4a809c8351b9eea4ebfcc222878a30bec0ad /packages/gitbook-asciidoc/lib/summary.js
parentd7b5c6a14d823cd067c7309240326d18a495674a (diff)
downloadgitbook-147679a42257660d70a9ef6ac6216fabf1d67582.zip
gitbook-147679a42257660d70a9ef6ac6216fabf1d67582.tar.gz
gitbook-147679a42257660d70a9ef6ac6216fabf1d67582.tar.bz2
Use gitbook-html as base parser
Diffstat (limited to 'packages/gitbook-asciidoc/lib/summary.js')
-rwxr-xr-xpackages/gitbook-asciidoc/lib/summary.js83
1 files changed, 0 insertions, 83 deletions
diff --git a/packages/gitbook-asciidoc/lib/summary.js b/packages/gitbook-asciidoc/lib/summary.js
deleted file mode 100755
index 2c9ada0..0000000
--- a/packages/gitbook-asciidoc/lib/summary.js
+++ /dev/null
@@ -1,83 +0,0 @@
-var _ = require('lodash');
-var cheerio = require('cheerio');
-
-var convert = require('./utils/convert');
-
-
-// parse a ul list and return list of chapters recursvely
-function parseList($ul, $) {
- var articles = [];
-
- $ul.children("li").each(function() {
- var article = {};
-
- var $li = $(this);
- var $p = $li.children("p");
-
- article.title = $p.text();
-
- // Parse link
- var $a = $p.children("a");
- if ($a.length > 0) {
- article.title = $a.first().text();
- article.path = $a.attr("href").replace(/\\/g, '/').replace(/^\/+/, '')
- }
-
- // Sub articles
- var $sub = $li.children(".olist").children("ol");
- article.articles = parseList($sub, $);
-
- articles.push(article);
- });
-
- return articles;
-}
-
-function parseSummary(src) {
- var chapters = parseEntries(src);
-
- return {
- chapters: chapters
- };
-}
-
-function parseEntries (src) {
- var html = convert(src);
- var $ = cheerio.load(html);
-
- var chapters = parseList($("ol").first(), $);
- return chapters;
-}
-
-function summaryToText(summary) {
- var bl = "\n";
- var content = "= Summary"+bl+bl;
-
- var _base = function(article) {
- if (article.path) {
- return "link:"+article.path+"["+article.title+"]";
- } else {
- return article.title;
- }
- };
-
- var convertArticle = function(article, d) {
- content = content + Array(d+2).join(".") + " " + _base(article)+bl;
- _.each(article.articles, function(_article) {
- convertArticle(_article, d + 1);
- });
- };
-
- _.each(summary.chapters, function(chapter) {
- convertArticle(chapter, 0);
- });
-
- content = content+bl;
-
- return content;
-};
-
-
-module.exports = parseSummary;
-module.exports.entries = parseEntries;
-module.exports.toText = summaryToText;