From 447e534350b0017fa4d09ac907bf27b7ea30ddbd Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Mon, 27 Mar 2017 16:37:44 +0100 Subject: [PATCH] build(aio): render ALL code-examples, not just the first --- .../examples-package/processors/render-examples.js | 2 +- .../examples-package/processors/render-examples.spec.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/aio/transforms/examples-package/processors/render-examples.js b/aio/transforms/examples-package/processors/render-examples.js index f2c2d0bba5..35ecde9ac7 100644 --- a/aio/transforms/examples-package/processors/render-examples.js +++ b/aio/transforms/examples-package/processors/render-examples.js @@ -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 diff --git a/aio/transforms/examples-package/processors/render-examples.spec.js b/aio/transforms/examples-package/processors/render-examples.spec.js index 0b956f7593..c7a13413eb 100644 --- a/aio/transforms/examples-package/processors/render-examples.spec.js +++ b/aio/transforms/examples-package/processors/render-examples.spec.js @@ -49,6 +49,14 @@ describe('renderExamples processor', () => { expect(docs[0].renderedContent).toEqual(`<${CODE_TAG}>\nwhole file\n`); }); + it(`should replace all instances of <${CODE_TAG}> tags`, () => { + const docs = [ + { renderedContent: `<${CODE_TAG} path="test/url">Some code<${CODE_TAG} path="test/url" region="region-1">Other code`} + ]; + processor.$process(docs); + expect(docs[0].renderedContent).toEqual(`<${CODE_TAG}>\nwhole file\n<${CODE_TAG}>\nregion 1 contents\n`); + }); + 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` }