summaryrefslogtreecommitdiffstats
path: root/lib/plugins
diff options
context:
space:
mode:
authorJohan Preynat <johan.preynat@gmail.com>2016-04-18 14:10:17 +0200
committerJohan Preynat <johan.preynat@gmail.com>2016-04-18 14:10:19 +0200
commitc59fc687dbf9cf10222e67295c7d9585f600f523 (patch)
tree3f94589c358f489ac8a01824b1cffd09a02dc5c8 /lib/plugins
parent0791b917f1191861e6320f48be95441102ae9ac7 (diff)
downloadgitbook-c59fc687dbf9cf10222e67295c7d9585f600f523.zip
gitbook-c59fc687dbf9cf10222e67295c7d9585f600f523.tar.gz
gitbook-c59fc687dbf9cf10222e67295c7d9585f600f523.tar.bz2
Ensure plugins compatibility with page.sections
Diffstat (limited to 'lib/plugins')
-rw-r--r--lib/plugins/compatibility.js22
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/plugins/compatibility.js b/lib/plugins/compatibility.js
index eb64e48..8fddba6 100644
--- a/lib/plugins/compatibility.js
+++ b/lib/plugins/compatibility.js
@@ -12,7 +12,12 @@ function pluginCtx(plugin) {
return ctx;
}
-// Call a function "fn" with a context of page similar to the one in GitBook v2
+/*
+ Call a function "fn" with a context of page similar to the one in GitBook v2
+
+ @params {Page}
+ @returns {String|undefined} new content of the page
+*/
function pageHook(page, fn) {
// Get page context
var ctx = page.getContext().page;
@@ -24,19 +29,26 @@ function pageHook(page, fn) {
// Deprecate sections
error.deprecateField(ctx, 'sections', [
- { content: ctx.content }
+ { content: ctx.content, type: 'normal' }
], '"sections" property is deprecated, use page.content instead');
return fn(ctx)
.then(function(result) {
+ // No returned value
+ // Existing content will be used
if (!result) return undefined;
- if (result.content) {
- return result.content;
- }
+ // GitBook 2 compatibility first
+ // Use sections if provided
if (result.sections) {
return _.pluck(result.sections, 'content').join('\n');
}
+
+ // GitBook 3
+ // Use returned page.content
+ if (result.content) {
+ return result.content;
+ }
});
}