1
0
mirror of https://github.com/golang/go synced 2024-10-04 08:41:21 -06:00
Commit Graph

107 Commits

Author SHA1 Message Date
Rob Pike
07ee3cc741 html/template: update to new template API
Not quite done yet but enough is here to review.

Embedding is eliminated so clients can't accidentally reach
methods of text/template.Template that would break the
invariants.

TODO later: Add and Clone are unimplemented.
TODO later: address issue 2349

R=golang-dev, r, rsc
CC=golang-dev
https://golang.org/cl/5434077
2011-11-30 17:42:18 -05:00
Nigel Tao
849fc19cab html: clean up the z.rawTag calculation in the tokenizer.
R=andybalholm
CC=golang-dev
https://golang.org/cl/5440064
2011-11-30 17:00:37 +11:00
Andrew Balholm
3b3922771a html: parse <xmp> tags
Pass tests5.dat, test 10:
<p><xmp></xmp>

| <html>
|   <head>
|   <body>
|     <p>
|     <xmp>

Also pass the remaining tests in tests5.dat.

R=nigeltao
CC=golang-dev
https://golang.org/cl/5440062
2011-11-30 15:37:41 +11:00
Andrew Balholm
e32f4ba77d html: parse the contents of <iframe> elements as raw text
Pass tests5.dat, test 4:
<iframe> <!---> </iframe>x

| <html>
|   <head>
|   <body>
|     <iframe>
|       " <!---> "
|     "x"

Also pass tests through test 9:
<style> <!</-- </style>x

R=nigeltao
CC=golang-dev
https://golang.org/cl/5450044
2011-11-30 11:44:54 +11:00
Nigel Tao
929290d5a0 html: spin doctype.go out of parse.go.
R=andybalholm
CC=golang-dev
https://golang.org/cl/5445049
2011-11-29 18:20:59 +11:00
Andrew Balholm
c32b607687 html: detect quirks mode
Pass tests3.dat, test 23:
<p><table></table>

| <html>
|   <head>
|   <body>
|     <p>
|       <table>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5446043
2011-11-29 11:18:49 +11:00
Andrew Balholm
68e7363b56 html: parse <nobr> elements
Pass tests3.dat, test 20:
<!doctype html><nobr><nobr><nobr>

| <!DOCTYPE html>
| <html>
|   <head>
|   <body>
|     <nobr>
|     <nobr>
|     <nobr>

Also pass tests through test 22:
<!doctype html><html><body><p><table></table></body></html>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5438056
2011-11-28 10:55:31 +11:00
Andrew Balholm
557ba72e69 html: ignore <head> tags in <head> element
Pass tests3.dat, test 12:
<!DOCTYPE html><HTML><META><HEAD></HEAD></HTML>

| <!DOCTYPE html>
| <html>
|   <head>
|     <meta>
|   <body>

Also pass tests through test 19:
<!DOCTYPE html><html><head></head><body><ul><li><div><p><li></ul></body></html>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5436069
2011-11-27 14:41:08 +11:00
Andrew Gerrand
38c082f69e html/template: fix documentation indent
R=nigeltao
CC=golang-dev
https://golang.org/cl/5437061
2011-11-25 13:32:44 +11:00
Andrew Balholm
af081cd43e html: ingore newline at the start of a <pre> block
Pass tests3.dat, test 4:
<!DOCTYPE html><html><head></head><body><pre>\n</pre></body></html>

| <!DOCTYPE html>
| <html>
|   <head>
|   <body>
|     <pre>

Also pass tests through test 11:
<!DOCTYPE html><pre>&#x0a;&#x0a;A</pre>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5437051
2011-11-24 13:15:09 +11:00
Andrew Balholm
77b0ad1e80 html: parse DOCTYPE into name and public and system identifiers
Pass tests2.dat, test 59:
<!DOCTYPE <!DOCTYPE HTML>><!--<!--x-->-->

| <!DOCTYPE <!doctype>
| <html>
|   <head>
|   <body>
|     ">"
|     <!-- <!--x -->
|     "-->"

Pass all the tests in doctype01.dat.

Also pass tests2.dat, test 60:
<!doctype html><div><form></form><div></div></div>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5437045
2011-11-24 09:28:58 +11:00
Andrew Balholm
57ed39fd3b html: on EOF in a comment, ignore final dashes (up to 2)
Pass tests2.dat, test 57:
<!DOCTYPE html><!--x--

