From 9f4a5280112d8502128c14acac3e63ad17c84bbe Mon Sep 17 00:00:00 2001 From: Fienny Angelina Date: Tue, 26 Feb 2019 23:03:54 +0800 Subject: [PATCH 1/2] Fix bug Code block tabs broke the referenced links - The reason is that the previous Codeblock implementation separates the tabs, the markdown before tabs, and the markdown after tabs into separate Remarkable component, thus they don't share information regarding the reference link - To solve this, change the Doc implementation so that one Doc have only one Remarkable component by transforming the codeblock into html string and add it as part of the markdown, letting the Remarkable take care of the html string - However, this approach made us need to ensure that there is no newline in the codetab, otherwise, the formatting inside the code will be broken. Thus, I replace every newline inside the code tag with a br tag Fix #1215 --- v1/lib/core/Doc.js | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/v1/lib/core/Doc.js b/v1/lib/core/Doc.js index c42fe493bfa2..c4353262459e 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,28 @@ 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 +63,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 +134,9 @@ class Doc extends React.Component {

{this.props.title}

)} -
{this.renderContent()}
+
+ {this.renderContent()} +
); } From afdfb89f35490061b6c45fb8c67f0ae72c837c68 Mon Sep 17 00:00:00 2001 From: Fienny Angelina Date: Tue, 26 Feb 2019 23:19:26 +0800 Subject: [PATCH 2/2] Fix prettier --- v1/lib/core/Doc.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/v1/lib/core/Doc.js b/v1/lib/core/Doc.js index c4353262459e..d31505f0bb5f 100644 --- a/v1/lib/core/Doc.js +++ b/v1/lib/core/Doc.js @@ -6,7 +6,7 @@ */ const React = require('react'); -const { renderToStaticMarkup } = require('react-dom/server'); +const {renderToStaticMarkup} = require('react-dom/server'); const MarkdownBlock = require('./MarkdownBlock.js'); const CodeTabsMarkdownBlock = require('./CodeTabsMarkdownBlock.js'); @@ -33,23 +33,21 @@ const splitTabsToTitleAndContent = content => { }; const cleanTheCodeTag = content => { - const contents = content.split( - /(
)(.*?)(<\/pre>)/gms,
-  );
+  const contents = content.split(/(
)(.*?)(<\/pre>)/gms);
   let inCodeBlock = false;
-  const cleanContents = contents.map((c) => {
+  const cleanContents = contents.map(c => {
     if (c === '
') {
       inCodeBlock = true;
       return c;
-    } if (c === '
') { + } + if (c === '
') { inCodeBlock = false; return c; - } if (inCodeBlock) { - return c.replace(/\n/g, "
"); } - return c; - - + if (inCodeBlock) { + return c.replace(/\n/g, '
'); + } + return c; }); return cleanContents.join(''); }; @@ -63,7 +61,7 @@ class Doc extends React.Component { /(\n)(.*?)(\n)/gms, ); - const renderResult = contents.map((c) => { + const renderResult = contents.map(c => { if (c === '\n') { inCodeTabs = true; return ''; @@ -76,7 +74,7 @@ class Doc extends React.Component { const codeTabsMarkdownBlock = renderToStaticMarkup( {splitTabsToTitleAndContent(c)} - + , ); return cleanTheCodeTag(codeTabsMarkdownBlock); }