From 1a00cd504ff60f1749327ebc3896a4641d28670e Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 5 Apr 2020 16:31:28 +0300 Subject: feat: install emojilib, beautify inline code --- src/lib/Markdown/CodeBlock.tsx | 1 + src/lib/Markdown/InlineSyntax.tsx | 29 +++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) (limited to 'src/lib') diff --git a/src/lib/Markdown/CodeBlock.tsx b/src/lib/Markdown/CodeBlock.tsx index cbb3078..c4478eb 100644 --- a/src/lib/Markdown/CodeBlock.tsx +++ b/src/lib/Markdown/CodeBlock.tsx @@ -9,6 +9,7 @@ const useStyles = makeStyles(theme => ({ background: theme.palette.background.default, padding: theme.spacing(2), overflowX: 'auto', + fontFamily: 'Monospace', }, })); diff --git a/src/lib/Markdown/InlineSyntax.tsx b/src/lib/Markdown/InlineSyntax.tsx index bf5669d..48c0374 100644 --- a/src/lib/Markdown/InlineSyntax.tsx +++ b/src/lib/Markdown/InlineSyntax.tsx @@ -1,7 +1,8 @@ import React from 'react'; -import { Link } from '@material-ui/core'; -import axios from 'axios'; +import { Link, makeStyles } from '@material-ui/core'; +// @ts-ignore-next-line; +import { lib as emojiLib } from 'emojilib'; import { InlineParserPropTypes } from './types'; interface RegexPair { @@ -38,17 +39,29 @@ const regex: Record = { const splitter = new RegExp(Object.values(regex).map(pair => pair.global.source).join('|')); const emojiList: Emoji[] = []; -axios.get('https://unpkg.com/emojilib@2.4.0/emojis.json').then(response => { - Object.keys(response.data).forEach(name => emojiList.push({ name, char: response.data[name].char })); -}); - +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 = ({ line }) => { + const classes = useStyles(); if (!line) return null; const matchConceal = regex.conceal.local.exec(line); if (matchConceal) { - if (line[0] === '!') return {matchConceal[1]}; + if (line[0] === '!') return {matchConceal[1]}; return {matchConceal[1]}; } @@ -59,7 +72,7 @@ const InlineSyntax: React.FC = ({ line }) => { } const matchCode = line.match(regex.code.local); - if (matchCode) return {matchCode[1]}; + if (matchCode) return {matchCode[1]}; const matchBold = line.match(regex.bold.local); if (matchBold) return {matchBold[1]}; -- cgit v1.2.3