aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Markdown/Content.tsx
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-04-07 20:31:45 +0300
committereug-vs <eug-vs@keemail.me>2020-04-07 20:31:45 +0300
commitc851a68e15daedb8dbe572ce5927a8e61254d4c9 (patch)
tree5fe16e5c5c9540d3ae66e769dd3cf5e335cbf1d0 /src/lib/Markdown/Content.tsx
parent8b737b42fff0c0e21f9173e047cae9ed488493f4 (diff)
downloadreact-benzin-c851a68e15daedb8dbe572ce5927a8e61254d4c9.tar.gz
feat: support \| symbol, fix html parsing
Diffstat (limited to 'src/lib/Markdown/Content.tsx')
-rw-r--r--src/lib/Markdown/Content.tsx14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/lib/Markdown/Content.tsx b/src/lib/Markdown/Content.tsx
index 30f2a8a..5895df9 100644
--- a/src/lib/Markdown/Content.tsx
+++ b/src/lib/Markdown/Content.tsx
@@ -28,6 +28,10 @@ const denotesSelfClosingHtml = (line: string): string[] | null => {
return line.match(regex);
}
+const declaresNoLineBreak = (line: string): boolean => {
+ return line.match(/\\\|$/) !== null;
+}
+
const Content: React.FC<ParserPropTypes> = ({ rawLines }) => {
if (!rawLines.length) return null;
@@ -46,7 +50,7 @@ const Content: React.FC<ParserPropTypes> = ({ rawLines }) => {
} else if ((buffer = denotesOpenHtml(line))) {
const tag = buffer;
const closeIndex = rawLines.findIndex(line => denotesClosingHtml(line, tag));
- const htmlLines = rawLines.splice(0, closeIndex + 1).slice(0, closeIndex);
+ const htmlLines = rawLines.splice(0, closeIndex + 1);
htmlLines.unshift(line);
buffer = <div dangerouslySetInnerHTML={{ __html: htmlLines.join('\n') }}></div>;
} else if ((buffer = denotesSelfClosingHtml(line)) !== null) {
@@ -59,6 +63,14 @@ const Content: React.FC<ParserPropTypes> = ({ rawLines }) => {
<Text line={after} />
</>
);
+ } else if (declaresNoLineBreak(line)) {
+ const closeIndex = rawLines.findIndex(line => !declaresNoLineBreak(line));
+ const lineBreakLines = rawLines.splice(0, closeIndex).map(line => line.slice(0, -2));
+ lineBreakLines.unshift(line.slice(0, -2));
+ lineBreakLines.push(rawLines.splice(0, 1)[0]);
+ buffer = <p>{lineBreakLines.map(lineBreakLine => <Text line={lineBreakLine} />)}</p>;
+ } else if (denotesClosingHtml(line, '')) {
+ buffer = null;
} else {
buffer = <p><Text line={line} /></p>
}