@@ -16,6 +16,7 @@ const pathUtils = require('./path-utils')
1616const Permalink = require ( './permalink' )
1717const languages = require ( './languages' )
1818const renderContent = require ( './render-content' )
19+ const { renderReact } = require ( './react/engine' )
1920const frontmatter = require ( './frontmatter' )
2021const products = require ( './all-products' )
2122const slash = require ( 'slash' )
@@ -133,10 +134,31 @@ class Page {
133134 this . title = await renderContent ( this . rawTitle , context , { textOnly : true , encodeEntities : true } )
134135 this . shortTitle = await renderContent ( this . shortTitle , context , { textOnly : true , encodeEntities : true } )
135136
136- const markdown = this . mapTopic
137+ let markdown = this . mapTopic
137138 ? getMapTopicContent ( this , context . pages , context . redirects )
138139 : this . markdown
139140
141+ // If the article is interactive parse the React!
142+ if ( this . interactive ) {
143+ // Search for the react code comments to find the react components
144+ const reactComponents = markdown . match ( / < ! - - r e a c t - - > ( .* ?) < ! - - e n d - r e a c t - - > / gs)
145+
146+ // Render each of the react components in the markdown
147+ await Promise . all ( reactComponents . map ( async ( reactComponent ) => {
148+ let componentStr = reactComponent
149+
150+ // Remove the React comment indicators
151+ componentStr = componentStr . replace ( '<!--react-->\n' , '' ) . replace ( '<!--react-->' , '' )
152+ componentStr = componentStr . replace ( '\n<!--end-react-->' , '' ) . replace ( '<!--end-react-->' , '' )
153+
154+ // Get the rendered component
155+ const renderedComponent = await renderReact ( componentStr )
156+
157+ // Replace the react component with the rendered markdown
158+ markdown = markdown . replace ( reactComponent , renderedComponent )
159+ } ) )
160+ }
161+
140162 const html = await renderContent ( markdown , context )
141163
142164 // product frontmatter may contain liquid
0 commit comments