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
34 changes: 12 additions & 22 deletions packages/core/src/html/MdAttributeRenderer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const cheerio = require('cheerio');

const { createSlotTemplateNode } = require('./elements');
const { getVslotShorthandName } = require('./vueSlotSyntaxProcessor');

const _ = {};
Expand Down Expand Up @@ -35,8 +36,7 @@ class MdAttributeRenderer {
rendered = this.markdownProcessor.renderMd(node.attribs[attribute]);
}

const attributeSlotElement = cheerio.parseHTML(
`<template #${slotName}>${rendered}</template>`, true);
const attributeSlotElement = createSlotTemplateNode(slotName, rendered);
node.children
= node.children ? attributeSlotElement.concat(node.children) : attributeSlotElement;
}
Expand Down Expand Up @@ -114,54 +114,44 @@ class MdAttributeRenderer {
*/

processQuestion(node) {
this.processAttributeWithoutOverride(node, 'header', false, 'header');
this.processAttributeWithoutOverride(node, 'hint', false, 'hint');
this.processAttributeWithoutOverride(node, 'answer', false, 'answer');
this.processAttributeWithoutOverride(node, 'header', false);
this.processAttributeWithoutOverride(node, 'hint', false);
this.processAttributeWithoutOverride(node, 'answer', false);
}

processQOption(node) {
this.processAttributeWithoutOverride(node, 'reason', false, 'reason');
this.processAttributeWithoutOverride(node, 'reason', false);
}

processQuiz(node) {
this.processAttributeWithoutOverride(node, 'intro', false, 'intro');
this.processAttributeWithoutOverride(node, 'intro', false);
}

/*
* Tabs
*/

processTabAttributes(node) {
this.processAttributeWithoutOverride(node, 'header', true, 'header');
this.processAttributeWithoutOverride(node, 'header', true);
}

/*
* Tip boxes
*/

processBoxAttributes(node) {
this.processAttributeWithoutOverride(node, 'icon', true, 'icon');
this.processAttributeWithoutOverride(node, 'header', false, 'header');
this.processAttributeWithoutOverride(node, 'icon', true);
this.processAttributeWithoutOverride(node, 'header', false);
}

/*
* Dropdowns
*/

processDropdownAttributes(node) {
const hasHeaderSlot = node.children
&& node.children.some(child => getVslotShorthandName(child) === 'header');

// If header slot is present, the header attribute has no effect, and we can simply remove it.
if (hasHeaderSlot) {
if (_.has(node.attribs, 'header')) {
logger.warn(`${node.name} has a header slot, 'header' attribute has no effect.`);
}
delete node.attribs.header;
return;
if (!this.hasSlotOverridingAttribute(node, 'header')) {
this.processAttributeWithoutOverride(node, 'header', true);
}

this.processAttributeWithoutOverride(node, 'header', true, 'header');
}

/**
Expand Down
16 changes: 9 additions & 7 deletions packages/core/src/html/includePanelProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function processPanelSrc(node, context, pageSources, config) {
asIfTo: filePath,
});

return node;
return context;
}

/*
Expand Down Expand Up @@ -168,6 +168,7 @@ function processInclude(node, context, pageSources, variableProcessor, renderMd,
const error = new Error(`Empty src attribute in include in: ${context.cwf}`);
logger.error(error);
cheerio(node).replaceWith(createErrorNode(node, error));
return context;
}

const {
Expand All @@ -177,6 +178,12 @@ function processInclude(node, context, pageSources, variableProcessor, renderMd,
actualFilePath,
} = _getSrcFlagsAndFilePaths(node, config);

// No need to process url contents
if (isUrl) {
_deleteIncludeAttributes(node);
return context;
}

const isOptional = _.has(node.attribs, 'optional');
const fileExistsNode = _getFileExistsNode(node, context, actualFilePath, pageSources, isOptional);
if (fileExistsNode) {
Expand All @@ -189,12 +196,6 @@ function processInclude(node, context, pageSources, variableProcessor, renderMd,

node.name = isInline ? 'span' : 'div';

// No need to process url contents
if (isUrl) {
_deleteIncludeAttributes(node);
return node;
}

pageSources.staticIncludeSrc.push({
from: context.cwf,
to: actualFilePath,
Expand Down Expand Up @@ -247,6 +248,7 @@ function processInclude(node, context, pageSources, variableProcessor, renderMd,
const error = new CyclicReferenceError(childContext.callStack);
logger.error(error);
cheerio(node).replaceWith(createErrorNode(node, error));
return context;
}
}

Expand Down