From 0d70ce2ac7eddb355d00be5954e470ce20b766dc Mon Sep 17 00:00:00 2001 From: Open Close Date: Sun, 23 Jun 2019 12:06:49 +0800 Subject: [PATCH 01/18] Implement importing of variables from other files Syntax introduced: If varname1, varname2... attributes are specified, the respective variables from filename.md can be used as variables in the current page normally: {{varname1}} {{varname2}}. If attribute 'as' is specified, ALL page variables from filename.md can be accessed through the namespace specified in the attribute: {{namespace.varname3}}, {{namespace.varname4}} In extractPageVariables, we store all non-imported page variables into a global lookup table. Also we detect what variables are imported ones, and let nunjucks replace them with themselves first. In the above example, {{namespace.varname1}} would be replaced with {{namespace.varname1}} in the first nunjucks call in includeFile after extractPageVariables. After this, and before _preprocess, a new preprocessing step is introduced that extracts the imported variables, after which another nunjucks call is made so that the imported variables can be rendered correctly. --- src/lib/markbind/src/parser.js | 145 +++++++++++++++++++++++++++++---- 1 file changed, 129 insertions(+), 16 deletions(-) diff --git a/src/lib/markbind/src/parser.js b/src/lib/markbind/src/parser.js index 27fd725657..c78df6ba28 100644 --- a/src/lib/markbind/src/parser.js +++ b/src/lib/markbind/src/parser.js @@ -27,6 +27,10 @@ const ATTRIB_CWF = 'cwf'; const BOILERPLATE_FOLDER_NAME = '_markbind/boilerplates'; +const VARIABLE_LOOKUP = new Map(); +const FILE_ALIASES = new Map(); +const PROCESSED_INNER_VARIABLES = new Set(); + /* * Utils */ @@ -123,6 +127,18 @@ function extractIncludeVariables(includeElement, contextVariables) { return includedVariables; } +function getImportedVariableMap(file) { + const innerVariables = {}; + FILE_ALIASES.get(file).forEach((path, alias) => { + innerVariables[alias] = {}; + const variables = VARIABLE_LOOKUP.get(path); + variables.forEach((value, name) => { + innerVariables[alias][name] = value; + }); + }); + return innerVariables; +} + /** * Extract page variables from a page * @param filename for error printing @@ -133,6 +149,25 @@ function extractIncludeVariables(includeElement, contextVariables) { function extractPageVariables(fileName, data, userDefinedVariables, includedVariables) { const $ = cheerio.load(data); const pageVariables = { }; + VARIABLE_LOOKUP.set(fileName, new Map()); + /** + * ed variables have not been processed yet, we replace such variables with itself first. + */ + $('import[from]').each((index, element) => { + const variableNames = Object.keys(element.attribs) + .filter(name => name !== 'from' && name !== 'as'); + // If no namespace is provided, we use the smallest name as one + const largestName = variableNames.sort()[0]; + const alias = _.hasIn(element.attribs, 'as') + ? element.attribs['as'] + : largestName; + pageVariables[alias] = new Proxy({}, { + get(obj, prop) { + return `{{${alias}.${prop}}}`; + }, + }); + variableNames.forEach(name => pageVariables[name] = `{{${alias}.${name}}}`); + }); $('variable').each(function () { const variableElement = $(this); const variableName = variableElement.attr('name'); @@ -142,9 +177,11 @@ function extractPageVariables(fileName, data, userDefinedVariables, includedVari return; } if (!pageVariables[variableName]) { - pageVariables[variableName] + const variableValue = nunjucks.renderString(md.renderInline(variableElement.html()), { ...pageVariables, ...userDefinedVariables, ...includedVariables }); + pageVariables[variableName] = variableValue; + VARIABLE_LOOKUP.get(fileName).set(variableName, variableValue); } }); return pageVariables; @@ -181,6 +218,73 @@ Parser.prototype._preprocessThumbnails = function (element) { return element; }; +Parser.prototype._prepreprocessInnerVariables = function (content, context, config) { + const { cwf } = context; + const $ = cheerio.load(content, { + xmlMode: false, + decodeEntities: false, + }); + const self = this; + const aliases = new Map(); + FILE_ALIASES.set(cwf, aliases); + $('import[from]').each((index, element) => { + const filePath = path.resolve(path.dirname(cwf), element.attribs.from); + const variableNames = Object.keys(element.attribs) + .filter(name => name !== 'from' && name !== 'as'); + // If no namespace is provided, we use the smallest name as one + const largestName = variableNames.sort()[0]; + const alias = _.hasIn(element.attribs, 'as') + ? element.attribs['as'] + : largestName; + + aliases.set(alias, filePath); + try { + self._fileCache[filePath] = self._fileCache[filePath] + ? self._fileCache[filePath] : fs.readFileSync(filePath, 'utf8'); + } catch (e) { + // Read file fail + const missingReferenceErrorMessage = `Missing reference in: ${element.attribs[ATTRIB_CWF]}`; + e.message += `\n${missingReferenceErrorMessage}`; + self._onError(e); + } + + let innerFileContent = self._fileCache[filePath]; // cache the file contents to save some I/O + const { parent, relative } = calculateNewBaseUrls(filePath, config.rootPath, config.baseUrlMap); + const userDefinedVariables = config.userDefinedVariablesMap[path.resolve(parent, relative)]; + + // Extract included variables from the PARENT file + const includeVariables = extractIncludeVariables(element, context.variables); + + // Extract page variables from the CHILD filere + const pageVariables = extractPageVariables(filePath, innerFileContent, + userDefinedVariables, includeVariables); + + // Render inner file content + innerFileContent = nunjucks.renderString(innerFileContent, + { + ...pageVariables, + ...includeVariables, + ...userDefinedVariables, + }, + { path: filePath }); + const childContext = _.cloneDeep(context); + childContext.cwf = filePath; + childContext.variables = includeVariables; + if (!PROCESSED_INNER_VARIABLES.has(filePath)) { + PROCESSED_INNER_VARIABLES.add(filePath); + this._prepreprocessInnerVariables(innerFileContent, childContext, config); + } + const innerVariables = getImportedVariableMap(filePath); + VARIABLE_LOOKUP.get(filePath).forEach((value, variableName, map) => { + map.set(variableName, nunjucks.renderString(value, { + ...userDefinedVariables, + ...pageVariables, + ...innerVariables, + })); + }); + }); +}; + Parser.prototype._preprocess = function (node, context, config) { const element = node; const self = this; @@ -290,13 +394,26 @@ Parser.prototype._preprocess = function (node, context, config) { const includeVariables = extractIncludeVariables(element, context.variables); // Extract page variables from the CHILD file - const pageVariables = extractPageVariables(element.attribs.src, fileContent, + const pageVariables = extractPageVariables(filePath, fileContent, userDefinedVariables, includeVariables); // Render inner file content fileContent = nunjucks.renderString(fileContent, { ...pageVariables, ...includeVariables, ...userDefinedVariables }, { path: actualFilePath }); + // The element's children are in the new context + // Process with new context + const childContext = _.cloneDeep(context); + childContext.cwf = filePath; + childContext.source = isIncludeSrcMd ? 'md' : 'html'; + childContext.callStack.push(context.cwf); + childContext.variables = includeVariables; + if (!PROCESSED_INNER_VARIABLES.has(filePath)) { + PROCESSED_INNER_VARIABLES.add(filePath); + this._prepreprocessInnerVariables(fileContent, childContext, config); + } + const innerVariables = getImportedVariableMap(filePath); + fileContent = nunjucks.renderString(fileContent, { ...userDefinedVariables, ...innerVariables }); // Delete variable attributes in include Object.keys(element.attribs).forEach((attribute) => { @@ -365,14 +482,6 @@ Parser.prototype._preprocess = function (node, context, config) { ); } - // The element's children are in the new context - // Process with new context - const childContext = _.cloneDeep(context); - childContext.cwf = filePath; - childContext.source = isIncludeSrcMd ? 'md' : 'html'; - childContext.callStack.push(context.cwf); - childContext.variables = includeVariables; - if (element.children && element.children.length > 0) { if (childContext.callStack.length > CyclicReferenceError.MAX_RECURSIVE_DEPTH) { const error = new CyclicReferenceError(childContext.callStack); @@ -388,7 +497,7 @@ Parser.prototype._preprocess = function (node, context, config) { element.attribs.src = filePath; this.dynamicIncludeSrc.push({ from: context.cwf, to: actualFilePath, asIfTo: filePath }); return element; - } else if (element.name === 'variable') { + } else if (element.name === 'variable' || element.name === 'import') { return createEmptyNode(); } else { if (element.name === 'body') { @@ -566,7 +675,7 @@ Parser.prototype.includeFile = function (file, config) { try { processed = this._preprocess(d, context, config); } catch (err) { - err.message += `\nError while preprocessing '${file}'`; + err.message += `${err.stack}\nError while preprocessing '${file}'`; this._onError(err); processed = createErrorNode(d, err); } @@ -596,10 +705,14 @@ Parser.prototype.includeFile = function (file, config) { } const { parent, relative } = calculateNewBaseUrls(file, config.rootPath, config.baseUrlMap); const userDefinedVariables = config.userDefinedVariablesMap[path.resolve(parent, relative)]; - const pageVariables = extractPageVariables(path.basename(file), data, userDefinedVariables, {}); - const fileContent = nunjucks.renderString(data, - { ...pageVariables, ...userDefinedVariables }, - { path: actualFilePath }); + const pageVariables = extractPageVariables(file, data, userDefinedVariables, {}); + + let fileContent = nunjucks.renderString(data, + { ...pageVariables, ...userDefinedVariables }, + { path: actualFilePath }); + this._prepreprocessInnerVariables(fileContent, context, config); + const innerVariables = getImportedVariableMap(context.cwf); + fileContent = nunjucks.renderString(fileContent, { ...userDefinedVariables, ...innerVariables }); const fileExt = utils.getExt(file); if (utils.isMarkdownFileExt(fileExt)) { context.source = 'md'; From 3c5831ee5b75b278e059cd11a0229ea3d56b3b08 Mon Sep 17 00:00:00 2001 From: Open Close Date: Tue, 25 Jun 2019 11:41:18 +0800 Subject: [PATCH 02/18] Add demos to docs site for easy showcase of how import works --- docs/site.json | 3 +++ docs/testing/child.md | 3 +++ docs/testing/morevariablestoimport.md | 1 + docs/testing/testimportvariables.md | 11 +++++++++++ docs/testing/usecaseincomment.md | 11 +++++++++++ docs/testing/variablestoimport.md | 17 +++++++++++++++++ 6 files changed, 46 insertions(+) create mode 100644 docs/testing/child.md create mode 100644 docs/testing/morevariablestoimport.md create mode 100644 docs/testing/testimportvariables.md create mode 100644 docs/testing/usecaseincomment.md create mode 100644 docs/testing/variablestoimport.md diff --git a/docs/site.json b/docs/site.json index 91ab123fe4..b117787993 100644 --- a/docs/site.json +++ b/docs/site.json @@ -15,6 +15,9 @@ { "glob": "userGuide/*.md" }, + { + "glob": "testing/*.md" + }, { "src": "userGuide/fullSyntaxReference.md", "searchable": "no" diff --git a/docs/testing/child.md b/docs/testing/child.md new file mode 100644 index 0000000000..fa04489a26 --- /dev/null +++ b/docs/testing/child.md @@ -0,0 +1,3 @@ +Title +testimportvariables.md +testimportvariables \ No newline at end of file diff --git a/docs/testing/morevariablestoimport.md b/docs/testing/morevariablestoimport.md new file mode 100644 index 0000000000..a81d2f3efe --- /dev/null +++ b/docs/testing/morevariablestoimport.md @@ -0,0 +1 @@ + This is a deeply imported variable \ No newline at end of file diff --git a/docs/testing/testimportvariables.md b/docs/testing/testimportvariables.md new file mode 100644 index 0000000000..e99537bf64 --- /dev/null +++ b/docs/testing/testimportvariables.md @@ -0,0 +1,11 @@ +variablestoimport + +Making sure the issue here https://github.com/MarkBind/markbind/commit/48b57a18a8bfd68101b163908da4a0541756364a is fixed. + + + +Test import variables from src specified via variable: +{{var}} + +Test import variables that itself imports other variables: +{{deepvar}} \ No newline at end of file diff --git a/docs/testing/usecaseincomment.md b/docs/testing/usecaseincomment.md new file mode 100644 index 0000000000..4fb2782a63 --- /dev/null +++ b/docs/testing/usecaseincomment.md @@ -0,0 +1,11 @@ +Refer to this comment: https://github.com/MarkBind/markbind/pull/751#issuecomment-469670640 + + +{{ child.title }} + + +## Below panel is working + + +## Below should be a panel, but is now an error. + \ No newline at end of file diff --git a/docs/testing/variablestoimport.md b/docs/testing/variablestoimport.md new file mode 100644 index 0000000000..25b973bf10 --- /dev/null +++ b/docs/testing/variablestoimport.md @@ -0,0 +1,17 @@ +This variable comes from variablesToImport.md + +This is a page variable from variablestoimport.md + + + + +## Trying to access a page variable: +There should be something red below: +
{{pagevar}}
+Something should have appeared above in red. + +## @#$@$ Trying to access an imported variable via namespace: +There should be something blue below: +
{{namespace.variable}}
+Something should have appeared above in blue. +
\ No newline at end of file From b82da4a305b34894285024f12041d65147f99466 Mon Sep 17 00:00:00 2001 From: Open Close Date: Tue, 25 Jun 2019 11:44:01 +0800 Subject: [PATCH 03/18] Lint --- src/lib/markbind/src/parser.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lib/markbind/src/parser.js b/src/lib/markbind/src/parser.js index c78df6ba28..7180860fc4 100644 --- a/src/lib/markbind/src/parser.js +++ b/src/lib/markbind/src/parser.js @@ -129,9 +129,9 @@ function extractIncludeVariables(includeElement, contextVariables) { function getImportedVariableMap(file) { const innerVariables = {}; - FILE_ALIASES.get(file).forEach((path, alias) => { + FILE_ALIASES.get(file).forEach((actualPath, alias) => { innerVariables[alias] = {}; - const variables = VARIABLE_LOOKUP.get(path); + const variables = VARIABLE_LOOKUP.get(actualPath); variables.forEach((value, name) => { innerVariables[alias][name] = value; }); @@ -159,14 +159,16 @@ function extractPageVariables(fileName, data, userDefinedVariables, includedVari // If no namespace is provided, we use the smallest name as one const largestName = variableNames.sort()[0]; const alias = _.hasIn(element.attribs, 'as') - ? element.attribs['as'] + ? element.attribs.as : largestName; pageVariables[alias] = new Proxy({}, { get(obj, prop) { return `{{${alias}.${prop}}}`; }, }); - variableNames.forEach(name => pageVariables[name] = `{{${alias}.${name}}}`); + variableNames.forEach((name) => { + pageVariables[name] = `{{${alias}.${name}}}`; + }); }); $('variable').each(function () { const variableElement = $(this); @@ -234,7 +236,7 @@ Parser.prototype._prepreprocessInnerVariables = function (content, context, conf // If no namespace is provided, we use the smallest name as one const largestName = variableNames.sort()[0]; const alias = _.hasIn(element.attribs, 'as') - ? element.attribs['as'] + ? element.attribs.as : largestName; aliases.set(alias, filePath); From 9ddae9af858241a2ad0d8212eb5c5e72ffc8789f Mon Sep 17 00:00:00 2001 From: Open Close Date: Mon, 8 Jul 2019 10:16:57 +0800 Subject: [PATCH 04/18] Rename function to extractInnerVariables --- src/lib/markbind/src/parser.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/markbind/src/parser.js b/src/lib/markbind/src/parser.js index 7180860fc4..eeb45b473b 100644 --- a/src/lib/markbind/src/parser.js +++ b/src/lib/markbind/src/parser.js @@ -220,7 +220,7 @@ Parser.prototype._preprocessThumbnails = function (element) { return element; }; -Parser.prototype._prepreprocessInnerVariables = function (content, context, config) { +Parser.prototype._extractInnerVariables = function (content, context, config) { const { cwf } = context; const $ = cheerio.load(content, { xmlMode: false, @@ -274,7 +274,7 @@ Parser.prototype._prepreprocessInnerVariables = function (content, context, conf childContext.variables = includeVariables; if (!PROCESSED_INNER_VARIABLES.has(filePath)) { PROCESSED_INNER_VARIABLES.add(filePath); - this._prepreprocessInnerVariables(innerFileContent, childContext, config); + this._extractInnerVariables(innerFileContent, childContext, config); } const innerVariables = getImportedVariableMap(filePath); VARIABLE_LOOKUP.get(filePath).forEach((value, variableName, map) => { @@ -412,7 +412,7 @@ Parser.prototype._preprocess = function (node, context, config) { childContext.variables = includeVariables; if (!PROCESSED_INNER_VARIABLES.has(filePath)) { PROCESSED_INNER_VARIABLES.add(filePath); - this._prepreprocessInnerVariables(fileContent, childContext, config); + this._extractInnerVariables(fileContent, childContext, config); } const innerVariables = getImportedVariableMap(filePath); fileContent = nunjucks.renderString(fileContent, { ...userDefinedVariables, ...innerVariables }); @@ -712,7 +712,7 @@ Parser.prototype.includeFile = function (file, config) { let fileContent = nunjucks.renderString(data, { ...pageVariables, ...userDefinedVariables }, { path: actualFilePath }); - this._prepreprocessInnerVariables(fileContent, context, config); + this._extractInnerVariables(fileContent, context, config); const innerVariables = getImportedVariableMap(context.cwf); fileContent = nunjucks.renderString(fileContent, { ...userDefinedVariables, ...innerVariables }); const fileExt = utils.getExt(file); From d9d2d66c55dc2a355b1423bf2091f606786358a9 Mon Sep 17 00:00:00 2001 From: Open Close Date: Mon, 8 Jul 2019 10:17:49 +0800 Subject: [PATCH 05/18] Remove err.stack --- src/lib/markbind/src/parser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/markbind/src/parser.js b/src/lib/markbind/src/parser.js index eeb45b473b..b5a36e9017 100644 --- a/src/lib/markbind/src/parser.js +++ b/src/lib/markbind/src/parser.js @@ -677,7 +677,7 @@ Parser.prototype.includeFile = function (file, config) { try { processed = this._preprocess(d, context, config); } catch (err) { - err.message += `${err.stack}\nError while preprocessing '${file}'`; + err.message += `\nError while preprocessing '${file}'`; this._onError(err); processed = createErrorNode(d, err); } From 2c0a12e2a6dd1aabd3c67ea211171ff8d9e8aa2a Mon Sep 17 00:00:00 2001 From: Open Close Date: Mon, 8 Jul 2019 11:12:22 +0800 Subject: [PATCH 06/18] Extract duplicated code into separate function --- src/lib/markbind/src/parser.js | 116 +++++++++++++-------------------- 1 file changed, 45 insertions(+), 71 deletions(-) diff --git a/src/lib/markbind/src/parser.js b/src/lib/markbind/src/parser.js index b5a36e9017..de58b7f498 100644 --- a/src/lib/markbind/src/parser.js +++ b/src/lib/markbind/src/parser.js @@ -220,13 +220,47 @@ Parser.prototype._preprocessThumbnails = function (element) { return element; }; +Parser.prototype._renderIncludeFile = function (filePath, element, context, config, asIfAt = filePath) { + try { + this._fileCache[filePath] = this._fileCache[filePath] + ? this._fileCache[filePath] : fs.readFileSync(filePath, 'utf8'); + } catch (e) { + // Read file fail + const missingReferenceErrorMessage = `Missing reference in: ${element.attribs[ATTRIB_CWF]}`; + e.message += `\n${missingReferenceErrorMessage}`; + this._onError(e); + return createErrorNode(element, e); + } + + const fileContent = this._fileCache[filePath]; // cache the file contents to save some I/O + const { parent, relative } + = calculateNewBaseUrls(asIfAt, config.rootPath, config.baseUrlMap); + const userDefinedVariables = config.userDefinedVariablesMap[path.resolve(parent, relative)]; + + // Extract included variables from the PARENT file + const includeVariables = extractIncludeVariables(element, context.variables); + + // Extract page variables from the CHILD file + const pageVariables = extractPageVariables(asIfAt, fileContent, + userDefinedVariables, includeVariables); + + const content = nunjucks.renderString(fileContent, + { ...pageVariables, ...includeVariables, ...userDefinedVariables }, + { path: filePath }); + + const childContext = _.cloneDeep(context); + childContext.cwf = asIfAt; + childContext.variables = includeVariables; + + return { content, childContext, userDefinedVariables }; +}; + Parser.prototype._extractInnerVariables = function (content, context, config) { const { cwf } = context; const $ = cheerio.load(content, { xmlMode: false, decodeEntities: false, }); - const self = this; const aliases = new Map(); FILE_ALIASES.set(cwf, aliases); $('import[from]').each((index, element) => { @@ -240,49 +274,18 @@ Parser.prototype._extractInnerVariables = function (content, context, config) { : largestName; aliases.set(alias, filePath); - try { - self._fileCache[filePath] = self._fileCache[filePath] - ? self._fileCache[filePath] : fs.readFileSync(filePath, 'utf8'); - } catch (e) { - // Read file fail - const missingReferenceErrorMessage = `Missing reference in: ${element.attribs[ATTRIB_CWF]}`; - e.message += `\n${missingReferenceErrorMessage}`; - self._onError(e); - } - - let innerFileContent = self._fileCache[filePath]; // cache the file contents to save some I/O - const { parent, relative } = calculateNewBaseUrls(filePath, config.rootPath, config.baseUrlMap); - const userDefinedVariables = config.userDefinedVariablesMap[path.resolve(parent, relative)]; - - // Extract included variables from the PARENT file - const includeVariables = extractIncludeVariables(element, context.variables); - - // Extract page variables from the CHILD filere - const pageVariables = extractPageVariables(filePath, innerFileContent, - userDefinedVariables, includeVariables); // Render inner file content - innerFileContent = nunjucks.renderString(innerFileContent, - { - ...pageVariables, - ...includeVariables, - ...userDefinedVariables, - }, - { path: filePath }); - const childContext = _.cloneDeep(context); - childContext.cwf = filePath; - childContext.variables = includeVariables; + const { content: renderedContent, childContext, userDefinedVariables } + = this._renderIncludeFile(filePath, element, context, config); + if (!PROCESSED_INNER_VARIABLES.has(filePath)) { PROCESSED_INNER_VARIABLES.add(filePath); - this._extractInnerVariables(innerFileContent, childContext, config); + this._extractInnerVariables(renderedContent, childContext, config); } const innerVariables = getImportedVariableMap(filePath); VARIABLE_LOOKUP.get(filePath).forEach((value, variableName, map) => { - map.set(variableName, nunjucks.renderString(value, { - ...userDefinedVariables, - ...pageVariables, - ...innerVariables, - })); + map.set(variableName, nunjucks.renderString(value, { ...userDefinedVariables, ...innerVariables })); }); }); }; @@ -370,52 +373,23 @@ Parser.prototype._preprocess = function (node, context, config) { this.staticIncludeSrc.push({ from: context.cwf, to: actualFilePath }); - try { - self._fileCache[actualFilePath] = self._fileCache[actualFilePath] - ? self._fileCache[actualFilePath] : fs.readFileSync(actualFilePath, 'utf8'); - } catch (e) { - // Read file fail - const missingReferenceErrorMessage = `Missing reference in: ${element.attribs[ATTRIB_CWF]}`; - e.message += `\n${missingReferenceErrorMessage}`; - this._onError(e); - return createErrorNode(element, e); - } - const isIncludeSrcMd = utils.isMarkdownFileExt(utils.getExt(filePath)); if (isIncludeSrcMd && context.source === 'html') { // HTML include markdown, use special tag to indicate markdown code. element.name = 'markdown'; } - - let fileContent = self._fileCache[actualFilePath]; // cache the file contents to save some I/O - const { parent, relative } = calculateNewBaseUrls(filePath, config.rootPath, config.baseUrlMap); - const userDefinedVariables = config.userDefinedVariablesMap[path.resolve(parent, relative)]; - - // Extract included variables from the PARENT file - const includeVariables = extractIncludeVariables(element, context.variables); - - // Extract page variables from the CHILD file - const pageVariables = extractPageVariables(filePath, fileContent, - userDefinedVariables, includeVariables); - - // Render inner file content - fileContent = nunjucks.renderString(fileContent, - { ...pageVariables, ...includeVariables, ...userDefinedVariables }, - { path: actualFilePath }); - // The element's children are in the new context - // Process with new context - const childContext = _.cloneDeep(context); - childContext.cwf = filePath; + const { content, childContext, userDefinedVariables } + = this._renderIncludeFile(actualFilePath, element, context, config, filePath); childContext.source = isIncludeSrcMd ? 'md' : 'html'; childContext.callStack.push(context.cwf); - childContext.variables = includeVariables; + if (!PROCESSED_INNER_VARIABLES.has(filePath)) { PROCESSED_INNER_VARIABLES.add(filePath); - this._extractInnerVariables(fileContent, childContext, config); + this._extractInnerVariables(content, childContext, config); } const innerVariables = getImportedVariableMap(filePath); - fileContent = nunjucks.renderString(fileContent, { ...userDefinedVariables, ...innerVariables }); + const fileContent = nunjucks.renderString(content, { ...userDefinedVariables, ...innerVariables }); // Delete variable attributes in include Object.keys(element.attribs).forEach((attribute) => { From 3fff4fc786a43ea949ffe5a197f71980634a5b42 Mon Sep 17 00:00:00 2001 From: Open Close Date: Tue, 23 Jul 2019 22:37:48 +0800 Subject: [PATCH 07/18] Make page variables take precedence over imported variables --- src/lib/markbind/src/parser.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/lib/markbind/src/parser.js b/src/lib/markbind/src/parser.js index de58b7f498..aacb172818 100644 --- a/src/lib/markbind/src/parser.js +++ b/src/lib/markbind/src/parser.js @@ -27,6 +27,7 @@ const ATTRIB_CWF = 'cwf'; const BOILERPLATE_FOLDER_NAME = '_markbind/boilerplates'; +const PREFIX_TO_REDUCE_NAME_CLASH = '$__MARKBIND__'; const VARIABLE_LOOKUP = new Map(); const FILE_ALIASES = new Map(); const PROCESSED_INNER_VARIABLES = new Set(); @@ -153,21 +154,23 @@ function extractPageVariables(fileName, data, userDefinedVariables, includedVari /** * ed variables have not been processed yet, we replace such variables with itself first. */ + const importedVariables = {}; $('import[from]').each((index, element) => { const variableNames = Object.keys(element.attribs) .filter(name => name !== 'from' && name !== 'as'); - // If no namespace is provided, we use the smallest name as one + // If no namespace is provided, we use the smallest name as one... const largestName = variableNames.sort()[0]; - const alias = _.hasIn(element.attribs, 'as') - ? element.attribs.as - : largestName; - pageVariables[alias] = new Proxy({}, { + // ... and prepend it with $__MARKBIND__ to reduce collisions. + const generatedAlias = PREFIX_TO_REDUCE_NAME_CLASH + largestName; + const hasAlias = _.hasIn(element.attribs, 'as'); + const alias = hasAlias ? element.attribs.as : generatedAlias; + importedVariables[alias] = new Proxy({}, { get(obj, prop) { return `{{${alias}.${prop}}}`; }, }); variableNames.forEach((name) => { - pageVariables[name] = `{{${alias}.${name}}}`; + importedVariables[name] = `{{${alias}.${name}}}`; }); }); $('variable').each(function () { @@ -180,13 +183,17 @@ function extractPageVariables(fileName, data, userDefinedVariables, includedVari } if (!pageVariables[variableName]) { const variableValue - = nunjucks.renderString(md.renderInline(variableElement.html()), - { ...pageVariables, ...userDefinedVariables, ...includedVariables }); + = nunjucks.renderString( + md.renderInline(variableElement.html()), + { + ...importedVariables, ...pageVariables, ...userDefinedVariables, ...includedVariables, + }, + ); pageVariables[variableName] = variableValue; VARIABLE_LOOKUP.get(fileName).set(variableName, variableValue); } }); - return pageVariables; + return { ...importedVariables, ...pageVariables }; } Parser.prototype.getDynamicIncludeSrc = function () { @@ -269,9 +276,11 @@ Parser.prototype._extractInnerVariables = function (content, context, config) { .filter(name => name !== 'from' && name !== 'as'); // If no namespace is provided, we use the smallest name as one const largestName = variableNames.sort()[0]; + // ... and prepend it with $__MARKBIND__ to reduce collisions. + const generatedAlias = PREFIX_TO_REDUCE_NAME_CLASH + largestName; const alias = _.hasIn(element.attribs, 'as') ? element.attribs.as - : largestName; + : generatedAlias; aliases.set(alias, filePath); From 75c9d29ac3255e6067fb4343d647e53359785c01 Mon Sep 17 00:00:00 2001 From: Open Close Date: Tue, 23 Jul 2019 22:41:28 +0800 Subject: [PATCH 08/18] Add docs for importing variables --- docs/userGuide/syntax/variables.mbdf | 61 ++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/docs/userGuide/syntax/variables.mbdf b/docs/userGuide/syntax/variables.mbdf index d768635983..da598828c5 100644 --- a/docs/userGuide/syntax/variables.mbdf +++ b/docs/userGuide/syntax/variables.mbdf @@ -103,6 +103,67 @@ You can specify a default value for a variable, which is displayed when the vari Note: These variables will not be applied to [`` files]({{ baseUrl }}/userGuide/reusingContents.html#the-include-tag). Additionally, global variables (`_markbind/variables.md`) will take precedence over any page variables. *See also: [Specifying Variables in an ``]({{ baseUrl }}/userGuide/reusingContents.html#specifying-variables-in-an-include)*. +### Importing Variables + +**You can access [page variables](#page-variables) from another page by importing them.** + +`page.md:` +```html +123 Sun Avenue +Mark +123456789 +``` + +{{ icon_example }} Importing page variables from above `page.md`: + +```html + +``` + +will allow you to access the variables as per normal: {{address}}, {{name}}, {{phone}}. + +--- + +{{ icon_example }} If you have many variables that you want to import, consider using a namespace: + +```html + +``` + +| Detail | How to access +| :------------- |:------------- +| address | {{details.address}} +| name | {{details.name}} +| phone | {{details.phone}} + +This way, ***all*** variables in `page.md` are accessible via {{details.variable_name}}. + +Note that in this case, `details` is treated as the variable name and so is subject to the same rules as other variables, such as global variables taking precedence, and multiple imports to the same namespace being impossible: + +```html + + +``` + +In this case, all the variables in `title.md` are not accessible, as they are overwritten with the variables from `index.md`. + + + +Note that global variables (`_markbind/variables.md`) and [page variables](#page-variables) will take precedence over any imported variables. + +While you can mix the two syntaxes for importing page variables, it may get confusing: +```html + +``` + +This may seem like it will import *only* `address` and `name` from `page.md` and storing them in the namespace `details`. + +However, this is a combination of *both* syntaxes above, and thus this will allow you to: + +- access `address` and `name` (but NOT `phone`) with {{address}} and {{name}} +- access `address`, `name`, and `phone` with {{details.address}}, {{details.name}}, and {{details.phone}} + + ### Variables: Tips and Tricks From 11cae4a508232e399f641b8bcf58e7330a54a063 Mon Sep 17 00:00:00 2001 From: Open Close Date: Fri, 26 Jul 2019 14:52:27 +0800 Subject: [PATCH 09/18] Reword explanation --- docs/userGuide/syntax/variables.mbdf | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/userGuide/syntax/variables.mbdf b/docs/userGuide/syntax/variables.mbdf index da598828c5..18297be70d 100644 --- a/docs/userGuide/syntax/variables.mbdf +++ b/docs/userGuide/syntax/variables.mbdf @@ -107,25 +107,31 @@ Note: These variables will not be applied to [`` files]({{ baseUrl }}/u **You can access [page variables](#page-variables) from another page by importing them.** -`page.md:` + +{{ icon_example }} Importing specific variables from `person.md` into `coverpage.md`: +`person.md`: ```html 123 Sun Avenue Mark 123456789 ``` -{{ icon_example }} Importing page variables from above `page.md`: +`coverpage.md`: ```html - + + ``` will allow you to access the variables as per normal: {{address}}, {{name}}, {{phone}}. --- -{{ icon_example }} If you have many variables that you want to import, consider using a namespace: +**When importing all variables, you should attach a _namespace_** to the imported variables using an `as` attributes. + +{{ icon_example }}: +`coverpage.md`: ```html ``` @@ -136,7 +142,7 @@ will allow you to access the variables as per normal: {{addre | name | {{details.name}} | phone | {{details.phone}} -This way, ***all*** variables in `page.md` are accessible via {{details.variable_name}}. +This way, ***all*** variables in `page.md` are accessible via {{details.<variable_name>}}. Note that in this case, `details` is treated as the variable name and so is subject to the same rules as other variables, such as global variables taking precedence, and multiple imports to the same namespace being impossible: From 92065f6b36671b26dfec66be0f738faa824397b5 Mon Sep 17 00:00:00 2001 From: Open Close Date: Mon, 29 Jul 2019 11:17:29 +0800 Subject: [PATCH 10/18] Fix typo in variables.mbdf --- docs/userGuide/syntax/variables.mbdf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/userGuide/syntax/variables.mbdf b/docs/userGuide/syntax/variables.mbdf index 18297be70d..fcbcb4b27a 100644 --- a/docs/userGuide/syntax/variables.mbdf +++ b/docs/userGuide/syntax/variables.mbdf @@ -119,8 +119,7 @@ Note: These variables will not be applied to [`` files]({{ baseUrl }}/u `coverpage.md`: ```html - - + ``` will allow you to access the variables as per normal: {{address}}, {{name}}, {{phone}}. From fbb5120b214b033a57c0c986832f47a9d8fec371 Mon Sep 17 00:00:00 2001 From: Open Close Date: Mon, 29 Jul 2019 11:18:13 +0800 Subject: [PATCH 11/18] Improve naming and added comments --- src/lib/markbind/src/parser.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/lib/markbind/src/parser.js b/src/lib/markbind/src/parser.js index aacb172818..5fb553c73b 100644 --- a/src/lib/markbind/src/parser.js +++ b/src/lib/markbind/src/parser.js @@ -27,7 +27,10 @@ const ATTRIB_CWF = 'cwf'; const BOILERPLATE_FOLDER_NAME = '_markbind/boilerplates'; -const PREFIX_TO_REDUCE_NAME_CLASH = '$__MARKBIND__'; +/* Imported global variables will be assigned a namespace. + * A prefix is appended to reduce clashes with other variables in the page. + */ +const IMPORTED_VARIABLE_PREFIX = '$__MARKBIND__'; const VARIABLE_LOOKUP = new Map(); const FILE_ALIASES = new Map(); const PROCESSED_INNER_VARIABLES = new Set(); @@ -128,6 +131,10 @@ function extractIncludeVariables(includeElement, contextVariables) { return includedVariables; } +/** + * Returns an object containing the imported variables for specified file + * @param file file name to get the imported variables for + */ function getImportedVariableMap(file) { const innerVariables = {}; FILE_ALIASES.get(file).forEach((actualPath, alias) => { @@ -161,7 +168,7 @@ function extractPageVariables(fileName, data, userDefinedVariables, includedVari // If no namespace is provided, we use the smallest name as one... const largestName = variableNames.sort()[0]; // ... and prepend it with $__MARKBIND__ to reduce collisions. - const generatedAlias = PREFIX_TO_REDUCE_NAME_CLASH + largestName; + const generatedAlias = IMPORTED_VARIABLE_PREFIX + largestName; const hasAlias = _.hasIn(element.attribs, 'as'); const alias = hasAlias ? element.attribs.as : generatedAlias; importedVariables[alias] = new Proxy({}, { @@ -277,7 +284,7 @@ Parser.prototype._extractInnerVariables = function (content, context, config) { // If no namespace is provided, we use the smallest name as one const largestName = variableNames.sort()[0]; // ... and prepend it with $__MARKBIND__ to reduce collisions. - const generatedAlias = PREFIX_TO_REDUCE_NAME_CLASH + largestName; + const generatedAlias = IMPORTED_VARIABLE_PREFIX + largestName; const alias = _.hasIn(element.attribs, 'as') ? element.attribs.as : generatedAlias; From 199aa3c7058a929f849cd4a6fb038b090d79bb88 Mon Sep 17 00:00:00 2001 From: Open Close Date: Mon, 29 Jul 2019 11:32:13 +0800 Subject: [PATCH 12/18] Added explanations in variables files --- docs/testing/child.md | 13 ++++++++++--- docs/testing/morevariablestoimport.md | 9 ++++++++- docs/testing/usecaseincomment.md | 2 +- docs/testing/variablestoimport.md | 19 ++++++++++++++----- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/docs/testing/child.md b/docs/testing/child.md index fa04489a26..2a3cd12de9 100644 --- a/docs/testing/child.md +++ b/docs/testing/child.md @@ -1,3 +1,10 @@ -Title -testimportvariables.md -testimportvariables \ No newline at end of file +This page contains some variables that are being imported in other files. +There should be only VARIABLES START and VARIABLES END in red: + +
+VARIABLES START +Title +testimportvariables.md +testimportvariables +VARIABLES END +
\ No newline at end of file diff --git a/docs/testing/morevariablestoimport.md b/docs/testing/morevariablestoimport.md index a81d2f3efe..30e3d815b0 100644 --- a/docs/testing/morevariablestoimport.md +++ b/docs/testing/morevariablestoimport.md @@ -1 +1,8 @@ - This is a deeply imported variable \ No newline at end of file +This page contains some variables that are being imported in other files. +There should be only VARIABLES START and VARIABLES END in red: + +
+VARIABLES START +This is a deeply imported variable +VARIABLES END +
\ No newline at end of file diff --git a/docs/testing/usecaseincomment.md b/docs/testing/usecaseincomment.md index 4fb2782a63..28cc78c294 100644 --- a/docs/testing/usecaseincomment.md +++ b/docs/testing/usecaseincomment.md @@ -1,6 +1,6 @@ Refer to this comment: https://github.com/MarkBind/markbind/pull/751#issuecomment-469670640 - + {{ child.title }} diff --git a/docs/testing/variablestoimport.md b/docs/testing/variablestoimport.md index 25b973bf10..59518c8a63 100644 --- a/docs/testing/variablestoimport.md +++ b/docs/testing/variablestoimport.md @@ -1,17 +1,26 @@ -This variable comes from variablesToImport.md +This page contains some variables that are being imported in other files. +There should be only VARIABLES START and VARIABLES END in red: -This is a page variable from variablestoimport.md +
+VARIABLES START - +This variable comes from variablesToImport.md + +This is a page variable from variablestoimport.md + + + ## Trying to access a page variable: There should be something red below:
{{pagevar}}
Something should have appeared above in red. -## @#$@$ Trying to access an imported variable via namespace: +## Trying to access an imported variable via namespace: There should be something blue below:
{{namespace.variable}}
Something should have appeared above in blue. -
\ No newline at end of file + +VARIABLES END +
\ No newline at end of file From e6883a7b6006271e8733dc80204125f62034d898 Mon Sep 17 00:00:00 2001 From: Open Close Date: Tue, 30 Jul 2019 13:22:23 +0800 Subject: [PATCH 13/18] Fix live reload --- src/Site.js | 2 ++ src/lib/markbind/src/parser.js | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/Site.js b/src/Site.js index 30eb5619d7..45d0790909 100644 --- a/src/Site.js +++ b/src/Site.js @@ -8,6 +8,7 @@ const path = require('path'); const Promise = require('bluebird'); const ProgressBar = require('progress'); const walkSync = require('walk-sync'); +const MarkBind = require('./lib/markbind/src/parser'); const _ = {}; _.difference = require('lodash/difference'); @@ -740,6 +741,7 @@ Site.prototype._rebuildAffectedSourceFiles = function (filePaths) { const filePathArray = Array.isArray(filePaths) ? filePaths : [filePaths]; const uniquePaths = _.uniq(filePathArray); logger.info('Rebuilding affected source files'); + MarkBind.resetVariables(); return new Promise((resolve, reject) => { this.regenerateAffectedPages(uniquePaths) .then(() => fs.removeAsync(this.tempPath)) diff --git a/src/lib/markbind/src/parser.js b/src/lib/markbind/src/parser.js index 5fb553c73b..72340f1c39 100644 --- a/src/lib/markbind/src/parser.js +++ b/src/lib/markbind/src/parser.js @@ -95,6 +95,12 @@ function Parser(options) { this.missingIncludeSrc = []; } +Parser.resetVariables = function () { + VARIABLE_LOOKUP.clear(); + FILE_ALIASES.clear(); + PROCESSED_INNER_VARIABLES.clear(); +}; + /** * Extract variables from an include element * @param includeElement include element to extract variables from @@ -290,6 +296,7 @@ Parser.prototype._extractInnerVariables = function (content, context, config) { : generatedAlias; aliases.set(alias, filePath); + this.staticIncludeSrc.push({ from: context.cwf, to: filePath }); // Render inner file content const { content: renderedContent, childContext, userDefinedVariables } From 18f9bccac9be549d093df70daa49b92c8f4485bb Mon Sep 17 00:00:00 2001 From: Open Close Date: Wed, 31 Jul 2019 10:43:26 +0800 Subject: [PATCH 14/18] Moved tests --- docs/site.json | 3 - .../test_site/expected/siteData.json | 22 ++++++ .../expected/testImportVariables.html | 67 +++++++++++++++++++ .../testPanelsWithImportedVariables.html | 64 ++++++++++++++++++ .../testimportvariables._include_.html | 13 ++++ .../test_site/moreVariablesToImport.md | 0 test/functional/test_site/panelSrcs.md | 10 +++ test/functional/test_site/site.json | 8 +++ .../test_site/testImportVariables.md | 2 +- .../testPanelsWithImportedVariables.md | 2 +- .../functional/test_site/variablesToImport.md | 2 +- 11 files changed, 187 insertions(+), 6 deletions(-) create mode 100644 test/functional/test_site/expected/testImportVariables.html create mode 100644 test/functional/test_site/expected/testPanelsWithImportedVariables.html create mode 100644 test/functional/test_site/expected/testimportvariables._include_.html rename docs/testing/morevariablestoimport.md => test/functional/test_site/moreVariablesToImport.md (100%) create mode 100644 test/functional/test_site/panelSrcs.md rename docs/testing/testimportvariables.md => test/functional/test_site/testImportVariables.md (84%) rename docs/testing/usecaseincomment.md => test/functional/test_site/testPanelsWithImportedVariables.md (87%) rename docs/testing/variablestoimport.md => test/functional/test_site/variablesToImport.md (93%) diff --git a/docs/site.json b/docs/site.json index b117787993..91ab123fe4 100644 --- a/docs/site.json +++ b/docs/site.json @@ -15,9 +15,6 @@ { "glob": "userGuide/*.md" }, - { - "glob": "testing/*.md" - }, { "src": "userGuide/fullSyntaxReference.md", "searchable": "no" diff --git a/test/functional/test_site/expected/siteData.json b/test/functional/test_site/expected/siteData.json index 260ac3336e..4504a32246 100644 --- a/test/functional/test_site/expected/siteData.json +++ b/test/functional/test_site/expected/siteData.json @@ -299,6 +299,28 @@ "layout": "default", "globalOverrideProperty": "Overridden by global override", "globalAndFrontMatterOverrideProperty": "Overridden by global override" + }, + { + "headings": { + "trying-to-access-a-page-variable": "Trying to access a page variable:", + "trying-to-access-an-imported-variable-via-namespace": "Trying to access an imported variable via namespace:" + }, + "src": "testImportVariables.md", + "title": "Imported Variables Test", + "layout": "default", + "globalOverrideProperty": "Overridden by global override", + "globalAndFrontMatterOverrideProperty": "Overridden by global override" + }, + { + "headings": { + "below-panel-is-working": "Below panel is working", + "below-should-be-a-panel-but-is-now-an-error": "Below should be a panel, but is now an error." + }, + "src": "testPanelsWithImportedVariables.md", + "title": "Panels with Imported Variables Test", + "layout": "default", + "globalOverrideProperty": "Overridden by global override", + "globalAndFrontMatterOverrideProperty": "Overridden by global override" } ] } diff --git a/test/functional/test_site/expected/testImportVariables.html b/test/functional/test_site/expected/testImportVariables.html new file mode 100644 index 0000000000..665095d144 --- /dev/null +++ b/test/functional/test_site/expected/testImportVariables.html @@ -0,0 +1,67 @@ + + + + + + + + + + Imported Variables Test + + + + + + + + + + + + + + + +
+
+
+
+

Making sure the issue here https://github.com/MarkBind/markbind/commit/48b57a18a8bfd68101b163908da4a0541756364a is fixed.

+
+

Test import variables from src specified via variable: This variable comes from variablesToImport.md

+

Test import variables that itself imports other variables:

+

Trying to access a page variable:

+

There should be something red below:

+
This is a page variable from variablestoimport.md
+ Something should have appeared above in red. +

Trying to access an imported variable via namespace:

+

There should be something blue below:

+
This is a deeply imported variable
+ Something should have appeared above in blue. +
+
+
+
+ Default footer +
+
+
+ + + + + + + + + + + + + \ No newline at end of file diff --git a/test/functional/test_site/expected/testPanelsWithImportedVariables.html b/test/functional/test_site/expected/testPanelsWithImportedVariables.html new file mode 100644 index 0000000000..50bdf09321 --- /dev/null +++ b/test/functional/test_site/expected/testPanelsWithImportedVariables.html @@ -0,0 +1,64 @@ + + + + + + + + + + Panels with Imported Variables Test + + + + + + + + + + + + + + + +
+
+
+

Refer to this comment: https://github.com/MarkBind/markbind/pull/751#issuecomment-469670640

+
+ Title +

Below panel is working

+

+ +

+

Below should be a panel, but is now an error.

+ +
+
+
+
+ Default footer +
+
+
+ + + + + + + + + + + + + \ No newline at end of file diff --git a/test/functional/test_site/expected/testimportvariables._include_.html b/test/functional/test_site/expected/testimportvariables._include_.html new file mode 100644 index 0000000000..3b8cff9686 --- /dev/null +++ b/test/functional/test_site/expected/testimportvariables._include_.html @@ -0,0 +1,13 @@ +
+

Making sure the issue here https://github.com/MarkBind/markbind/commit/48b57a18a8bfd68101b163908da4a0541756364a is fixed.

+
+

Test import variables from src specified via variable: This variable comes from variablesToImport.md

+

Test import variables that itself imports other variables:

+

Trying to access a page variable:

+

There should be something red below:

+
This is a page variable from variablestoimport.md
+Something should have appeared above in red. +

Trying to access an imported variable via namespace:

+

There should be something blue below:

+
This is a deeply imported variable
+Something should have appeared above in blue. \ No newline at end of file diff --git a/docs/testing/morevariablestoimport.md b/test/functional/test_site/moreVariablesToImport.md similarity index 100% rename from docs/testing/morevariablestoimport.md rename to test/functional/test_site/moreVariablesToImport.md diff --git a/test/functional/test_site/panelSrcs.md b/test/functional/test_site/panelSrcs.md new file mode 100644 index 0000000000..2a3cd12de9 --- /dev/null +++ b/test/functional/test_site/panelSrcs.md @@ -0,0 +1,10 @@ +This page contains some variables that are being imported in other files. +There should be only VARIABLES START and VARIABLES END in red: + +
+VARIABLES START +Title +testimportvariables.md +testimportvariables +VARIABLES END +
\ No newline at end of file diff --git a/test/functional/test_site/site.json b/test/functional/test_site/site.json index 91c2460049..6896ab6cd7 100644 --- a/test/functional/test_site/site.json +++ b/test/functional/test_site/site.json @@ -63,6 +63,14 @@ { "src": "testPlantUML.md", "title": "PlantUML Test" + }, + { + "src": "testImportVariables.md", + "title": "Imported Variables Test" + }, + { + "src": "testPanelsWithImportedVariables.md", + "title": "Panels with Imported Variables Test" } ], "ignore": [ diff --git a/docs/testing/testimportvariables.md b/test/functional/test_site/testImportVariables.md similarity index 84% rename from docs/testing/testimportvariables.md rename to test/functional/test_site/testImportVariables.md index e99537bf64..b8d8aa11eb 100644 --- a/docs/testing/testimportvariables.md +++ b/test/functional/test_site/testImportVariables.md @@ -1,4 +1,4 @@ -variablestoimport +variablesToImport Making sure the issue here https://github.com/MarkBind/markbind/commit/48b57a18a8bfd68101b163908da4a0541756364a is fixed. diff --git a/docs/testing/usecaseincomment.md b/test/functional/test_site/testPanelsWithImportedVariables.md similarity index 87% rename from docs/testing/usecaseincomment.md rename to test/functional/test_site/testPanelsWithImportedVariables.md index 28cc78c294..450e4120f2 100644 --- a/docs/testing/usecaseincomment.md +++ b/test/functional/test_site/testPanelsWithImportedVariables.md @@ -1,6 +1,6 @@ Refer to this comment: https://github.com/MarkBind/markbind/pull/751#issuecomment-469670640 - + {{ child.title }} diff --git a/docs/testing/variablestoimport.md b/test/functional/test_site/variablesToImport.md similarity index 93% rename from docs/testing/variablestoimport.md rename to test/functional/test_site/variablesToImport.md index 59518c8a63..19c7466a39 100644 --- a/docs/testing/variablestoimport.md +++ b/test/functional/test_site/variablesToImport.md @@ -8,7 +8,7 @@ VARIABLES START This is a page variable from variablestoimport.md - + From 5b4273d2eb852070729d848ea956714d27543e90 Mon Sep 17 00:00:00 2001 From: Open Close Date: Wed, 31 Jul 2019 15:25:17 +0800 Subject: [PATCH 15/18] Fix tests --- .../test_site/expected/testPanelsWithImportedVariables.html | 4 ++-- test/functional/test_site/panelSrcs.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/functional/test_site/expected/testPanelsWithImportedVariables.html b/test/functional/test_site/expected/testPanelsWithImportedVariables.html index 50bdf09321..a282e0d67e 100644 --- a/test/functional/test_site/expected/testPanelsWithImportedVariables.html +++ b/test/functional/test_site/expected/testPanelsWithImportedVariables.html @@ -31,10 +31,10 @@ Title

Below panel is working

- +

Below should be a panel, but is now an error.

- diff --git a/test/functional/test_site/panelSrcs.md b/test/functional/test_site/panelSrcs.md index 2a3cd12de9..f8507a582f 100644 --- a/test/functional/test_site/panelSrcs.md +++ b/test/functional/test_site/panelSrcs.md @@ -4,7 +4,7 @@ There should be only VARIABLES START and VARIABLES END in red:
VARIABLES START Title -testimportvariables.md -testimportvariables +testImportVariables.md +testImportVariables VARIABLES END
\ No newline at end of file From c3ed3fae4b82fbd3fcfe6645c637a2a574061013 Mon Sep 17 00:00:00 2001 From: "Open O. Close" <3646725+openorclose@users.noreply.github.com> Date: Wed, 31 Jul 2019 15:45:26 +0800 Subject: [PATCH 16/18] Fix capitalisation --- ...iables._include_.html => testImportVariables._include_.html} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename test/functional/test_site/expected/{testimportvariables._include_.html => testImportVariables._include_.html} (95%) diff --git a/test/functional/test_site/expected/testimportvariables._include_.html b/test/functional/test_site/expected/testImportVariables._include_.html similarity index 95% rename from test/functional/test_site/expected/testimportvariables._include_.html rename to test/functional/test_site/expected/testImportVariables._include_.html index 3b8cff9686..37af3d13cf 100644 --- a/test/functional/test_site/expected/testimportvariables._include_.html +++ b/test/functional/test_site/expected/testImportVariables._include_.html @@ -10,4 +10,4 @@

Trying to access a page variable:

Trying to access an imported variable via namespace:

There should be something blue below:

This is a deeply imported variable
-Something should have appeared above in blue. \ No newline at end of file +Something should have appeared above in blue. From 9b1a5b19b705d07c5093b4cc781477ba0c9339b6 Mon Sep 17 00:00:00 2001 From: Open Close Date: Wed, 31 Jul 2019 15:54:54 +0800 Subject: [PATCH 17/18] Remove failing test due to absolute location --- test/functional/test_site/expected/siteData.json | 2 +- .../test_site/expected/testImportVariables._include_.html | 2 +- .../test_site/expected/testPanelsWithImportedVariables.html | 4 +--- test/functional/test_site/testPanelsWithImportedVariables.md | 4 ++-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/test/functional/test_site/expected/siteData.json b/test/functional/test_site/expected/siteData.json index 4504a32246..b0da98f1f1 100644 --- a/test/functional/test_site/expected/siteData.json +++ b/test/functional/test_site/expected/siteData.json @@ -314,7 +314,7 @@ { "headings": { "below-panel-is-working": "Below panel is working", - "below-should-be-a-panel-but-is-now-an-error": "Below should be a panel, but is now an error." + "below-should-be-a-panel-but-is-now-an-error-uncomment-it-to-see-the-error": "Below should be a panel, but is now an error. Uncomment it to see the error." }, "src": "testPanelsWithImportedVariables.md", "title": "Panels with Imported Variables Test", diff --git a/test/functional/test_site/expected/testImportVariables._include_.html b/test/functional/test_site/expected/testImportVariables._include_.html index 37af3d13cf..3b8cff9686 100644 --- a/test/functional/test_site/expected/testImportVariables._include_.html +++ b/test/functional/test_site/expected/testImportVariables._include_.html @@ -10,4 +10,4 @@

Trying to access a page variable:

Trying to access an imported variable via namespace:

There should be something blue below:

This is a deeply imported variable
-Something should have appeared above in blue. +Something should have appeared above in blue. \ No newline at end of file diff --git a/test/functional/test_site/expected/testPanelsWithImportedVariables.html b/test/functional/test_site/expected/testPanelsWithImportedVariables.html index a282e0d67e..f948f7b545 100644 --- a/test/functional/test_site/expected/testPanelsWithImportedVariables.html +++ b/test/functional/test_site/expected/testPanelsWithImportedVariables.html @@ -33,9 +33,7 @@

Below panel is working

-

Below should be a panel, but is now an error.

- +

Below should be a panel, but is now an error. Uncomment it to see the error.