| <!DOCTYPE html>
| <!-- x -->
| <html>
|   <head>
|   <body>

Also pass test 58:
<!DOCTYPE html><table><tr><td></p></table>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5436048
2011-11-23 09:26:37 +11:00
Andrew Balholm
95e60acb97 html: copy attributes from extra <html> tags to root element
Pass tests2.dat, test 50:
<!DOCTYPE html><html><body><html id=x>

| <!DOCTYPE html>
| <html>
|   id="x"
|   <head>
|   <body>

Also pass tests through test 56:
<!DOCTYPE html>X<p/x/y/z>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5432045
2011-11-22 12:08:22 +11:00
Andrew Balholm
750de28d6c html: ignore whitespace before <head> element
Pass tests2.dat, test 47:
" \n "
(That is, two spaces separated by a newline)

| <html>
|   <head>
|   <body>

Also pass tests through test 49:
<!DOCTYPE html><script>
</script>  <title>x</title>  </head>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5422043
2011-11-22 09:27:27 +11:00
Andrew Balholm
05d8d112fe html: refactor parse test infrastructure
My excuse for doing this is that test cases with newlines in them didn't
work. But instead of just fixing that, I rearranged everything in
parse_test.go to use fewer channels and pipes, and just call a
straightforward function to read test cases from a file.

R=nigeltao
CC=golang-dev
https://golang.org/cl/5410049
2011-11-20 22:42:28 +11:00
Andrew Gerrand
6c864210fc html/template: fix documentation formatting
See http://weekly.golang.org/pkg/html/template/

R=golang-dev, r, rsc
CC=golang-dev
https://golang.org/cl/5413055
2011-11-19 10:54:44 +11:00
Lucio De Re
5b9d7825ed html/template, net/http, websocket: fix import paths in comments
R=golang-dev
CC=golang-dev, rsc
https://golang.org/cl/5411048
2011-11-18 18:33:44 -05:00
Gustavo Niemeyer
f6279b46f8 html: fix doc after Err method name change
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5411045
2011-11-18 01:06:59 -02:00
Andrew Balholm
a1dbfa6f09 html: parse <isindex>
Pass tests2.dat, test 42:
<isindex test=x name=x>

| <html>
|   <head>
|   <body>
|     <form>
|       <hr>
|       <label>
|         "This is a searchable index. Enter search keywords: "
|         <input>
|           name="isindex"
|           test="x"
|       <hr>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5399049
2011-11-17 13:12:13 +11:00
Andrew Balholm
3276afd4d4 html: parse </optgroup> and </option>
Pass tests2.dat, test 35:
<!DOCTYPE html><select><optgroup><option></optgroup><option><select><option>

| <!DOCTYPE html>
| <html>
|   <head>
|   <body>
|     <select>
|       <optgroup>
|         <option>
|       <option>
|     <option>

Also pass tests through test 41:
<!DOCTYPE html><!-- XXX - XXX - XXX -->

R=nigeltao, rsc
CC=golang-dev
https://golang.org/cl/5395045
2011-11-17 10:25:33 +11:00
Rob Pike
f5db4d05f2 html/template: indirect top-level values before printing
text/template does this (in an entirely different way), so
make html/template do the same. Before this fix, the template
{{.}} given a pointer to a string prints its address instead of its
value.

R=mikesamuel, r
CC=golang-dev
https://golang.org/cl/5370098
2011-11-16 09:32:52 -08:00
Andrew Balholm
3307597069 html: parse <optgroup> tags
Pass tests2.dat, test 34:
<!DOCTYPE html><select><option><optgroup>

| <!DOCTYPE html>
| <html>
|   <head>
|   <body>
|     <select>
|       <option>
|       <optgroup>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5393045
2011-11-16 19:25:55 +11:00
Andrew Balholm
28546ed56a html: parse <caption> elements
Pass tests2.dat, test 33:
<!DOCTYPE html><table><caption>test TEST</caption><td>test

| <!DOCTYPE html>
| <html>
|   <head>
|   <body>
|     <table>
|       <caption>
|         "test TEST"
|       <tbody>
|         <tr>
|           <td>
|             "test"

R=nigeltao
CC=golang-dev
https://golang.org/cl/5371099
2011-11-16 12:18:11 +11:00
Andrew Balholm
b91d82258f html: auto-close <p> elements when starting <form> element.
Pass tests2.dat, test 26:
<!doctypehtml><p><form>

