build(aio): render ALL code-examples, not just the first
This commit is contained in:
parent
cda887896a
commit
447e534350
|
@ -12,7 +12,7 @@ module.exports = function renderExamples(getExampleRegion) {
|
|||
docs.forEach(doc => {
|
||||
if (doc.renderedContent) {
|
||||
// We match either `code-example` or `code-pane` elements that have a path attribute
|
||||
doc.renderedContent = doc.renderedContent.replace(/<(code-example|code-pane)([^>]*)>[^<]*<\/\1>/, (original, element, attributes) => {
|
||||
doc.renderedContent = doc.renderedContent.replace(/<(code-example|code-pane)([^>]*)>[^<]*<\/\1>/g, (original, element, attributes) => {
|
||||
const attrMap = parseAttributes(attributes);
|
||||
if (attrMap.path) {
|
||||
// We found a path attribute so look up the example and rebuild the HTML
|
||||
|
|
|
@ -49,6 +49,14 @@ describe('renderExamples processor', () => {
|
|||
expect(docs[0].renderedContent).toEqual(`<${CODE_TAG}>\nwhole file\n</${CODE_TAG}>`);
|
||||
});
|
||||
|
||||
it(`should replace all instances of <${CODE_TAG}> tags`, () => {
|
||||
const docs = [
|
||||
{ renderedContent: `<${CODE_TAG} path="test/url">Some code</${CODE_TAG}><${CODE_TAG} path="test/url" region="region-1">Other code</${CODE_TAG}>`}
|
||||
];
|
||||
processor.$process(docs);
|
||||
expect(docs[0].renderedContent).toEqual(`<${CODE_TAG}>\nwhole file\n</${CODE_TAG}><${CODE_TAG}>\nregion 1 contents\n</${CODE_TAG}>`);
|
||||
});
|
||||
|
||||
it('should contain the region contents from the example file if a region is specified', () => {
|
||||
const docs = [
|
||||
{ renderedContent: `<${CODE_TAG} path="test/url" region="region-1">Some code</${CODE_TAG}>` }
|
||||
|
|
Loading…
Reference in New Issue