-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdump_test.go
More file actions
38 lines (27 loc) · 827 Bytes
/
Copy pathdump_test.go
File metadata and controls
38 lines (27 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package htmldump_test
import (
"regexp"
"strings"
"testing"
)
func extractHTMLTable(t *testing.T, doc string) string {
t.Helper()
being := strings.Index(doc, `<table`)
end := strings.Index(doc, `</table>`) + len(`</table>`)
table := doc[being:end]
whiteSpaces := regexp.MustCompile(`>\s+<`)
table = whiteSpaces.ReplaceAllString(table, "><")
return table
}
func removeStyle(t *testing.T, table string) string {
t.Helper()
style := regexp.MustCompile(`class="[^"]+"|style="[^"]+"`)
table = style.ReplaceAllString(table, ``)
td := regexp.MustCompile(`<td\s+>`)
table = td.ReplaceAllString(table, `<td>`)
th := regexp.MustCompile(`<th\s+>`)
table = th.ReplaceAllString(table, `<th>`)
// tableRE := regexp.MustCompile(`<table\s+>`)
// table = tableRE.ReplaceAllString(table, `<table>`)
return table
}