| <!DOCTYPE html>
| <html>
|   <head>
|   <body>
|     <p>
|     <form>

Also pass tests through test 32:
<!DOCTYPE html><!-- X

R=nigeltao
CC=golang-dev
https://golang.org/cl/5369114
2011-11-15 15:31:22 +11:00
Andrew Balholm
3bd5082f57 html: parse and render <plaintext> elements
Pass tests2.dat, test 10:
<table><plaintext><td>

| <html>
|   <head>
|   <body>
|     <plaintext>
|       "<td>"
|     <table>

Also pass tests through test 25:
<!doctypehtml><p><dd>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5369109
2011-11-15 11:39:18 +11:00
Andrew Balholm
06ef97e15d html: auto-close <dd> and <dt> elements
Pass tests2.dat, test 8:
<!DOCTYPE html><dt><div><dd>

| <!DOCTYPE html>
| <html>
|   <head>
|   <body>
|     <dt>
|       <div>
|     <dd>

Also pass tests through test 9:
<script></x

R=nigeltao
CC=golang-dev
https://golang.org/cl/5373083
2011-11-13 23:27:20 +11:00
Andrew Balholm
631a575fd9 html: store the current insertion mode in the parser
Currently, the state transition functions in the HTML parser
return the next insertion mode and whether the token is consumed.
This works well except for when one insertion mode needs to use
the rules for another insertion mode. Then the useTheRulesFor
function needs to patch things up. This requires comparing functions
for equality, which is going to stop working.

Adding a field to the parser structure to store the current
insertion mode eliminates the need for useTheRulesFor;
one insertion mode function can now just call the other
directly. The insertion mode will be changed only if it needs to be.

This CL is an alternative to CL 5372078.

R=nigeltao, rsc
CC=golang-dev
https://golang.org/cl/5372079
2011-11-13 12:39:41 +11:00
Andrew Balholm
3df0512469 html: handle end tags in strange places
Pass tests1.dat, test 111:
</strong></b></em></i></u></strike></s></blink></tt></pre></big></small></font></select></h1></h2></h3></h4></h5></h6></body></br></a></img></title></span></style></script></table></th></td></tr></frame></area></link></param></hr></input></col></base></meta></basefont></bgsound></embed></spacer></p></dd></dt></caption></colgroup></tbody></tfoot></thead></address></blockquote></center></dir></div></dl></fieldset></listing></menu></ol></ul></li></nobr></wbr></form></button></marquee></object></html></frameset></head></iframe></image></isindex></noembed></noframes></noscript></optgroup></option></plaintext></textarea>

| <html>
|   <head>
|   <body>
|     <br>
|     <p>

Also pass all the remaining tests in tests1.dat.

R=nigeltao
CC=golang-dev
https://golang.org/cl/5372066
2011-11-12 12:23:30 +11:00
Andrew Balholm
0a61c846ef html: ignore <col> tag outside tables
Pass tests1.dat, test 109:
<table><col><tbody><col><tr><col><td><col></table><col>

| <html>
|   <head>
|   <body>
|     <table>
|       <colgroup>
|         <col>
|       <tbody>
|       <colgroup>
|         <col>
|       <tbody>
|         <tr>
|       <colgroup>
|         <col>
|       <tbody>
|         <tr>
|           <td>
|       <colgroup>
|         <col>

Also pass test 110:
<table><colgroup><tbody><colgroup><tr><colgroup><td><colgroup></table><colgroup>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5369069
2011-11-11 21:44:01 +11:00
Andrew Balholm
83f61a27d6 html: parse column groups
Pass tests1.dat, test 108:
<table><colgroup><col><colgroup><col><col><col><colgroup><col><col><thead><tr><td></table>

| <html>
|   <head>
|   <body>
|     <table>
|       <colgroup>
|         <col>
|       <colgroup>
|         <col>
|         <col>
|         <col>
|       <colgroup>
|         <col>
|         <col>
|       <thead>
|         <tr>
|           <td>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5369061
2011-11-11 11:41:46 +11:00
Andrew Balholm
e9e874b7fc html: parse framesets
Pass tests1.dat, test 106:
<frameset><frame><frameset><frame></frameset><noframes></noframes></frameset>

| <html>
|   <head>
|   <frameset>
|     <frame>
|     <frameset>
|       <frame>
|     <noframes>

