diff --git a/shared/common-adapters/markdown/index.stories.js b/shared/common-adapters/markdown/index.stories.js index aa68b393444e..c4741707555a 100644 --- a/shared/common-adapters/markdown/index.stories.js +++ b/shared/common-adapters/markdown/index.stories.js @@ -102,6 +102,7 @@ something unrelated > Separate paragraph `, + 'Quotes super nested': `> > > > > > > > > foo bar`, 'Quotes 3': `> _foo_ and *bar*! \`\`\` a = 1 \`\`\` diff --git a/shared/common-adapters/markdown/shared.js b/shared/common-adapters/markdown/shared.js index a7ec48ab43df..41e470ffde8e 100644 --- a/shared/common-adapters/markdown/shared.js +++ b/shared/common-adapters/markdown/shared.js @@ -278,11 +278,17 @@ const rules = { // e.g. https://regex101.com/r/ZiDBsO/8 parse: (capture, parse, state) => { const content = capture[0].replace(/^ *> */gm, '') + const blockQuoteRecursionLevel = state.blockQuoteRecursionLevel || 0 + const nextState = {...state, blockQuoteRecursionLevel: blockQuoteRecursionLevel + 1} + return { - content: parse(content, state), + content: parse(content, nextState), } }, match: (source, state, lookbehind) => { + if (state.blockQuoteRecursionLevel > 6) { + return null + } const regex = /^( *>(?:[^\n](?!```))+\n?)+/ // make sure the look behind is empty const emptyLookbehind = /^$|\n *$/ @@ -426,7 +432,7 @@ class SimpleMarkdownComponent extends PureComponent + {this.props.children || ''} ) @@ -452,7 +458,7 @@ class SimpleMarkdownComponent extends PureComponent + {this.props.children || ''} ) diff --git a/shared/stories/__tests__/__snapshots__/Storyshots.test.js.snap b/shared/stories/__tests__/__snapshots__/Storyshots.test.js.snap index fafe4b23e353..6183dd6b2e1a 100644 --- a/shared/stories/__tests__/__snapshots__/Storyshots.test.js.snap +++ b/shared/stories/__tests__/__snapshots__/Storyshots.test.js.snap @@ -145122,6 +145122,669 @@ Array [ ] `; +exports[`Storyshots Common/Markdown Quotes super nested[comparison] 1`] = ` +Array [ +
+
+
+
+ +
+
+
+
+
+
+
+ + > > foo bar + + +
+
+
+
+
+
+
+
+ +
+
+ + > > > > > > > > foo bar + +
+
+
+
+
+
+
+ , +
, +] +`; + +exports[`Storyshots Common/Markdown Quotes super nested[o] 1`] = ` +Array [ +
+
+
+
+ +
+
+ + > > > > > > > > foo bar + +
+
+
+
+
+
+ + Show AST + +
+
+
+
+
+
+ + Show Preview + +
+
+
+
+
+
+
+ , +
, +] +`; + +exports[`Storyshots Common/Markdown Quotes super nested[s] 1`] = ` +Array [ +
+
+
+
+ +
+
+
+
+
+
+
+ + > > foo bar + + +
+
+
+
+
+
+
+
+
+
+
+ + Show AST + +
+
+
+
+
+
+ + Show Preview + +
+
+
+
+
+
+
+ , +
, +] +`; + exports[`Storyshots Common/Markdown Quotes[comparison] 1`] = ` Array [