diff --git a/web/src/utils/content.ts b/web/src/utils/content.ts index c1138af1..f48e55be 100644 --- a/web/src/utils/content.ts +++ b/web/src/utils/content.ts @@ -1,19 +1,30 @@ - export const parsePostTag = (content: string) => { - const tags: string[] = [] - const users: string[] = [] - var tagExp = /(#|#)([^#@])+?\s+?/g // 这⾥中⽂#和英⽂#都会识别 - var atExp = /@([a-zA-Z0-9])+?\s+?/g // 这⾥中⽂#和英⽂#都会识别 - content = content - .replace(/<[^>]*?>/gi, '') - .replace(/(.*?)<\/[^>]*?>/gi, '') - .replace(tagExp, item => { - tags.push(item.substr(1).trim()) - return '' + item.trim() + ' ' - }) - .replace(atExp, item => { - users.push(item.substr(1).trim()) - return '' + item.trim() + ' ' - }) - return { content, tags, users } -} \ No newline at end of file + const tags: string[] = []; + const users: string[] = []; + var tagExp = /(#|#)([^#@\s])+?\s+?/g; // 这⾥中⽂#和英⽂#都会识别 + var atExp = /@([a-zA-Z0-9])+?\s+?/g; // 这⾥中⽂#和英⽂#都会识别 + content = content + .replace(/<[^>]*?>/gi, "") + .replace(/(.*?)<\/[^>]*?>/gi, "") + .replace(tagExp, (item) => { + tags.push(item.substr(1).trim()); + return ( + '' + + item.trim() + + " " + ); + }) + .replace(atExp, (item) => { + users.push(item.substr(1).trim()); + return ( + '' + + item.trim() + + " " + ); + }); + return { content, tags, users }; +};