parseMarkdownRules 解析 Markdown 格式的规则
(content, sourcePath string, scope Scope)
| 175 | |
| 176 | // parseMarkdownRules 解析 Markdown 格式的规则 |
| 177 | func (m *Manager) parseMarkdownRules(content, sourcePath string, scope Scope) ([]*Rule, error) { |
| 178 | var rules []*Rule |
| 179 | |
| 180 | // 整个文件作为一条规则 |
| 181 | title := extractTitle(content) |
| 182 | if title == "" { |
| 183 | title = filepath.Base(sourcePath) |
| 184 | } |
| 185 | |
| 186 | rule := &Rule{ |
| 187 | ID: generateID(), |
| 188 | Scope: scope, |
| 189 | Title: title, |
| 190 | Content: content, |
| 191 | Source: "file", |
| 192 | SourcePath: sourcePath, |
| 193 | Priority: 0, |
| 194 | Enabled: true, |
| 195 | } |
| 196 | rules = append(rules, rule) |
| 197 | |
| 198 | return rules, nil |
| 199 | } |
| 200 | |
| 201 | // extractTitle 从 Markdown 中提取标题 |
| 202 | func extractTitle(content string) string { |
no test coverage detected