mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
added some markdown stylings
This commit is contained in:
parent
d786606924
commit
5dbf4245bf
4 changed files with 82 additions and 7 deletions
|
@ -1,13 +1,15 @@
|
||||||
import React, { FC } from 'react';
|
import React, { FC } from 'react';
|
||||||
import { ICommentBlockProps } from '~/constants/comment';
|
import { ICommentBlockProps } from '~/constants/comment';
|
||||||
import styles from './styles.module.scss';
|
import styles from './styles.module.scss';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
import markdown from '~/styles/common/markdown.module.scss';
|
||||||
|
|
||||||
interface IProps extends ICommentBlockProps {}
|
interface IProps extends ICommentBlockProps {}
|
||||||
|
|
||||||
const CommentTextBlock: FC<IProps> = ({ block }) => {
|
const CommentTextBlock: FC<IProps> = ({ block }) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={styles.text}
|
className={classNames(styles.text, markdown.wrapper)}
|
||||||
dangerouslySetInnerHTML={{
|
dangerouslySetInnerHTML={{
|
||||||
__html: block.content,
|
__html: block.content,
|
||||||
}}
|
}}
|
||||||
|
|
60
src/styles/common/markdown.module.scss
Normal file
60
src/styles/common/markdown.module.scss
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
@import "../variables";
|
||||||
|
|
||||||
|
.wrapper {
|
||||||
|
pre {
|
||||||
|
background-color: darken($comment_bg, 2%);
|
||||||
|
border: {
|
||||||
|
left: 4px solid $red;
|
||||||
|
right: 4px solid $red;
|
||||||
|
}
|
||||||
|
font-family: monospace;
|
||||||
|
font-size: 13px;
|
||||||
|
padding: $gap;
|
||||||
|
border-radius: $radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin-bottom: $gap;
|
||||||
|
}
|
||||||
|
|
||||||
|
h5, h4, h3, h2, h1 {
|
||||||
|
color: white;
|
||||||
|
font-weight: 800;
|
||||||
|
line-height: 1.2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: 1.8em;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
font-size: 1.6em;
|
||||||
|
}
|
||||||
|
|
||||||
|
h4 {
|
||||||
|
font-size: 1.4em;
|
||||||
|
}
|
||||||
|
|
||||||
|
h5 {
|
||||||
|
font-size: 1.2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul {
|
||||||
|
list-style: disc;
|
||||||
|
padding-left: 20px;
|
||||||
|
margin-bottom: $gap;
|
||||||
|
|
||||||
|
li {
|
||||||
|
margin: 5px 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.grey) {
|
||||||
|
color: #555555;
|
||||||
|
white-space: pre-line;
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,6 +19,7 @@ import {
|
||||||
formatTextSanitizeYoutube,
|
formatTextSanitizeYoutube,
|
||||||
formatTextTodos,
|
formatTextTodos,
|
||||||
} from '~/utils/formatText';
|
} from '~/utils/formatText';
|
||||||
|
import { splitTextByYoutube, splitTextOmitEmpty } from '~/utils/splitText';
|
||||||
|
|
||||||
export const getStyle = (oElm: any, strCssRule: string) => {
|
export const getStyle = (oElm: any, strCssRule: string) => {
|
||||||
if (document.defaultView && document.defaultView.getComputedStyle) {
|
if (document.defaultView && document.defaultView.getComputedStyle) {
|
||||||
|
@ -112,9 +113,10 @@ export const findBlockType = (line: string): ValueOf<typeof COMMENT_BLOCK_TYPES>
|
||||||
};
|
};
|
||||||
|
|
||||||
export const splitCommentByBlocks = (text: string): ICommentBlock[] =>
|
export const splitCommentByBlocks = (text: string): ICommentBlock[] =>
|
||||||
text
|
pipe(
|
||||||
.split(/(https?:\/\/(?:www\.)(?:youtube\.com|youtu\.be)\/(?:watch)(?:\?v=)[\w\-\&\=]+)/)
|
splitTextByYoutube,
|
||||||
.map(line => ({
|
splitTextOmitEmpty
|
||||||
|
)([text]).map(line => ({
|
||||||
type: findBlockType(line),
|
type: findBlockType(line),
|
||||||
content: line,
|
content: line,
|
||||||
}));
|
}));
|
||||||
|
|
11
src/utils/splitText.ts
Normal file
11
src/utils/splitText.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import { flatten } from 'ramda';
|
||||||
|
|
||||||
|
export const splitTextByYoutube = (strings: string[]): string[] =>
|
||||||
|
flatten(
|
||||||
|
strings.map(str =>
|
||||||
|
str.split(/(https?:\/\/(?:www\.)(?:youtube\.com|youtu\.be)\/(?:watch)(?:\?v=)[\w\-\&\=]+)/)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
export const splitTextOmitEmpty = (strings: string[]): string[] =>
|
||||||
|
strings.filter(el => !!el.trim());
|
Loading…
Add table
Add a link
Reference in a new issue