From 9d3f01749d2cb36950634ece2cffefc95ea4e3c5 Mon Sep 17 00:00:00 2001 From: Stevie Robinson Date: Wed, 26 Jul 2023 23:08:13 +0200 Subject: [PATCH] extend InlineMarkdown to handle code blocks in backticks --- .../src/Components/Markdown/InlineMarkdown.js | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/frontend/src/Components/Markdown/InlineMarkdown.js b/frontend/src/Components/Markdown/InlineMarkdown.js index dc9ea9bf3..b04400c27 100644 --- a/frontend/src/Components/Markdown/InlineMarkdown.js +++ b/frontend/src/Components/Markdown/InlineMarkdown.js @@ -10,7 +10,8 @@ class InlineMarkdown extends Component { render() { const { className, - data + data, + code } = this.props; // For now only replace links @@ -33,13 +34,28 @@ class InlineMarkdown extends Component { } } + // replace blocks in the string surrounded in backticks with + // if the first character is a backtick then we ignore the first split and start directly with a code block + if (code) { + const codeSplit = code.split('`'); + const startIndex = (code.startsWith('`') === true) ? 1 : 0; + + for (let index = startIndex; index < codeSplit.length; index++) { + if (index % 2 === 1) { + markdownBlocks.push({codeSplit[index]}); + } else { + markdownBlocks.push(codeSplit[index]); + } + } + } return {markdownBlocks}; } } InlineMarkdown.propTypes = { className: PropTypes.string, - data: PropTypes.string + data: PropTypes.string, + code: PropTypes.string }; export default InlineMarkdown;