Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
fec6ab97
Commit
fec6ab97
authored
Dec 15, 2010
by
Nigel Tao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
html: parse "<h1>foo<h2>bar".
R=gri CC=golang-dev
https://golang.org/cl/3571043
parent
8132bb1c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
6 deletions
+20
-6
src/pkg/html/parse.go
src/pkg/html/parse.go
+7
-0
src/pkg/html/parse_test.go
src/pkg/html/parse_test.go
+10
-4
src/pkg/html/token.go
src/pkg/html/token.go
+3
-2
No files found.
src/pkg/html/parse.go
View file @
fec6ab97
...
...
@@ -371,6 +371,13 @@ func inBodyIM(p *parser) (insertionMode, bool) {
}
else
{
p
.
addElement
(
p
.
tok
.
Data
,
p
.
tok
.
Attr
)
}
case
"h1"
,
"h2"
,
"h3"
,
"h4"
,
"h5"
,
"h6"
:
// TODO: auto-insert </p> if necessary.
switch
n
:=
p
.
top
();
n
.
Data
{
case
"h1"
,
"h2"
,
"h3"
,
"h4"
,
"h5"
,
"h6"
:
p
.
pop
()
}
p
.
addElement
(
p
.
tok
.
Data
,
p
.
tok
.
Attr
)
case
"b"
,
"big"
,
"code"
,
"em"
,
"font"
,
"i"
,
"s"
,
"small"
,
"strike"
,
"strong"
,
"tt"
,
"u"
:
p
.
reconstructActiveFormattingElements
()
p
.
addFormattingElement
(
p
.
tok
.
Data
,
p
.
tok
.
Attr
)
...
...
src/pkg/html/parse_test.go
View file @
fec6ab97
...
...
@@ -11,6 +11,7 @@ import (
"io"
"io/ioutil"
"os"
"strings"
"testing"
)
...
...
@@ -124,9 +125,14 @@ func TestParser(t *testing.T) {
rc
:=
make
(
chan
io
.
Reader
)
go
readDat
(
filename
,
rc
)
// TODO(nigeltao): Process all test cases, not just a subset.
for
i
:=
0
;
i
<
2
1
;
i
++
{
for
i
:=
0
;
i
<
2
2
;
i
++
{
// Parse the #data section.
doc
,
err
:=
Parse
(
<-
rc
)
b
,
err
:=
ioutil
.
ReadAll
(
<-
rc
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
text
:=
string
(
b
)
doc
,
err
:=
Parse
(
strings
.
NewReader
(
text
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -139,13 +145,13 @@ func TestParser(t *testing.T) {
t
.
Fatal
(
err
)
}
// Compare the parsed tree to the #document section.
b
,
err
:
=
ioutil
.
ReadAll
(
<-
rc
)
b
,
err
=
ioutil
.
ReadAll
(
<-
rc
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
expected
:=
string
(
b
)
if
actual
!=
expected
{
t
.
Errorf
(
"%s test #%d
, actual vs expected:
\n
----
\n
%s----
\n
%s----"
,
filename
,
i
,
actual
,
expected
)
t
.
Errorf
(
"%s test #%d
%q, actual vs expected:
\n
----
\n
%s----
\n
%s----"
,
filename
,
i
,
text
,
actual
,
expected
)
}
}
}
...
...
src/pkg/html/token.go
View file @
fec6ab97
...
...
@@ -277,7 +277,7 @@ func (z *Tokenizer) trim(i int) int {
return
k
}
// lower finds the largest alphabetic [
a-zA-Z
]* word at the start of z.buf[i:]
// lower finds the largest alphabetic [
0-9A-Za-z
]* word at the start of z.buf[i:]
// and returns that word lower-cased, as well as the trimmed cursor location
// after that word.
func
(
z
*
Tokenizer
)
lower
(
i
int
)
([]
byte
,
int
)
{
...
...
@@ -285,8 +285,9 @@ func (z *Tokenizer) lower(i int) ([]byte, int) {
loop
:
for
;
i
<
z
.
p1
;
i
++
{
c
:=
z
.
buf
[
i
]
// TODO(nigeltao): Check what '0' <= c && c <= '9' should do.
switch
{
case
'0'
<=
c
&&
c
<=
'9'
:
// No-op.
case
'A'
<=
c
&&
c
<=
'Z'
:
z
.
buf
[
i
]
=
c
+
'a'
-
'A'
case
'a'
<=
c
&&
c
<=
'z'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment