mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: fix tag regex
This commit is contained in:
@@ -12,6 +12,8 @@ import (
|
|||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var tagRegexp = regexp.MustCompile(`#([^\s#]+?) `)
|
||||||
|
|
||||||
func (s *Server) registerTagRoutes(g *echo.Group) {
|
func (s *Server) registerTagRoutes(g *echo.Group) {
|
||||||
g.GET("/tag", func(c echo.Context) error {
|
g.GET("/tag", func(c echo.Context) error {
|
||||||
ctx := c.Request().Context()
|
ctx := c.Request().Context()
|
||||||
@@ -47,13 +49,9 @@ func (s *Server) registerTagRoutes(g *echo.Group) {
|
|||||||
|
|
||||||
tagMapSet := make(map[string]bool)
|
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 _, memo := range memoList {
|
||||||
for _, rawTag := range r.FindAllString(memo.Content, -1) {
|
for _, rawTag := range tagRegexp.FindAllString(memo.Content, -1) {
|
||||||
tag := r.ReplaceAllString(rawTag, "$1")
|
tag := tagRegexp.ReplaceAllString(rawTag, "$1")
|
||||||
tagMapSet[tag] = true
|
tagMapSet[tag] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,8 +18,6 @@ export const MEMO_LINK_REG = /@\[(.+?)\]\((.+?)\)/g;
|
|||||||
|
|
||||||
const parseMarkedToHtml = (markedStr: string): string => {
|
const parseMarkedToHtml = (markedStr: string): string => {
|
||||||
const htmlText = markedStr
|
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(CODE_BLOCK_REG, "<pre lang=''>$1</pre>")
|
||||||
.replace(TODO_BLOCK_REG, "<span class='todo-block todo' data-value='TODO'></span>")
|
.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>")
|
.replace(DONE_BLOCK_REG, "<span class='todo-block done' data-value='DONE'>✓</span>")
|
||||||
|
Reference in New Issue
Block a user