aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Markdown/Content.tsx
diff options
context:
space:
mode:
authorEugene Sokolov <eug-vs@keemail.me>2020-04-18 21:17:50 +0300
committerGitHub <noreply@github.com>2020-04-18 21:17:50 +0300
commit1d1df03b64d31a9606e494d086eb7ae3bee92681 (patch)
tree5bea19d0bc6afc0440f71fb8df962e29fbb568e2 /src/lib/Markdown/Content.tsx
parentad42e742c04c8302c2bcaf67c07ef215bba04f3b (diff)
parenta31244374f5609e89d8ff22e4111ab04d94886a2 (diff)
downloadreact-benzin-1d1df03b64d31a9606e494d086eb7ae3bee92681.tar.gz
Merge pull request #12 from eug-vs/codestyle
Configure ESlint properly
Diffstat (limited to 'src/lib/Markdown/Content.tsx')
-rw-r--r--src/lib/Markdown/Content.tsx39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/lib/Markdown/Content.tsx b/src/lib/Markdown/Content.tsx
index 5816214..88409fa 100644
--- a/src/lib/Markdown/Content.tsx
+++ b/src/lib/Markdown/Content.tsx
@@ -6,31 +6,32 @@ import { ParserPropTypes } from './types';
const denotesCodeBlock = (line: string): boolean => {
- return line.match(/^\s*```.*$/) !== null; }
+ return line.match(/^\s*```.*$/) !== null;
+};
const denotesDottedList = (line: string): boolean => {
return line.match(/^ ?[-*] .*$/) !== null;
-}
+};
-const denotesOpenHtml= (line: string): string => {
+const denotesOpenHtml = (line: string): string => {
const regex = /<([^/\s]*)[^<]*[^/]>/g;
const match = regex.exec(line);
return match ? match[1] : '';
-}
+};
-const denotesClosingHtml= (line: string, tag: string): boolean => {
+const denotesClosingHtml = (line: string, tag: string): boolean => {
const regex = new RegExp(`</${tag}[^<]*>`);
return line.match(regex) !== null;
-}
+};
const denotesSelfClosingHtml = (line: string): string[] | null => {
const regex = /(<[^/\s]*[^<]*\/>)/g;
return line.match(regex);
-}
+};
const declaresNoLineBreak = (line: string): boolean => {
return line.match(/\\\|$/) !== null;
-}
+};
const Content: React.FC<ParserPropTypes> = ({ rawLines }) => {
if (!rawLines.length) return null;
@@ -39,40 +40,42 @@ const Content: React.FC<ParserPropTypes> = ({ rawLines }) => {
let buffer;
if (denotesCodeBlock(line)) {
- const closeIndex = rawLines.findIndex(line => denotesCodeBlock(line));
+ const closeIndex = rawLines.findIndex(rawLine => denotesCodeBlock(rawLine));
const codeBlockLines = rawLines.splice(0, closeIndex + 1).slice(0, closeIndex);
- buffer = <CodeBlock rawLines={codeBlockLines} />
+ buffer = <CodeBlock rawLines={codeBlockLines} />;
} else if (denotesDottedList(line)) {
- const closeIndex = rawLines.findIndex(line => !denotesDottedList(line));
+ const closeIndex = rawLines.findIndex(rawLine => !denotesDottedList(rawLine));
const dottedListLines = rawLines.splice(0, closeIndex).slice(0, closeIndex);
dottedListLines.unshift(line);
buffer = <ul>{dottedListLines.map(li => <li><Text line={li.slice(2)} /></li>)}</ul>;
} else if ((buffer = denotesOpenHtml(line))) {
const tag = buffer;
- const closeIndex = denotesClosingHtml(line, tag) ? -1 : rawLines.findIndex(line => denotesClosingHtml(line, tag));
+ const closeIndex = denotesClosingHtml(line, tag) ? -1 : rawLines.findIndex(
+ rawLine => denotesClosingHtml(rawLine, tag),
+ );
const htmlLines = rawLines.splice(0, closeIndex + 1);
htmlLines.unshift(line);
- buffer = <div dangerouslySetInnerHTML={{ __html: htmlLines.join('\n') }}></div>;
+ buffer = <div dangerouslySetInnerHTML={{ __html: htmlLines.join('\n') }} />;
} else if ((buffer = denotesSelfClosingHtml(line)) !== null) {
const match = buffer[0];
const [before, after] = line.split(match);
buffer = (
<>
<Text line={before} />
- <div dangerouslySetInnerHTML={{ __html: match }}></div>
+ <div dangerouslySetInnerHTML={{ __html: match }} />
<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));
+ const closeIndex = rawLines.findIndex(rawLine => !declaresNoLineBreak(rawLine));
+ const lineBreakLines = rawLines.splice(0, closeIndex).map(rawLine => rawLine.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>
+ buffer = <p><Text line={line} /></p>;
}
return (
@@ -81,7 +84,7 @@ const Content: React.FC<ParserPropTypes> = ({ rawLines }) => {
<Content rawLines={rawLines} />
</>
);
-}
+};
export default Content;