diff --git a/v1/lib/core/Doc.js b/v1/lib/core/Doc.js index c42fe493bfa2..d31505f0bb5f 100644 --- a/v1/lib/core/Doc.js +++ b/v1/lib/core/Doc.js @@ -6,6 +6,7 @@ */ const React = require('react'); +const {renderToStaticMarkup} = require('react-dom/server'); const MarkdownBlock = require('./MarkdownBlock.js'); const CodeTabsMarkdownBlock = require('./CodeTabsMarkdownBlock.js'); @@ -31,6 +32,26 @@ const splitTabsToTitleAndContent = content => { })); }; +const cleanTheCodeTag = content => { + const contents = content.split(/(
)(.*?)(<\/pre>)/gms); + let inCodeBlock = false; + const cleanContents = contents.map(c => { + if (c === '') { + inCodeBlock = true; + return c; + } + if (c === '') { + inCodeBlock = false; + return c; + } + if (inCodeBlock) { + return c.replace(/\n/g, '
'); + } + return c; + }); + return cleanContents.join(''); +}; + // inner doc component for article itself class Doc extends React.Component { renderContent() { @@ -40,26 +61,27 @@ class Doc extends React.Component { /(\n)(.*?)(\n)/gms, ); - const renderResult = contents.map((c, index) => { + const renderResult = contents.map(c => { if (c === '\n') { inCodeTabs = true; - return null; + return ''; } if (c === '\n') { inCodeTabs = false; - return null; + return ''; } if (inCodeTabs) { - return ( + const codeTabsMarkdownBlock = renderToStaticMarkup({splitTabsToTitleAndContent(c)} - + , ); + return cleanTheCodeTag(codeTabsMarkdownBlock); } - return{c} ; + return c; }); - return renderResult; + return renderResult.join(''); } render() { @@ -110,7 +132,9 @@ class Doc extends React.Component {{this.props.title}
)} -{this.renderContent()} ++ ); }{this.renderContent()} +