aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Markdown/SyntacticSpan.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/SyntacticSpan.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/SyntacticSpan.tsx')
-rw-r--r--src/lib/Markdown/SyntacticSpan.tsx21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/lib/Markdown/SyntacticSpan.tsx b/src/lib/Markdown/SyntacticSpan.tsx
index f3c2125..11cc024 100644
--- a/src/lib/Markdown/SyntacticSpan.tsx
+++ b/src/lib/Markdown/SyntacticSpan.tsx
@@ -19,24 +19,25 @@ interface Emoji {
const enclosureRegex = (e: string): RegexPair => ({
local: new RegExp(`${e}([^${e}]+)${e}`),
- global: new RegExp(`(${e}[^${e}]+${e})`)
+ global: new RegExp(`(${e}[^${e}]+${e})`),
});
const regex: Record<string, RegexPair> = {
conceal: {
global: /(!?\[.+?\]\(.+?\))(?!])/g,
- local: /!?\[(.*\]?.*)\]\((.+?)\)/
+ local: /!?\[(.*\]?.*)\]\((.+?)\)/,
},
rawLink: {
+ // eslint-disable-next-line max-len
global: /((?:(?:[A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www\.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)(?:(?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[.!/\\\w]*))?)/,
- local: /&^/
+ local: /&^/,
},
emoji: enclosureRegex(':'),
bold: enclosureRegex('\\*\\*'),
italic: enclosureRegex('\\*'),
code: enclosureRegex('`'),
strikeThrough: enclosureRegex('~~'),
-}
+};
const splitter = new RegExp(Object.values(regex).map(pair => pair.global.source).join('|'));
@@ -46,13 +47,13 @@ Object.keys(emojiLib).forEach(name => emojiList.push({ name, char: emojiLib[name
const useStyles = makeStyles(theme => ({
code: {
background: theme.palette.background.default,
- borderRadius: theme.spacing(.5),
- padding: theme.spacing(.5),
+ borderRadius: theme.spacing(0.5),
+ padding: theme.spacing(0.5),
fontFamily: 'Monospace',
},
image: {
maxWidth: '100%',
- maxHeight: '100%'
+ maxHeight: '100%',
},
}));
@@ -68,7 +69,7 @@ const SyntacticSpan: React.FC<PropTypes> = ({ span }) => {
const matchEmoji = span.match(regex.emoji.local);
if (matchEmoji) {
- const emoji = emojiList.find(emoji => emoji.name === matchEmoji[1]);
+ const emoji = emojiList.find(e => e.name === matchEmoji[1]);
return <span>{emoji ? emoji.char : span}</span>;
}
@@ -82,12 +83,12 @@ const SyntacticSpan: React.FC<PropTypes> = ({ span }) => {
if (matchItalic) return <i>{matchItalic[1]}</i>;
const matchStrikeThrough = span.match(regex.strikeThrough.local);
- if (matchStrikeThrough) return <span style={{textDecoration: 'line-through' }}>{matchStrikeThrough[1]}</span>;
+ if (matchStrikeThrough) return <span style={{ textDecoration: 'line-through' }}>{matchStrikeThrough[1]}</span>;
if (span.match(regex.rawLink.global)) return <Link href={span}>{span}</Link>;
return <>{span}</>;
-}
+};
export { splitter };