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

better text formatting

This commit is contained in:
Fedor Katurov 2019-10-17 16:34:41 +07:00
parent de8e5b2d9e
commit 6d0a22707c
3 changed files with 19 additions and 13 deletions

View file

@ -67,10 +67,8 @@ export const getURL = (file: Partial<IFile>) => {
export const getImageSize = (file: IFile, size?: string): string => getURL(file);
// `${process.env.API_HOST}${image}`.replace('{size}', size);
export const formatCommentText = (author, text: string) => {
if (!text) return '';
return text
export const formatText = (text: string): string =>
text
.replace(/(\n{2,})/gi, '\n')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
@ -78,15 +76,21 @@ export const formatCommentText = (author, text: string) => {
.replace(/(\/\/[^\n]+)/gim, '<span class="grey">$1</span>')
.replace(/:\|--\|/gim, '://')
.split('\n')
.map((el, index) =>
index === 0
? `${author ? `<p><b class="comment-author">${author}: </b>` : ''}${el}</p>`
: `<p>${el}</p>`
)
.map(el => `<p>${el}</p>`)
// .map((el, index) =>
// index === 0
// ? `${author ? `<p><b class="comment-author">${author}: </b>` : ''}${el}</p>`
// : `<p>${el}</p>`
// )
.join('');
};
// .replace(/\/\*(\*(?!\/)|[^*])*\*\//igm, '');
export const formatCommentText = (author: string, text: string): string =>
text
? formatText(text).replace(
/^<p>/,
author ? `<p><b class="comment-author">${author}: </b></p>` : '<p>'
)
: '';
export const getPrettyDate = (date: string): string =>
formatDistanceToNow(new Date(date), { locale: ru, includeSeconds: true, addSuffix: true });