Skip to content

Commit 5a1eda5

Browse files
committed
Adds html-comments
1 parent da572b0 commit 5a1eda5

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

html-comments/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
html-comments

html-comments/README.mkd

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# html-comments
2+
3+
pull comments out of HTML

html-comments/main.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"strings"
7+
8+
"golang.org/x/net/html"
9+
)
10+
11+
func main() {
12+
13+
z := html.NewTokenizer(os.Stdin)
14+
15+
for {
16+
tt := z.Next()
17+
if tt == html.ErrorToken {
18+
break
19+
}
20+
21+
t := z.Token()
22+
23+
if t.Type == html.CommentToken {
24+
d := strings.Replace(t.Data, "\n", " ", -1)
25+
d = strings.TrimSpace(d)
26+
if d == "" {
27+
continue
28+
}
29+
fmt.Println(d)
30+
}
31+
32+
}
33+
34+
}

0 commit comments

Comments
 (0)