Skip to content

Commit

Permalink
feat: parse content with url => parsePostTag
Browse files Browse the repository at this point in the history
  • Loading branch information
whatwewant committed Oct 19, 2023
1 parent 26445ad commit c9b7fb9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 11 additions & 1 deletion web/src/assets/css/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
}
}

a {
color: #18a058;
text-decoration: none;
cursor: pointer;
}

.hash-link,
.user-link {
color: #18a058;
Expand Down Expand Up @@ -98,6 +104,10 @@

.dark {

a {
color: #63e2b7;
}

.hash-link,
.user-link {
color: #63e2b7;
Expand All @@ -118,4 +128,4 @@
top: 0;
position: absolute !important;
}
}
}
4 changes: 3 additions & 1 deletion web/src/utils/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const parsePostTag = (content: string) => {
const users: string[] = [];
var tagExp = /(#|)([^#@\s])+?\s+?/g; // 这⾥中⽂#和英⽂#都会识别
var atExp = /@([a-zA-Z0-9])+?\s+?/g; // 这⾥中⽂#和英⽂#都会识别
var urlExp = /((?:(?:https?|ftp):\/\/)?[\w/\-?=%.]+\.[\w/\-&?=%.]+)/g;
content = content
.replace(/<[^>]*?>/gi, "")
.replace(/(.*?)<\/[^>]*?>/gi, "")
Expand All @@ -25,7 +26,8 @@ export const parsePostTag = (content: string) => {
item.trim() +
"</a> "
);
});
})
.replace(urlExp, '<a href="$1" target="_blank">$1</a>');
return { content, tags, users };
};

Expand Down

0 comments on commit c9b7fb9

Please sign in to comment.