build(aio): allow render-examples to complete even if examples are broken
By setting `renderExamples.ignoreBrokenExamples = true` the doc-gen will not fail if there is something wrong with an example. Instead it will just log a warning.
This commit is contained in:

committed by
Victor Berchet

parent
feae55b264
commit
3a03ff6b2d
@ -4,10 +4,11 @@ const { parseAttributes, renderAttributes } = require('../../helpers/utils');
|
||||
* Search the renderedContent looking for code examples that have a path (and optionally a region) attribute.
|
||||
* When they are found replace their content with the appropriate doc-region parsed previously from an example file.
|
||||
*/
|
||||
module.exports = function renderExamples(getExampleRegion) {
|
||||
module.exports = function renderExamples(getExampleRegion, log, createDocMessage) {
|
||||
return {
|
||||
$runAfter: ['docs-rendered'],
|
||||
$runBefore: ['writing-files'],
|
||||
ignoreBrokenExamples: false,
|
||||
$process: function(docs) {
|
||||
docs.forEach(doc => {
|
||||
if (doc.renderedContent) {
|
||||
@ -17,34 +18,41 @@ module.exports = function renderExamples(getExampleRegion) {
|
||||
(original, openingTag, attributes, closingTag) => {
|
||||
const attrMap = parseAttributes(attributes);
|
||||
if (attrMap.path) {
|
||||
if (closingTag !== openingTag) {
|
||||
// The markdown renderer will wrap what it thinks is a paragraph in `<p>` and `</p>` tags.
|
||||
// If you do not leave a blank line between a paragraph of text and a `<code-example>` then
|
||||
// the markdown renderer may add a paragraph marker "in-between" the opening and closing
|
||||
// tags of the code-example. For example:
|
||||
//
|
||||
// ```
|
||||
// Some paragraph
|
||||
// <code-example path="...">
|
||||
//
|
||||
// </code-example>
|
||||
// ```
|
||||
//
|
||||
// will be rendered as:
|
||||
//
|
||||
// ```
|
||||
// <p>Some paragraph
|
||||
// <code-example path="...">
|
||||
// </p>
|
||||
// </code-example>
|
||||
// ```
|
||||
throw new Error(
|
||||
'Badly formed example: ' + original + ' - closing tag does not match opening tag.\n' +
|
||||
' - Perhaps you forgot to put a blank line before the example?');
|
||||
try {
|
||||
if (closingTag !== openingTag) {
|
||||
// The markdown renderer will wrap what it thinks is a paragraph in `<p>` and `</p>` tags.
|
||||
// If you do not leave a blank line between a paragraph of text and a `<code-example>` then
|
||||
// the markdown renderer may add a paragraph marker "in-between" the opening and closing
|
||||
// tags of the code-example. For example:
|
||||
//
|
||||
// ```
|
||||
// Some paragraph
|
||||
// <code-example path="...">
|
||||
//
|
||||
// </code-example>
|
||||
// ```
|
||||
//
|
||||
// will be rendered as:
|
||||
//
|
||||
// ```
|
||||
// <p>Some paragraph
|
||||
// <code-example path="...">
|
||||
// </p>
|
||||
// </code-example>
|
||||
// ```
|
||||
throw new Error(
|
||||
'Badly formed example: ' + original + ' - closing tag does not match opening tag.\n' +
|
||||
' - Perhaps you forgot to put a blank line before the example?');
|
||||
}
|
||||
// We found a path attribute so look up the example and rebuild the HTML
|
||||
const exampleContent = getExampleRegion(doc, attrMap.path, attrMap.region);
|
||||
return `<${openingTag}${renderAttributes(attrMap)}>\n${exampleContent}\n</${openingTag}>`;
|
||||
} catch(e) {
|
||||
log.warn(createDocMessage(e.message, doc));
|
||||
if (!this.ignoreBrokenExamples) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
// We found a path attribute so look up the example and rebuild the HTML
|
||||
const exampleContent = getExampleRegion(doc, attrMap.path, attrMap.region);
|
||||
return `<${openingTag}${renderAttributes(attrMap)}>\n${exampleContent}\n</${openingTag}>`;
|
||||
}
|
||||
// No path attribute so just ignore this one
|
||||
return original;
|
||||
@ -54,4 +62,3 @@ module.exports = function renderExamples(getExampleRegion) {
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user