diff --git a/packages/core/src/html/NodeProcessor.ts b/packages/core/src/html/NodeProcessor.ts
index 34728f99ae..790188d67b 100644
--- a/packages/core/src/html/NodeProcessor.ts
+++ b/packages/core/src/html/NodeProcessor.ts
@@ -26,7 +26,7 @@ import { PageNavProcessor, renderSiteNav, addSitePageNavPortal } from './siteAnd
import { highlightCodeBlock, setCodeLineNumbers } from './codeblockProcessor';
import { setHeadingId, assignPanelId } from './headerProcessor';
import { FootnoteProcessor } from './FootnoteProcessor';
-import { Node, NodeOrText, TextElement } from '../utils/node';
+import { MbNode, NodeOrText, TextElement } from '../utils/node';
const fm = require('fastmatter');
@@ -90,7 +90,7 @@ export class NodeProcessor {
static _trimNodes(nodeOrText: NodeOrText) {
if (NodeProcessor._isText(nodeOrText)) return;
- const node = nodeOrText as Node;
+ const node = nodeOrText as MbNode;
if (node.name === 'pre' || node.name === 'code') {
return;
}
@@ -115,7 +115,7 @@ export class NodeProcessor {
/*
* Frontmatter collection
*/
- _processFrontmatter(node: Node, context: Context) {
+ _processFrontmatter(node: MbNode, context: Context) {
let currentFrontmatter = {};
const frontmatter = cheerio(node);
if (!context.processingOptions.omitFrontmatter && frontmatter.text().trim()) {
@@ -124,8 +124,8 @@ export class NodeProcessor {
// The latter case will result in the data being wrapped in a div
const frontmatterIncludeDiv = frontmatter.find('div');
const frontmatterData = frontmatterIncludeDiv.length
- ? ((frontmatterIncludeDiv[0] as Node).children as Node[])[0].data
- : ((frontmatter[0] as Node).children as Node[])[0].data;
+ ? ((frontmatterIncludeDiv[0] as MbNode).children as MbNode[])[0].data
+ : ((frontmatter[0] as MbNode).children as MbNode[])[0].data;
const frontmatterWrapped = `${FRONTMATTER_FENCE}\n${frontmatterData}\n${FRONTMATTER_FENCE}`;
currentFrontmatter = fm(frontmatterWrapped).attributes;
@@ -142,7 +142,7 @@ export class NodeProcessor {
* Layout element collection
*/
- private static collectLayoutEl(node: Node): string | null {
+ private static collectLayoutEl(node: MbNode): string | null {
const $ = cheerio(node);
const html = $.html();
$.remove();
@@ -152,7 +152,7 @@ export class NodeProcessor {
/**
* Removes the node if modal id already exists, processes node otherwise
*/
- private processModal(node: Node) {
+ private processModal(node: MbNode) {
if (node.attribs) {
if (this.processedModals[node.attribs.id]) {
cheerio(node).remove();
@@ -174,7 +174,7 @@ export class NodeProcessor {
processNode(nodeOrText: NodeOrText, context: Context): Context {
try {
if (NodeProcessor._isText(nodeOrText)) return context;
- const node = nodeOrText as Node;
+ const node = nodeOrText as MbNode;
transformOldSlotSyntax(node);
shiftSlotNodeDeeper(node);
@@ -275,7 +275,7 @@ export class NodeProcessor {
postProcessNode(nodeOrText: NodeOrText) {
if (NodeProcessor._isText(nodeOrText)) return;
- const node = nodeOrText as Node;
+ const node = nodeOrText as MbNode;
try {
switch (node.name) {
@@ -322,7 +322,7 @@ export class NodeProcessor {
if (NodeProcessor._isText(dom)) {
return dom as TextElement;
}
- const node = dom as Node;
+ const node = dom as MbNode;
node.name = node.name.toLowerCase();
if (linkProcessor.hasTagLink(node)) {
linkProcessor.convertRelativeLinks(node, context.cwf, this.config.rootPath, this.config.baseUrl);
diff --git a/packages/core/src/html/elements.ts b/packages/core/src/html/elements.ts
index b64a9a3bcf..bd8e4fc962 100644
--- a/packages/core/src/html/elements.ts
+++ b/packages/core/src/html/elements.ts
@@ -1,6 +1,6 @@
import cheerio from 'cheerio';
import pick from 'lodash/pick';
-import { Node, NodeOrText } from '../utils/node';
+import { MbNode, NodeOrText } from '../utils/node';
const _ = { pick };
@@ -8,15 +8,15 @@ export function createErrorNode(element: NodeOrText, error: any) {
const errorElement = cheerio.parseHTML(
`
${error.message}
`, undefined, true,
)[0];
- return Object.assign(element, _.pick(errorElement, ['name', 'attribs', 'children'])) as Node;
+ return Object.assign(element, _.pick(errorElement, ['name', 'attribs', 'children'])) as MbNode;
}
export function createEmptyNode() {
return cheerio.parseHTML('', undefined, true)[0];
}
-export function createSlotTemplateNode(slotName: string, content: string): Node[] {
+export function createSlotTemplateNode(slotName: string, content: string): MbNode[] {
return cheerio.parseHTML(
`${content}`, undefined, true,
- ) as unknown as Node[];
+ ) as unknown as MbNode[];
}
diff --git a/packages/core/src/html/includePanelProcessor.ts b/packages/core/src/html/includePanelProcessor.ts
index 2e670be5eb..4505130dd2 100644
--- a/packages/core/src/html/includePanelProcessor.ts
+++ b/packages/core/src/html/includePanelProcessor.ts
@@ -13,7 +13,7 @@ import * as urlUtil from '../utils/urlUtil';
import type { Context } from './Context';
import type { PageSources } from '../Page/PageSources';
import type VariableProcessor from '../variables/VariableProcessor';
-import { Node, NodeOrText } from '../utils/node';
+import { MbNode, NodeOrText } from '../utils/node';
require('../patches/htmlparser2');
@@ -26,7 +26,7 @@ const _ = { has, isEmpty };
/**
* Returns a boolean representing whether the file specified exists.
*/
-function _checkAndWarnFileExists(element: Node, context: Context, actualFilePath: string,
+function _checkAndWarnFileExists(element: MbNode, context: Context, actualFilePath: string,
pageSources: PageSources, isOptional = false) {
if (!fsUtil.fileExists(actualFilePath)) {
if (isOptional) {
@@ -48,7 +48,7 @@ function _checkAndWarnFileExists(element: Node, context: Context, actualFilePath
return true;
}
-function _getBoilerplateFilePath(element: Node, filePath: string, config: Record) {
+function _getBoilerplateFilePath(element: MbNode, filePath: string, config: Record) {
const isBoilerplate = _.has(element.attribs, 'boilerplate');
if (isBoilerplate) {
element.attribs.boilerplate = element.attribs.boilerplate || path.basename(filePath);
@@ -62,7 +62,7 @@ function _getBoilerplateFilePath(element: Node, filePath: string, config: Record
/**
* Retrieves several flags and file paths from the src attribute specified in the element.
*/
-function _getSrcFlagsAndFilePaths(element: Node, config: Record) {
+function _getSrcFlagsAndFilePaths(element: MbNode, config: Record) {
const isUrl = urlUtil.isUrl(element.attribs.src);
// We do this even if the src is not a url to get the hash, if any
@@ -104,7 +104,7 @@ function _getSrcFlagsAndFilePaths(element: Node, config: Record) {
* Otherwise, sets the fragment attribute of the panel as parsed from the src,
* and adds the appropriate include.
*/
-export function processPanelSrc(node: Node, context: Context, pageSources: PageSources,
+export function processPanelSrc(node: MbNode, context: Context, pageSources: PageSources,
config: Record): Context {
const hasSrc = _.has(node.attribs, 'src');
if (!hasSrc) {
@@ -148,7 +148,7 @@ export function processPanelSrc(node: Node, context: Context, pageSources: PageS
* Includes
*/
-function _deleteIncludeAttributes(node: Node) {
+function _deleteIncludeAttributes(node: MbNode) {
// Delete variable attributes in include tags as they are no longer needed
// e.g. ''
Object.keys(node.attribs).forEach((attribute) => {
@@ -170,7 +170,7 @@ function _deleteIncludeAttributes(node: Node) {
* Replaces it with an error node if the specified src is invalid,
* or an empty node if the src is invalid but optional.
*/
-export function processInclude(node: Node, context: Context, pageSources: PageSources,
+export function processInclude(node: MbNode, context: Context, pageSources: PageSources,
variableProcessor: VariableProcessor, renderMd: (text: string) => string,
renderMdInline: (text: string) => string,
config: Record): Context {
@@ -270,7 +270,7 @@ export function processInclude(node: Node, context: Context, pageSources: PageSo
* Replaces it with an error node if the specified src is invalid.
* Else, appends the content to the node.
*/
-export function processPopoverSrc(node: Node, context: Context, pageSources: PageSources,
+export function processPopoverSrc(node: MbNode, context: Context, pageSources: PageSources,
variableProcessor: VariableProcessor, renderMd: (text: string) => string,
config: Record): Context {
if (!_.has(node.attribs, 'src')) {
diff --git a/packages/core/src/utils/node.ts b/packages/core/src/utils/node.ts
index 15ce07b045..642607d200 100644
--- a/packages/core/src/utils/node.ts
+++ b/packages/core/src/utils/node.ts
@@ -3,10 +3,10 @@ import { DomElement } from 'htmlparser2';
export type TextElement = DomElement;
-export type Node = DomElement & cheerio.Element & {
+export type MbNode = DomElement & cheerio.Element & {
name: string,
attribs: { [key: string]: any },
children: NodeOrText[],
};
-export type NodeOrText = TextElement | Node;
+export type NodeOrText = TextElement | MbNode;