Files
jiang13-bbs/backend/service/content_hide.go

40 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package service
import (
"errors"
"github.com/freefire/jiang13-bbs/markdown"
)
var (
// ErrAnnouncementReplyHideNotAllowed 公告不可评论,禁止回复可见块
ErrAnnouncementReplyHideNotAllowed = errors.New("公告不可评论,不能使用回复可见")
// ErrSitePageHideNotAllowed 站点单页正文禁止 [hide](本轮单页仍无评论/解锁)
ErrSitePageHideNotAllowed = errors.New("页面不支持隐藏内容")
// ErrCommentHideNotAllowed 评论无隐藏解锁流程,禁止 [hide]
ErrCommentHideNotAllowed = errors.New("评论不支持隐藏内容")
)
// rejectHideBlocks 若正文含 [hide] 开标记(忽略代码围栏内伪语法)则返回指定错误。
func rejectHideBlocks(content string, deny error) error {
if markdown.HasHideBlocks(content) {
return deny
}
return nil
}
// rejectReplyHideBlocks 若正文含回复可见隐藏块则返回指定错误。
func rejectReplyHideBlocks(content string, deny error) error {
blocks, err := markdown.ParseHideBlocks(content)
if err != nil {
// 语法错误交给 ValidateHideContent;此处不阻断「无有效块」的脏文本
return nil
}
for _, b := range blocks {
if b.Kind == markdown.HideKindReply {
return deny
}
}
return nil
}