code: func rewriteHTML(reader io.Reader, writer io.Writer, urlRewriter func(string) string) error {
  	// Note: This assumes the content is UTF-8.
  	tokenizer := html.NewTokenizer(reader)
  
  	var err error
  	for err == nil {
  		tokenType := tokenizer.Next()
  		switch tokenType {
  		case html.ErrorToken:
  			err = tokenizer.Err()
  		case html.StartTagToken, html.SelfClosingTagToken:
  			token := tokenizer.Token()
  			if urlAttrs, ok := atomsToAttrs[token.DataAtom]; ok {
  				for i, attr := range token.Attr {
  					if urlAttrs.Has(attr.Key) {
  						token.Attr[i].Val = urlRewriter(attr.Val)
  					}
  				}
  			}
  			_, err = writer.Write([]byte(token.String()))
  		default:
  			_, err = writer.Write(tokenizer.Raw())
  		}
  	}
  	if err != io.EOF {
  		return err
  	}
  	return nil
  }
docs: // rewriteHTML scans the HTML for tags with url-valued attributes, and updates
  // those values with the urlRewriter function. The updated HTML is output to the
  // writer.