mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00

* added notes sidebar * added note dropping and editing * added sidebar navigation * handling sidebarchanges over time * using router back for closing sidebar * fixed tripping inside single sidebar * added superpowers toggle to sidebar * user button opens sidebar now * added profile cover for profile sidebar * removed profile sidebar completely * ran prettier over project * added note not found error literal
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
import { marked } from 'marked';
|
||
|
||
import { EventMessageType } from '~/constants/events';
|
||
import { stripHTMLTags } from '~/utils/stripHTMLTags';
|
||
|
||
/**
|
||
* Cleans youtube urls
|
||
*/
|
||
export const formatTextSanitizeYoutube = (text: string): string =>
|
||
text.replace(
|
||
/(https?:\/\/(www\.)?(youtube\.com|youtu\.be)\/(watch)?(\?v=)?[\w\-&=]+)/gim,
|
||
'\n$1\n',
|
||
);
|
||
|
||
/**
|
||
* Removes HTML tags
|
||
*/
|
||
export const formatTextSanitizeTags = (text: string): string =>
|
||
stripHTMLTags(text);
|
||
|
||
/**
|
||
* Returns clickable usernames
|
||
*/
|
||
export const formatTextClickableUsernames = (text: string): string =>
|
||
text.replace(/~([\wа-яА-Я-]+)/giu, `<span class="username">~$1</span>`);
|
||
|
||
/**
|
||
* Makes gray comments
|
||
*/
|
||
export const formatTextComments = (text: string): string =>
|
||
text
|
||
.replace(/:\/\//gim, ':|--|')
|
||
.replace(/(\/\/[^\n]+)/gim, '<span class="grey">$1</span>')
|
||
.replace(/(\/\*[\s\S]*?\*\/)/gim, '<span class="grey">$1</span>')
|
||
.replace(/:\|--\|/gim, '://');
|
||
|
||
/**
|
||
* Highlights todos
|
||
*/
|
||
export const formatTextTodos = (text: string): string =>
|
||
text
|
||
.replace(
|
||
/\/\/\s*(todo|туду):?\s*([^\n]+)/gim,
|
||
'// <span class="todo">$1</span> $2',
|
||
)
|
||
.replace(
|
||
/\/\/\s*(done|сделано|сделал|готово|fixed|пофикшено|фиксед):?\s*([^\n]+)/gim,
|
||
'// <span class="done">$1</span> $2',
|
||
);
|
||
|
||
/**
|
||
* Formats !!exclamation messages with green color
|
||
*/
|
||
export const formatExclamations = (text: string): string =>
|
||
text.replace(/(!![\s\S]*?(!!|\n|$))/gim, '<span class="green">$1$2</span>');
|
||
|
||
/**
|
||
* Replaces -- with dash
|
||
*/
|
||
export const formatTextDash = (text: string): string =>
|
||
text.replace(' -- ', ' — ');
|
||
|
||
/**
|
||
* Formats with markdown
|
||
*/
|
||
export const formatTextMarkdown = (text: string): string => marked(text);
|