applyCommentPatterns replaces any custom comment delimiters with HTML comment tags based on the user configuration. This makes it possible to apply comment-based controls using custom comment delimiters.
(c *core.Config, exts extensionConfig, content string)
| 126 | // tags based on the user configuration. This makes it possible to apply |
| 127 | // comment-based controls using custom comment delimiters. |
| 128 | func applyCommentPatterns(c *core.Config, exts extensionConfig, content string) (string, error) { |
| 129 | for syntax, delims := range c.CommentDelimiters { |
| 130 | sec, err := glob.Compile(syntax) |
| 131 | if err != nil { |
| 132 | return content, err |
| 133 | } else if sec.Match(exts.Normed) || sec.Match(exts.Real) { |
| 134 | // This field was not assigned, so do nothing. |
| 135 | if delims[0] == "" && delims[1] == "" { |
| 136 | return content, nil |
| 137 | } |
| 138 | // Return an error if only one delimiter is configured |
| 139 | if (delims[0] == "" && delims[1] != "") || (delims[0] != "" && delims[1] == "") { |
| 140 | return content, fmt.Errorf("CommentDelimiters must be empty or have two values") |
| 141 | } |
| 142 | |
| 143 | content = strings.ReplaceAll(content, delims[0], "<!--") |
| 144 | content = strings.ReplaceAll(content, delims[1], "-->") |
| 145 | } |
| 146 | } |
| 147 | return content, nil |
| 148 | } |
| 149 | |
| 150 | func applyPatterns(c *core.Config, exts extensionConfig, content string) (string, error) { |
| 151 | s, err := applyBlockPatterns(c, exts, content) |
no test coverage detected
searching dependent graphs…