1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 04:46:40 +07:00

splitting comment text by blocks

This commit is contained in:
Fedor Katurov 2019-11-26 10:25:43 +07:00
parent d74c9ee739
commit 93afa626db
8 changed files with 206 additions and 158 deletions

33
src/constants/comment.ts Normal file
View file

@ -0,0 +1,33 @@
import { CommentTextBlock } from '~/components/comment/CommentTextBlock';
export const COMMENT_BLOCK_TYPES = {
TEXT: 'TEXT',
MARK: 'MARK',
EMBED: 'EMBED',
};
export const COMMENT_BLOCK_DETECTORS = [
{
type: COMMENT_BLOCK_TYPES.EMBED,
test: /(https?:\/\/(www\.)?(youtube\.com|youtu\.be)\/(watch)?(\?v=)?[\w\-]+)/gim,
},
{
type: COMMENT_BLOCK_TYPES.MARK,
test: /^[\n\s]{0,}?<\.{3}>[\n\s]{0,}$/gi,
},
{
type: COMMENT_BLOCK_TYPES.TEXT,
test: /^.*$/gi,
},
];
export type ICommentBlock = {
type: typeof COMMENT_BLOCK_TYPES[keyof typeof COMMENT_BLOCK_TYPES];
content: string;
};
export const COMMENT_BLOCK_RENDERERS = {
[COMMENT_BLOCK_TYPES.TEXT]: CommentTextBlock,
[COMMENT_BLOCK_TYPES.MARK]: CommentTextBlock,
[COMMENT_BLOCK_TYPES.EMBED]: CommentTextBlock,
};