summaryrefslogtreecommitdiffstats
path: root/packages/gitbook
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gitbook')
-rw-r--r--packages/gitbook/package.json1
-rw-r--r--packages/gitbook/src/blocks/include.js29
-rw-r--r--packages/gitbook/src/parsers/annotateCodeBlocks.js130
-rw-r--r--packages/gitbook/src/parsers/asciidoc.js10
-rw-r--r--packages/gitbook/src/parsers/markdown.js13
-rw-r--r--packages/gitbook/src/utils/error.js8
6 files changed, 29 insertions, 162 deletions
diff --git a/packages/gitbook/package.json b/packages/gitbook/package.json
index 0ecbf21..b5eed9f 100644
--- a/packages/gitbook/package.json
+++ b/packages/gitbook/package.json
@@ -47,7 +47,6 @@
"mkdirp": "0.5.1",
"moment": "2.13.0",
"npm": "3.10.9",
- "nunjucks": "2.5.2",
"object-path": "^0.9.2",
"omit-keys": "^0.1.0",
"open": "0.0.5",
diff --git a/packages/gitbook/src/blocks/include.js b/packages/gitbook/src/blocks/include.js
new file mode 100644
index 0000000..55cd06e
--- /dev/null
+++ b/packages/gitbook/src/blocks/include.js
@@ -0,0 +1,29 @@
+const Git = require('../utils/git');
+
+/**
+ * Fetch a reference "ref" relative to "file".
+ * @param {Book} book
+ * @param {File} file
+ * @param {String} ref
+ * @return {Promise<Slate.Fragment>}
+ */
+function fetchReference(book, file, ref) {
+
+}
+
+/**
+ * Include another file. It replaces the templating node with content from the other file.
+ *
+ * @param {Slate.Block} node
+ * @return {Promise<List<Block>>}
+ */
+function include(book, file, node) {
+ const ref = node.data.get('props').get(0);
+
+ return fetchReference(book, file, ref)
+ .then((fragment) => {
+
+ });
+}
+
+module.exports = include;
diff --git a/packages/gitbook/src/parsers/annotateCodeBlocks.js b/packages/gitbook/src/parsers/annotateCodeBlocks.js
deleted file mode 100644
index 92ce83a..0000000
--- a/packages/gitbook/src/parsers/annotateCodeBlocks.js
+++ /dev/null
@@ -1,130 +0,0 @@
-const { Block, Text, Inline, INLINES, BLOCKS, MARKS } = require('markup-it');
-
-const RAW_START = 'raw';
-const RAW_END = 'endraw';
-
-/**
- * Create a templating node.
- * @param {String} expr
- * @return {Node}
- */
-function createTemplatingNode(expr) {
- return Inline.create({
- type: INLINES.TEMPLATE,
- data: {
- type: 'expr',
- text: expr
- }
- });
-}
-
-/**
- * Escape a code block.
- * @param {Block} block
- * @return {Array<Node>} blocks
- */
-function escapeCodeBlock(block) {
- return [
- Block.create({
- type: BLOCKS.TEXT,
- nodes: [
- createTemplatingNode(RAW_START)
- ]
- }),
- block,
- Block.create({
- type: BLOCKS.TEXT,
- nodes: [
- createTemplatingNode(RAW_END)
- ]
- })
- ];
-}
-
-
-/**
- * Escape a text node.
- * @param {Text} node
- * @return {Array<Node>} nodes
- */
-function escapeTextNode(node) {
- const ranges = node.getRanges();
-
- const nodes = ranges.reduce((result, range) => {
- const hasCode = range.marks.some(mark => mark.type == MARKS.CODE);
- const text = Text.createFromRanges([ range ]);
-
- if (hasCode) {
- return result.concat([
- createTemplatingNode(RAW_START),
- text,
- createTemplatingNode(RAW_END)
- ]);
- }
-
- return result.concat([ text ]);
- }, []);
-
- return nodes;
-}
-
-/**
- * Annotate a block container.
- * @param {Node} parent
- * @param {Number} levelRaw
- * @return {Node} node
- * @return {Number} levelRaw
- */
-function annotateNode(parent, levelRaw) {
- let { nodes } = parent;
-
- nodes = nodes.reduce((out, node) => {
- if (node.type === INLINES.TEMPLATE) {
- const { type, text } = node.data.toJS();
-
- if (type === 'expr') {
- if (text === 'raw') {
- levelRaw = levelRaw + 1;
- } else if (text == 'endraw') {
- levelRaw = 0;
- }
- }
-
- return out.concat([ node ]);
- }
-
- else if (node.type === BLOCKS.CODE) {
- return out.concat(
- levelRaw == 0 ? escapeCodeBlock(node) : [ node ]
- );
- }
-
- else if (node.kind == 'text') {
- return out.concat(
- levelRaw == 0 ? escapeTextNode(node) : [ node ]
- );
- }
-
- const result = annotateNode(node, levelRaw);
- levelRaw = result.levelRaw;
- return out.concat([result.node]);
- }, []);
-
- return {
- levelRaw,
- node: parent.merge({ nodes })
- };
-}
-
-/**
- * Add templating "raw" to code blocks to
- * avoid nunjucks processing their content.
- *
- * @param {Document} document
- * @return {Document}
- */
-function annotateCodeBlocks(document) {
- return annotateNode(document, 0).node;
-}
-
-module.exports = annotateCodeBlocks;
diff --git a/packages/gitbook/src/parsers/asciidoc.js b/packages/gitbook/src/parsers/asciidoc.js
index 7425f65..830a834 100644
--- a/packages/gitbook/src/parsers/asciidoc.js
+++ b/packages/gitbook/src/parsers/asciidoc.js
@@ -41,15 +41,6 @@ function toHTML(text) {
}
/**
- * Prepare a document for parsing
- * @param {String} text
- * @return {String} text
- */
-function prepare(text) {
- return text;
-}
-
-/**
* Render asciidoc to inline HTML.
* @param {String} text
* @return {String} html
@@ -64,7 +55,6 @@ function toInlineHTML(text) {
module.exports = {
name: 'asciidoc',
FILE_EXTENSIONS,
- prepare,
toDocument,
toText,
toHTML,
diff --git a/packages/gitbook/src/parsers/markdown.js b/packages/gitbook/src/parsers/markdown.js
index e110eb7..1dff741 100644
--- a/packages/gitbook/src/parsers/markdown.js
+++ b/packages/gitbook/src/parsers/markdown.js
@@ -1,7 +1,6 @@
const { State } = require('markup-it');
const markdown = require('markup-it/lib/markdown');
const html = require('markup-it/lib/html');
-const annotateCodeBlocks = require('./annotateCodeBlocks');
const FILE_EXTENSIONS = [
'.md',
@@ -30,17 +29,6 @@ function toDocument(text) {
}
/**
- * Prepare a document for parsing
- * @param {String} text
- * @return {String} text
- */
-function prepare(text) {
- let doc = toDocument(text);
- doc = annotateCodeBlocks(doc);
- return toText(doc);
-}
-
-/**
* Render markdown to HTML.
* @param {String} text
* @return {String} html
@@ -67,7 +55,6 @@ function toInlineHTML(text) {
module.exports = {
name: 'markdown',
FILE_EXTENSIONS,
- prepare,
toText,
toDocument,
toHTML,
diff --git a/packages/gitbook/src/utils/error.js b/packages/gitbook/src/utils/error.js
index 925b5ff..2d65b17 100644
--- a/packages/gitbook/src/utils/error.js
+++ b/packages/gitbook/src/utils/error.js
@@ -55,13 +55,6 @@ const RequireInstallError = TypedError({
});
// Error for nunjucks templates
-const TemplateError = WrappedError({
- message: 'Error compiling template "{filename}": {origMessage}',
- type: 'template',
- filename: null
-});
-
-// Error for nunjucks templates
const PluginError = WrappedError({
message: 'Error with plugin "{plugin}": {origMessage}',
type: 'plugin',
@@ -92,7 +85,6 @@ module.exports = {
FileNotFoundError,
FileOutOfScopeError,
- TemplateError,
PluginError,
ConfigurationError,
EbookError