Also pass test 107:
<h1><table><td><h3></table><h3></h1>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5373050
2011-11-10 23:56:13 +11:00
Andrew Balholm
ddc5ec642d html: don't emit text token for empty raw text elements.
Pass tests1.dat, test 99:
<script></script></div><title></title><p><p>

| <html>
|   <head>
|     <script>
|     <title>
|   <body>
|     <p>
|     <p>

Also pass tests through test 105:
<ul><li><ul></li><li>a</li></ul></li></ul>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5373043
2011-11-10 08:09:54 +11:00
Andrew Balholm
820523d091 html: correctly parse </html> in <head> element.
Pass tests1.dat, test 92:
<head></html><meta><p>

| <html>
|   <head>
|   <body>
|     <meta>
|     <p>

Also pass tests through test 98:
<p><b><div><marquee></p></b></div>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5359054
2011-11-09 19:18:26 +11:00
Rob Pike
30aa701fec renaming_2: gofix -r go1pkgrename src/pkg/[a-l]*
R=rsc
CC=golang-dev
https://golang.org/cl/5358041
2011-11-08 15:40:58 -08:00
Rob Pike
6ab6c49fce renaming_1: hand-edited files for go 1 renaming
This contains the files that required handiwork, mostly
Makefiles with updated TARGs, plus the two packages
with modified package names.
html/template/doc.go needs a separate edit pass.
test/fixedbugs/bug358.go is not legal go so gofix fails on it.

R=rsc
CC=golang-dev
https://golang.org/cl/5340050
2011-11-08 15:38:47 -08:00
Andrew Balholm
ce4eec2e0a html: treat <image> as <img>
Pass tests1.dat, test 90:
<p><image></p>

| <html>
|   <head>
|   <body>
|     <p>
|       <img>

Also pass test 91:
<a><table><a></table><p><a><div><a>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5339052
2011-11-09 09:43:55 +11:00
Andrew Balholm
f2b602ed42 html: parse <body>, <base>, <link>, <meta>, and <title> tags inside page body
Pass tests1.dat, test 87:
<body><body><base><link><meta><title><p></title><body><p></body>

| <html>
|   <head>
|   <body>
|     <base>
|     <link>
|     <meta>
|     <title>
|       "<p>"
|     <p>

Handling the last <body> tag requires correcting the original insertion mode in useTheRulesFor.

Also pass test 88:
<textarea><p></textarea>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5364047
2011-11-08 17:55:17 +11:00
Nigel Tao
46ee09eff1 html: fix typo in package docs.
Fixes #2419.

R=dsymonds, rsc
CC=golang-dev
https://golang.org/cl/5352046
2011-11-08 10:09:17 +11:00
Nigel Tao
bbd173fc3d html: be able to test more than one testdata file.
R=andybalholm
CC=golang-dev
https://golang.org/cl/5351041
2011-11-07 09:38:40 +11:00
Mike Samuel
a5291099d2 html/template: wraps package template instead of exposing func Escape
This does escaping on first execution.

template.go defines the same interface elements as package template.
It requires rather more duplication of code than I'd like, but I'm
not clear how to avoid that.

Maybe instead of

    mySet.ParseGlob(...)
    template.ParseSetGlob(...)
    mySet.ParseFiles(...)
    mySet.ParseTemplateFiles(...)
    template.ParseTemplateFiles(...)

we combine these into a fileset abstraction that can be wrapped

    var fileset template.FileSet
    fileset.Glob(...)  // Load a few files by glob
    fileset.Files(...)  // Load a few {{define}}d files
    fileset.TemplateFiles(...)  // Load a few files as template bodies
    fileset.Funcs(...)  // Make the givens func available to templates
    // Do the parsing.
    set, err := fileset.ParseSet()
    // or set, err := fileset.ParseInto(set)

or provide an interface that can receive filenames and functions and
parse messages:

    type Bundle interface {
      TemplateFile(string)
      File(string)
      Funcs(FuncMap)
    }

and define template.Parse* to handle the file-system stuff and send
messages to a bundle:

    func ParseFiles(b Bundle, filenames ...string)

R=r, r
CC=golang-dev
https://golang.org/cl/5270042
2011-11-04 13:09:21 -04:00
Gustavo Niemeyer
f2dc50b48d html,bzip2,sql: rename Error methods that return error to Err
There are three classes of methods/functions called Error:

a) The Error method in the just introduced error interface
b) Error methods that create or report errors (http.Error, etc)
c) Error methods that return errors previously associated with
   the receiver (Tokenizer.Error, rows.Error, etc).

