(tok html.Token)
| 143 | } |
| 144 | |
| 145 | func (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 | |
| 170 | func (w *walker) advance(text string) int { |
| 171 | pos := 0 |
no test coverage detected