Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions src/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,9 +568,7 @@ class Page {
* @param {FileConfig} fileConfig
*/
generateExpressiveLayout(pageData, fileConfig) {
const markbinder = new MarkBind({
errorHandler: logger.error,
});
const markbinder = new MarkBind();
const template = {};
template[LAYOUT_PAGE_BODY_VARIABLE] = pageData;
const { layout } = this.frontMatter;
Expand Down Expand Up @@ -916,9 +914,7 @@ class Page {
this.includedFiles = new Set([this.sourcePath]);
this.headerIdMap = {}; // Reset for live reload

const markbinder = new MarkBind({
errorHandler: logger.error,
});
const markbinder = new MarkBind();
/**
* @type {FileConfig}
*/
Expand Down Expand Up @@ -1236,9 +1232,7 @@ class Page {
* We create a local instance of Markbind for an empty dynamicIncludeSrc
* so that we only recursively rebuild the file's included content
*/
const markbinder = new MarkBind({
errorHandler: logger.error,
});
const markbinder = new MarkBind();
return markbinder.includeFile(dependency.to, {
baseUrlMap: this.baseUrlMap,
userDefinedVariablesMap: this.userDefinedVariablesMap,
Expand Down
20 changes: 8 additions & 12 deletions src/lib/markbind/src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ const {
class Parser {
constructor(options) {
this._options = options || {};
// eslint-disable-next-line no-console
this._onError = this._options.errorHandler || console.error;
this._fileCache = {};
this.dynamicIncludeSrc = [];
this.staticIncludeSrc = [];
Expand Down Expand Up @@ -122,8 +120,7 @@ class Parser {
}
} else {
if (!variableName) {
// eslint-disable-next-line no-console
console.warn(`Missing 'name' for variable in ${fileName}\n`);
logger.warn(`Missing 'name' for variable in ${fileName}\n`);
return;
}
setPageVariable(variableName, md.renderInline(variableElement.html()));
Expand Down Expand Up @@ -155,7 +152,7 @@ class Parser {
// Read file fail
const missingReferenceErrorMessage = `Missing reference in: ${node.attribs[ATTRIB_CWF]}`;
e.message += `\n${missingReferenceErrorMessage}`;
this._onError(e);
logger.error(e);
return utils.createErrorNode(node, e);
}
const fileContent = this._fileCache[filePath]; // cache the file contents to save some I/O
Expand Down Expand Up @@ -345,15 +342,15 @@ class Parser {
break;
}

componentParser.parseComponents(node, this._onError);
componentParser.parseComponents(node);

if (node.children) {
node.children.forEach((child) => {
this._parse(child, config);
});
}

componentParser.postParseComponents(node, this._onError);
componentParser.postParseComponents(node);

// If a fixed header is applied to this page, generate dummy spans as anchor points
if (config.fixedHeader && isHeadingTag && node.attribs.id) {
Expand Down Expand Up @@ -398,7 +395,7 @@ class Parser {
processed = componentPreprocessor.preProcessComponent(d, context, config, this);
} catch (err) {
err.message += `\nError while preprocessing '${file}'`;
this._onError(err);
logger.error(err);
processed = utils.createErrorNode(d, err);
}
return processed;
Expand Down Expand Up @@ -479,7 +476,7 @@ class Parser {
processed = componentPreprocessor.preProcessComponent(d, currentContext, config, this);
} catch (err) {
err.message += `\nError while preprocessing '${actualFilePath}'`;
this._onError(err);
logger.error(err);
processed = utils.createErrorNode(d, err);
}
return processed;
Expand Down Expand Up @@ -538,7 +535,7 @@ class Parser {
parsed = this._parse(d, config);
} catch (err) {
err.message += `\nError while rendering '${filePath}'`;
this._onError(err);
logger.error(err);
parsed = utils.createErrorNode(d, err);
}
return parsed;
Expand Down Expand Up @@ -672,8 +669,7 @@ class Parser {
}
const variableName = child.attribs.name || child.attribs.id;
if (!variableName) {
// eslint-disable-next-line no-console
console.warn(`Missing reference in ${includeElement.attribs[ATTRIB_CWF]}\n`
logger.warn(`Missing reference in ${includeElement.attribs[ATTRIB_CWF]}\n`
+ `Missing 'name' or 'id' in variable for ${includeElement.attribs.src} include.`);
return;
}
Expand Down
39 changes: 10 additions & 29 deletions src/lib/markbind/src/parsers/componentParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const _ = {};
_.has = require('lodash/has');

const md = require('../lib/markdown-it');
const logger = require('../../../../util/logger');

cheerio.prototype.options.xmlMode = true; // Enable xml mode for self-closing tag
cheerio.prototype.options.decodeEntities = false; // Don't escape HTML entities
Expand Down Expand Up @@ -148,9 +149,7 @@ function _warnConflictingAttributes(node, attribute, attrsConflictingWith) {
}
attrsConflictingWith.forEach((conflictingAttr) => {
if (conflictingAttr in node.attribs) {
// TODO: Use logger here instead of console.warn. See issue #1060
// eslint-disable-next-line no-console
console.warn(`warn: Usage of conflicting ${node.name} attributes: `
logger.warn(`Usage of conflicting ${node.name} attributes: `
+ `'${attribute}' with '${conflictingAttr}'`);
}
});
Expand All @@ -164,9 +163,7 @@ function _warnConflictingAttributes(node, attribute, attrsConflictingWith) {
function _warnDeprecatedAttributes(node, attributeNamePairs) {
Object.entries(attributeNamePairs).forEach(([deprecatedAttrib, correctAttrib]) => {
if (deprecatedAttrib in node.attribs) {
// TODO: Use logger here instead of console.warn. See issue #1060
// eslint-disable-next-line no-console
console.warn(`warn: ${node.name} attribute '${deprecatedAttrib}' `
logger.warn(`${node.name} attribute '${deprecatedAttrib}' `
+ `is deprecated and may be removed in the future. Please use '${correctAttrib}'`);
}
});
Expand Down Expand Up @@ -249,9 +246,7 @@ function _warnDeprecatedSlotNames(element, namePairs) {
if (child.attribs.slot !== deprecatedName) {
return;
}
// TODO: Use logger here instead of console.warn. See issue #1060
// eslint-disable-next-line no-console
console.warn(`warn: ${element.name} slot name '${deprecatedName}' `
logger.warn(`${element.name} slot name '${deprecatedName}' `
+ `is deprecated and may be removed in the future. Please use '${correctName}'`);
});
});
Expand Down Expand Up @@ -389,14 +384,10 @@ function _parseDropdownAttributes(node) {
// If header slot is present, the header attribute has no effect, and we can simply remove it.
if (hasHeaderSlot) {
if (_.has(node.attribs, 'header')) {
// TODO: Use logger here instead of console.warn. See issue #1060
// eslint-disable-next-line no-console
console.warn(`warn: ${node.name} has a header slot, 'header' attribute has no effect.`);
logger.warn(`${node.name} has a header slot, 'header' attribute has no effect.`);
}
if (_.has(node.attribs, 'text')) {
// TODO: Use logger here instead of console.warn. See issue #1060
// eslint-disable-next-line no-console
console.warn(`warn: ${node.name} has a header slot, 'text' attribute has no effect.`);
logger.warn(`${node.name} has a header slot, 'text' attribute has no effect.`);
}
delete node.attribs.header;
delete node.attribs.text;
Expand Down Expand Up @@ -438,7 +429,7 @@ function _parseThumbnailAttributes(node) {
* API
*/

function parseComponents(node, errorHandler) {
function parseComponents(node) {
try {
switch (node.name) {
case 'panel':
Expand Down Expand Up @@ -473,16 +464,11 @@ function parseComponents(node, errorHandler) {
break;
}
} catch (error) {
if (!errorHandler) {
// eslint-disable-next-line no-console
console.error(error);
return;
}
errorHandler(error);
logger.error(error);
}
}

function postParseComponents(node, errorHandler) {
function postParseComponents(node) {
try {
switch (node.name) {
case 'panel':
Expand All @@ -492,12 +478,7 @@ function postParseComponents(node, errorHandler) {
break;
}
} catch (error) {
if (!errorHandler) {
// eslint-disable-next-line no-console
console.error(error);
return;
}
errorHandler(error);
logger.error(error);
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/lib/markbind/src/preprocessors/componentPreprocessor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const cheerio = require('cheerio');
const path = require('path');
const url = require('url');
const logger = require('../../../../util/logger');

const CyclicReferenceError = require('../handlers/cyclicReferenceError.js');

Expand Down Expand Up @@ -64,7 +65,7 @@ function _getFileExistsNode(element, context, config, parser, actualFilePath, is
parser.missingIncludeSrc.push({ from: context.cwf, to: actualFilePath });
const error = new Error(
`No such file: ${actualFilePath}\nMissing reference in ${element.attribs[ATTRIB_CWF]}`);
parser._onError(error);
logger.error(error);

return utils.createErrorNode(element, error);
}
Expand Down Expand Up @@ -212,7 +213,7 @@ function _preprocessInclude(node, context, config, parser) {

if (_.isEmpty(element.attribs.src)) {
const error = new Error(`Empty src attribute in include in: ${element.attribs[ATTRIB_CWF]}`);
parser._onError(error);
logger.error(error);
return utils.createErrorNode(element, error);
}

Expand Down Expand Up @@ -285,7 +286,7 @@ function _preprocessInclude(node, context, config, parser) {
const hashSrcWithoutHash = hash.substring(1);
const error = new Error(`No such segment '${hashSrcWithoutHash}' in file: ${actualFilePath}\n`
+ `Missing reference in ${element.attribs[ATTRIB_CWF]}`);
parser._onError(error);
logger.error(error);

return utils.createErrorNode(element, error);
}
Expand All @@ -309,7 +310,7 @@ function _preprocessInclude(node, context, config, parser) {
if (element.children && element.children.length > 0) {
if (childContext.callStack.length > CyclicReferenceError.MAX_RECURSIVE_DEPTH) {
const error = new CyclicReferenceError(childContext.callStack);
parser._onError(error);
logger.error(error);
return utils.createErrorNode(element, error);
}

Expand Down