diff --git a/backend/markdown/hide.go b/backend/markdown/hide.go index 8d704e6..90cc972 100644 --- a/backend/markdown/hide.go +++ b/backend/markdown/hide.go @@ -248,7 +248,7 @@ func MatchPasswordBlocks(content, password string) ([]int, error) { return hit, nil } -// WrapContentAsHide 将整篇正文包进单一隐藏块(旧帖迁移用) +// WrapContentAsHide 将整篇正文包进单一隐藏块 func WrapContentAsHide(kind string, points int, content string) string { body := strings.TrimRight(content, "\n") open := openMarkerLine(kind, points, "", false) @@ -258,7 +258,7 @@ func WrapContentAsHide(kind string, points int, content string) string { return open + "\n" + body + "\n[/hide]\n" } -// HasHideBlocks 快速判断正文是否已含隐藏块(迁移幂等) +// HasHideBlocks 判断正文是否已含隐藏块 func HasHideBlocks(content string) bool { blocks, err := ParseHideBlocks(content) if err != nil { diff --git a/backend/markdown/hide_test.go b/backend/markdown/hide_test.go index 2d0c4e3..403a9f5 100644 --- a/backend/markdown/hide_test.go +++ b/backend/markdown/hide_test.go @@ -177,20 +177,3 @@ func TestTimelineDoesNotBreakHideValidate(t *testing.T) { t.Fatalf("timeline-only should pass: %v", err) } } - -func TestRewriteLegacyDirectives(t *testing.T) { - src := "公开\n\n:::hide login\n秘\n:::\n\n:::timeline\n## 2026-01-01 A\n:::\n" - got := RewriteLegacyDirectives(src) - if strings.Contains(got, ":::") { - t.Fatalf("legacy remains: %q", got) - } - if !strings.Contains(got, "[hide login]") || !strings.Contains(got, "[/hide]") { - t.Fatalf("hide missing: %q", got) - } - if !strings.Contains(got, "[timeline]") || !strings.Contains(got, "[/timeline]") { - t.Fatalf("timeline missing: %q", got) - } - if err := ValidateHideContent(got); err != nil { - t.Fatal(err) - } -} diff --git a/backend/markdown/legacy_rewrite.go b/backend/markdown/legacy_rewrite.go deleted file mode 100644 index 95aa077..0000000 --- a/backend/markdown/legacy_rewrite.go +++ /dev/null @@ -1,158 +0,0 @@ -package markdown - -import ( - "strconv" - "strings" -) - -// RewriteLegacyDirectives 将旧式 :::hide / :::timeline / 裸 ::: 改写为行级 BBCode。 -// 幂等:已是 BBCode 的内容原样返回(若无旧标记)。代码围栏内不改写。 -func RewriteLegacyDirectives(content string) string { - if content == "" { - return content - } - if !strings.Contains(content, ":::") { - return content - } - lines := splitLines(content) - var out []string - inCode := false - i := 0 - for i < len(lines) { - trimmed := strings.TrimSpace(lines[i]) - if strings.HasPrefix(trimmed, "```") { - inCode = !inCode - out = append(out, lines[i]) - i++ - continue - } - if inCode { - out = append(out, lines[i]) - i++ - continue - } - - if kind, pts, pwd, locked, ok := parseLegacyHideOpen(trimmed); ok { - bodyLines := make([]string, 0) - j := i + 1 - innerCode := false - found := false - for j < len(lines) { - inner := strings.TrimSpace(lines[j]) - if strings.HasPrefix(inner, "```") { - innerCode = !innerCode - bodyLines = append(bodyLines, lines[j]) - j++ - continue - } - if innerCode { - bodyLines = append(bodyLines, lines[j]) - j++ - continue - } - if inner == ":::" { - found = true - break - } - bodyLines = append(bodyLines, lines[j]) - j++ - } - out = append(out, openMarkerLine(kind, pts, pwd, locked)) - out = append(out, bodyLines...) - if found { - out = append(out, "[/hide]") - i = j + 1 - } else { - // 未闭合:仍写出已转换开标记与正文,避免丢内容 - i = j - } - continue - } - - if trimmed == ":::timeline" || strings.HasPrefix(trimmed, ":::timeline ") { - bodyLines := make([]string, 0) - j := i + 1 - innerCode := false - found := false - for j < len(lines) { - inner := strings.TrimSpace(lines[j]) - if strings.HasPrefix(inner, "```") { - innerCode = !innerCode - bodyLines = append(bodyLines, lines[j]) - j++ - continue - } - if innerCode { - bodyLines = append(bodyLines, lines[j]) - j++ - continue - } - if inner == ":::" { - found = true - break - } - bodyLines = append(bodyLines, lines[j]) - j++ - } - out = append(out, "[timeline]") - out = append(out, bodyLines...) - if found { - out = append(out, "[/timeline]") - i = j + 1 - } else { - i = j - } - continue - } - - out = append(out, lines[i]) - i++ - } - return strings.Join(out, "\n") -} - -// parseLegacyHideOpen 解析旧式 :::hide [arg] [locked] -func parseLegacyHideOpen(trimmed string) (kind string, points int, password string, locked bool, ok bool) { - if !strings.HasPrefix(trimmed, ":::hide") { - return "", 0, "", false, false - } - rest := strings.TrimSpace(trimmed[len(":::hide"):]) - if rest == "" { - return "", 0, "", false, false - } - parts := strings.Fields(rest) - if len(parts) == 0 { - return "", 0, "", false, false - } - kind = parts[0] - switch kind { - case HideKindLogin, HideKindReply, HideKindPoints, HideKindPassword: - default: - return "", 0, "", false, false - } - idx := 1 - if kind == HideKindPoints { - if idx >= len(parts) { - return "", 0, "", false, false - } - n, err := strconv.Atoi(parts[idx]) - if err != nil { - return "", 0, "", false, false - } - points = n - idx++ - } else if kind == HideKindPassword { - if idx < len(parts) && parts[idx] != "locked" { - password = parts[idx] - idx++ - } - } - for ; idx < len(parts); idx++ { - if parts[idx] == "locked" { - locked = true - } else { - return "", 0, "", false, false - } - } - return kind, points, password, locked, true -} diff --git a/backend/service/operations_mail.go b/backend/service/operations_mail.go index c53ca51..6510315 100644 --- a/backend/service/operations_mail.go +++ b/backend/service/operations_mail.go @@ -113,9 +113,6 @@ func (o *Operations) smtp(ctx context.Context, c MailConfig, p *mailPayload, id const defaultMailSubject = "{{site_name}} · {{purpose}}" -// 旧版内置正文:读取时若仍是此值,升级为新默认模板。 -const legacyMailBody = "{{logo}}

{{site_name}} · {{purpose}}

您的验证码:

{{code}}

15 分钟内有效。如果不是您本人操作,请忽略本邮件。

前往站点完成{{purpose}}(请粘贴以上验证码)

" - const defaultMailBody = `