Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

chore: fix tag regex

Stevend68891d91d6a
diff --git a/server/tag.go b/server/tag.go
index f8ac6e0d4..d78242267 100644
--- a/server/tag.go
+++ b/server/tag.go
@@ -12,6 +12,8 @@ import (
"github.com/labstack/echo/v4"
)
+var tagRegexp = regexp.MustCompile(`#([^\s#]+?) `)
+
func (s *Server) registerTagRoutes(g *echo.Group) {
g.GET("/tag", func(c echo.Context) error {
ctx := c.Request().Context()
@@ -47,13 +49,9 @@ func (s *Server) registerTagRoutes(g *echo.Group) {
tagMapSet := make(map[string]bool)
- r := regexp.MustCompile(`#([^\s#]+?) `)
- if err != nil {
- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to compile regexp").SetInternal(err)
- }
for _, memo := range memoList {
- for _, rawTag := range r.FindAllString(memo.Content, -1) {
- tag := r.ReplaceAllString(rawTag, "$1")
+ for _, rawTag := range tagRegexp.FindAllString(memo.Content, -1) {
+ tag := tagRegexp.ReplaceAllString(rawTag, "$1")
tagMapSet[tag] = true
}
}
diff --git a/web/src/helpers/marked.ts b/web/src/helpers/marked.ts
index 28acd1cdd..01c35548f 100644
--- a/web/src/helpers/marked.ts
+++ b/web/src/helpers/marked.ts
@@ -18,8 +18,6 @@ export const MEMO_LINK_REG = /@\[(.+?)\]\((.+?)\)/g;
const parseMarkedToHtml = (markedStr: string): string => {
const htmlText = markedStr
- .replace(/([\u4e00-\u9fa5])([A-Za-z0-9?.,;[\]]+)/g, "$1 $2")
- .replace(/([A-Za-z0-9?.,;[\]]+)([\u4e00-\u9fa5])/g, "$1 $2")
.replace(CODE_BLOCK_REG, "<pre lang=''>$1</pre>")
.replace(TODO_BLOCK_REG, "<span class='todo-block todo' data-value='TODO'></span>")
.replace(DONE_BLOCK_REG, "<span class='todo-block done' data-value='DONE'>✓</span>")