summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-html/lib/summary.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-20 15:30:27 +0100
committerSamy Pessé <samypesse@gmail.com>2016-12-22 12:32:14 +0100
commitc1c17a273ae45c653a0c7d2cc64fabbb5b42e224 (patch)
tree526eff188d5799762191b46d2dfb8009b6c57398 /packages/gitbook-html/lib/summary.js
parent21fe8961d7ac91a49c49c28052fc2de4f251f409 (diff)
downloadgitbook-c1c17a273ae45c653a0c7d2cc64fabbb5b42e224.zip
gitbook-c1c17a273ae45c653a0c7d2cc64fabbb5b42e224.tar.gz
gitbook-c1c17a273ae45c653a0c7d2cc64fabbb5b42e224.tar.bz2
Improve gitbook -> text
Diffstat (limited to 'packages/gitbook-html/lib/summary.js')
-rwxr-xr-xpackages/gitbook-html/lib/summary.js51
1 files changed, 2 insertions, 49 deletions
diff --git a/packages/gitbook-html/lib/summary.js b/packages/gitbook-html/lib/summary.js
index 607062e..9b6b688 100755
--- a/packages/gitbook-html/lib/summary.js
+++ b/packages/gitbook-html/lib/summary.js
@@ -24,7 +24,7 @@ function parseList($ul, $) {
// Get text for the entry
var $p = $li.children('p');
- article.title = $p.text() || dom.textNode($li.get(0));
+ article.title = ($p.text() || dom.textNode($li.get(0))).trim();
// Parse link
var $a = $li.find(SELECTOR_LINK);
@@ -37,6 +37,7 @@ function parseList($ul, $) {
var $sub = findList($li);
article.articles = parseList($sub, $);
+ if (!article.title) return;
articles.push(article);
});
@@ -64,52 +65,4 @@ function parseSummary(html) {
};
}
-// Summary -> HTML
-function textPrefix(d) {
- return Array(d*4).join(' ');
-}
-
-function articleToText(article, d) {
- var prefix = textPrefix(d);
- var content = prefix + '<li>';
-
- if (article.path) {
- content += '<a href="'+article.path+'">'+article.title+'</a>';
- } else {
- content += article.title;
- }
-
- if (article.articles.length > 0) {
- content += BL + articlesToText(article.articles, d) + prefix;
- }
- content += '</li>' + BL;
-
- return content;
-}
-
-function articlesToText(articles, d) {
- var prefix = textPrefix(d);
- var content = prefix + '<ul>' + BL;
- _.each(articles, function(_article) {
- content += articleToText(_article, d + 1);
- });
- return content + '</ul>' + BL;
-}
-
-function partsToText(part) {
- return articlesToText(part.articles, 0) + BL + BL;
-}
-
-function summaryToText(summary) {
- var content = '<h1>Summary</h1>' + BL;
-
- _.each(summary.parts, function(part) {
- content += partsToText(part);
- });
-
- return content + BL;
-};
-
-
module.exports = parseSummary;
-module.exports.toText = summaryToText;