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

Method replaceToks

internal/lint/walk.go:145–168  ·  view source on GitHub ↗
(tok html.Token)

Source from the content-addressed store, hash-verified

143}
144
145func (w *walker) replaceToks(tok html.Token) {
146 tags := core.StringInSlice(tok.Data, []string{
147 "img", "a", "p", "script", "h1", "h2", "h3", "h4", "h5", "h6", "span"})
148 if tags {
149 names := []string{"href", "id", "src", "alt"}
150 if w.ext == ".html" {
151 // We need to handle cases in which inline tags include `class` attributes, which may
152 // contain substrings that match our actual findings. The challenge is that many of our
153 // supported formats inject these *after* converting to HTML, so we can't find them in
154 // the original text.
155 //
156 // See testdata/fixtures/patterns/{test2.rst, test3.html} for examples.
157 names = append(names, "class")
158 }
159 for _, a := range tok.Attr {
160 if core.StringInSlice(a.Key, names) {
161 if a.Key == "href" {
162 a.Val, _ = url.QueryUnescape(a.Val)
163 }
164 w.update(a.Val, html.TextToken)
165 }
166 }
167 }
168}
169
170func (w *walker) advance(text string) int {
171 pos := 0

Callers 1

lintHTMLTokensMethod · 0.80

Calls 2

updateMethod · 0.95
StringInSliceFunction · 0.92

Tested by

no test coverage detected