aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Markdown/InlineSyntax.tsx
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-04-05 22:06:54 +0300
committereug-vs <eug-vs@keemail.me>2020-04-05 22:06:54 +0300
commit828946eb02bdfaa7ec5631f1e854881f874f7b7e (patch)
treea34e88a752ce49965433a1794f660a1e46c30747 /src/lib/Markdown/InlineSyntax.tsx
parent09f8c6865fb9a7e239cc907e313db44cccb7b5e8 (diff)
downloadreact-benzin-828946eb02bdfaa7ec5631f1e854881f874f7b7e.tar.gz
refactor: rename InlineSyntax -> SyntacticSpan
Diffstat (limited to 'src/lib/Markdown/InlineSyntax.tsx')
-rw-r--r--src/lib/Markdown/InlineSyntax.tsx93
1 files changed, 0 insertions, 93 deletions
diff --git a/src/lib/Markdown/InlineSyntax.tsx b/src/lib/Markdown/InlineSyntax.tsx
deleted file mode 100644
index 53cdaf0..0000000
--- a/src/lib/Markdown/InlineSyntax.tsx
+++ /dev/null
@@ -1,93 +0,0 @@
-import React from 'react';
-import { Link, makeStyles } from '@material-ui/core';
-
-import { lib as emojiLib } from 'emojilib';
-import { InlineParserPropTypes } from './types';
-
-interface RegexPair {
- global: RegExp;
- local: RegExp;
-}
-
-interface Emoji {
- name: string;
- char: string;
-}
-
-const enclosureRegex = (e: string): RegexPair => ({
- local: new RegExp(`${e}([^${e}]+)${e}`),
- global: new RegExp(`(${e}[^${e}]+${e})`)
-});
-
-const regex: Record<string, RegexPair> = {
- conceal: {
- global: /(!?\[.+?\]\(.+?\))/g,
- local: /!?\[(.+?)\]\((.+?)\)/
- },
- rawLink: {
- global: /((?:(?:[A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www\.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)(?:(?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[.!/\\\w]*))?)/,
- local: /&^/
- },
- emoji: enclosureRegex(':'),
- bold: enclosureRegex('\\*\\*'),
- italic: enclosureRegex('\\*'),
- code: enclosureRegex('`'),
- strikeThrough: enclosureRegex('~~'),
-}
-
-const splitter = new RegExp(Object.values(regex).map(pair => pair.global.source).join('|'));
-
-const emojiList: Emoji[] = [];
-Object.keys(emojiLib).forEach(name => emojiList.push({ name, char: emojiLib[name].char }));
-console.log({emojiList})
-
-const useStyles = makeStyles(theme => ({
- code: {
- background: theme.palette.background.default,
- borderRadius: theme.spacing(.5),
- padding: theme.spacing(.5),
- fontFamily: 'Monospace',
- },
- image: {
- maxWidth: '100%',
- maxHeight: '100%'
- },
-}));
-
-const InlineSyntax: React.FC<InlineParserPropTypes> = ({ line }) => {
- const classes = useStyles();
- if (!line) return null;
-
- const matchConceal = regex.conceal.local.exec(line);
- if (matchConceal) {
- if (line[0] === '!') return <img src={matchConceal[2]} alt={matchConceal[1]} className={classes.image} />;
- return <Link href={matchConceal[2]}>{matchConceal[1]}</Link>;
- }
-
- const matchEmoji = line.match(regex.emoji.local);
- if (matchEmoji) {
- const emoji = emojiList.find(emoji => emoji.name === matchEmoji[1]);
- return <span>{emoji ? emoji.char : line}</span>;
- }
-
- const matchCode = line.match(regex.code.local);
- if (matchCode) return <span className={classes.code}>{matchCode[1]}</span>;
-
- const matchBold = line.match(regex.bold.local);
- if (matchBold) return <b>{matchBold[1]}</b>;
-
- const matchItalic = line.match(regex.italic.local);
- if (matchItalic) return <i>{matchItalic[1]}</i>;
-
- const matchStrikeThrough = line.match(regex.strikeThrough.local);
- if (matchStrikeThrough) return <span style={{textDecoration: 'line-through' }}>{matchStrikeThrough[1]}</span>;
-
- if (line.match(regex.rawLink.global)) return <Link href={line}>{line}</Link>;
-
- return <>{line}</>;
-}
-
-
-export { splitter };
-export default InlineSyntax;
-