MCPcopy Create free account
hub / github.com/vale-cli/vale / applyBlockPatterns

Function applyBlockPatterns

internal/lint/html.go:39–81  ·  view source on GitHub ↗
(c *core.Config, exts extensionConfig, content string)

Source from the content-addressed store, hash-verified

37}
38
39func applyBlockPatterns(c *core.Config, exts extensionConfig, content string) (string, error) {
40 block, ok := blockDelimiters[exts.Normed]
41 if !ok {
42 return content, fmt.Errorf("ignore patterns are not supported in '%s' files", exts.Normed)
43 }
44
45 // TODO: Should we assume this?
46 s := reFrontMatter.ReplaceAllString(content, block)
47
48 for syntax, regexes := range c.BlockIgnores {
49 sec, err := glob.Compile(syntax)
50 if err != nil {
51 return s, err
52 } else if sec.Match(exts.Normed) || sec.Match(exts.Real) {
53 for _, r := range regexes {
54 pat, errc := regexp2.CompileStd(r)
55 if errc != nil { //nolint:gocritic
56 return s, core.NewE201FromTarget(
57 errc.Error(),
58 r,
59 c.Flags.Path,
60 )
61 } else if strings.HasSuffix(exts.Normed, ".rst") {
62 // HACK: We need to add padding for the literal block.
63 for _, c := range pat.FindAllStringSubmatch(s, -1) {
64 sec := fmt.Sprintf(block, core.Indent(c[0], " "))
65 s = strings.Replace(s, c[0], sec, 1)
66 }
67 } else {
68 s, err = pat.Replace(s, block, 0, -1)
69 if err != nil {
70 return s, core.NewE201FromTarget(
71 err.Error(),
72 r,
73 c.Flags.Path,
74 )
75 }
76 }
77 }
78 }
79 }
80 return s, nil
81}
82
83var inlineDelimiters = map[string]string{
84 ".adoc": "`$1`",

Callers 1

applyPatternsFunction · 0.85

Calls 4

CompileFunction · 0.92
NewE201FromTargetFunction · 0.92
IndentFunction · 0.92
MatchMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…