This CL introduces the convention that methods in case (c)
should be named Err.

The reasoning for the change is:

- The change differentiates the two kinds of APIs based on
  names rather than just on signature, unloading Error a bit
- Err is closer to the err variable name that is so commonly
  used with the intent of verifying an error
- Err is shorter and thus more convenient to be used often
  on error verifications, such as in iterators following the
  convention of the sql package.

R=bradfitz, rsc
CC=golang-dev
https://golang.org/cl/5327064
2011-11-04 09:50:20 -04:00
Andrew Balholm
632a2c59b1 html: properly close <tr> element when an new <tr> starts.
Pass tests1.dat, test 87:
<table><tr><tr><td><td><span><th><span>X</table>

| <html>
|   <head>
|   <body>
|     <table>
|       <tbody>
|         <tr>
|         <tr>
|           <td>
|           <td>
|             <span>
|           <th>
|             <span>
|               "X"

R=nigeltao
CC=golang-dev
https://golang.org/cl/5343041
2011-11-04 15:48:11 +11:00
Andrew Balholm
46308d7d11 html: move <link> element from after <head> into <head>
Pass tests1.dat, test 85:
<head><meta></head><link>

| <html>
|   <head>
|     <meta>
|     <link>
|   <body>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5297079
2011-11-04 09:29:06 +11:00
Vincent Vanackere
eb1717e035 all: rename os.EOF to io.EOF in various non-code contexts
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5334050
2011-11-03 14:01:30 -07:00
Rob Pike
5cb4a15320 html,log,math: renamings
This is Go 1 package renaming CL #2.
This one merely moves the source; the import strings will be
changed after the next weekly release.

exp/template/html -> html/template
big -> math/big
cmath -> math/cmplx
rand -> math/rand
syslog -> log/syslog

The only edits are in Makefiles and deps.bash.

Note that this CL moves exp/template/html out of exp. I decided
to do that so all the renamings can be done together, even though
the API (and that of template, for that matter) is still fluid.

R=r, rsc
CC=golang-dev
https://golang.org/cl/5332053
2011-11-03 12:42:57 -07:00
Andrew Balholm
77aabbf217 html: parse <link> elements in <head>
Pass tests1.dat, test 83:
<title><meta></title><link><title><meta></title>

| <html>
|   <head>
|     <title>
|       "<meta>"
|     <link>
|     <title>
|       "<meta>"
|   <body>

Also pass test 84:
<style><!--</style><meta><script>--><link></script>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5331061
2011-11-03 17:12:13 +11:00
Andrew Balholm
cf6a712162 html: properly close <marquee> elements.
Pass tests1.dat, test 80:
<a href=a>aa<marquee>aa<a href=b>bb</marquee>aa

| <html>
|   <head>
|   <body>
|     <a>
|       href="a"
|       "aa"
|       <marquee>
|         "aa"
|         <a>
|           href="b"
|           "bb"
|       "aa"

Also pass tests through test 82:
<!DOCTYPE html><spacer>foo

R=nigeltao
CC=golang-dev
https://golang.org/cl/5319071
2011-11-03 10:11:06 +11:00
Russ Cox
c2049d2dfe src/pkg/[a-m]*: gofix -r error -force=error
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/5322051
2011-11-01 22:04:37 -04:00
Andrew Balholm
22ee5ae25a html: stop at scope marker node when generating implied </a> tags
A <a> tag generates implied end tags for any open <a> elements.
But it shouldn't do that when it is inside a table cell the the open <a>
is outside the table.
So stop the search for an open <a> when we reach a scope marker node.

Pass tests1.dat, test 78:
<a href="blah">aba<table><tr><td><a href="foo">br</td></tr>x</table>aoe

| <html>
|   <head>
|   <body>
|     <a>
|       href="blah"
|       "abax"
|       <table>
|         <tbody>
|           <tr>
|             <td>
|               <a>
|                 href="foo"
|                 "br"
|       "aoe"

Also pass test 79:
<table><a href="blah">aba<tr><td><a href="foo">br</td></tr>x</table>aoe

R=nigeltao
CC=golang-dev
https://golang.org/cl/5320063
2011-11-02 11:47:05 +11:00
Nigel Tao
90b76c0f3e html: refactor the blacklist for the "render and re-parse" test.
R=andybalholm
CC=golang-dev, mikesamuel
https://golang.org/cl/5331056
2011-11-02 09:42:25 +11:00