mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
added some markdown stylings
This commit is contained in:
parent
d786606924
commit
5dbf4245bf
4 changed files with 82 additions and 7 deletions
|
@ -19,6 +19,7 @@ import {
|
|||
formatTextSanitizeYoutube,
|
||||
formatTextTodos,
|
||||
} from '~/utils/formatText';
|
||||
import { splitTextByYoutube, splitTextOmitEmpty } from '~/utils/splitText';
|
||||
|
||||
export const getStyle = (oElm: any, strCssRule: string) => {
|
||||
if (document.defaultView && document.defaultView.getComputedStyle) {
|
||||
|
@ -112,12 +113,13 @@ export const findBlockType = (line: string): ValueOf<typeof COMMENT_BLOCK_TYPES>
|
|||
};
|
||||
|
||||
export const splitCommentByBlocks = (text: string): ICommentBlock[] =>
|
||||
text
|
||||
.split(/(https?:\/\/(?:www\.)(?:youtube\.com|youtu\.be)\/(?:watch)(?:\?v=)[\w\-\&\=]+)/)
|
||||
.map(line => ({
|
||||
type: findBlockType(line),
|
||||
content: line,
|
||||
}));
|
||||
pipe(
|
||||
splitTextByYoutube,
|
||||
splitTextOmitEmpty
|
||||
)([text]).map(line => ({
|
||||
type: findBlockType(line),
|
||||
content: line,
|
||||
}));
|
||||
|
||||
export const formatCommentText = (author: string, text: string): ICommentBlock[] =>
|
||||
text ? splitCommentByBlocks(formatText(text)) : null;
|
||||
|
|
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