html_tag.go
func (e *htmlTag) WriteTo(w io.Writer) (int64, error) {
	var bf bytes.Buffer

	// Write an open tag.
	bf.WriteString(lt)
	bf.WriteString(e.tagName)
	// Write an id.
	if e.id != "" {
		bf.WriteString(space)
		bf.WriteString(attributeNameID)
		bf.WriteString(equal)
		bf.WriteString(doubleQuote)
		bf.WriteString(e.id)
		bf.WriteString(doubleQuote)
	}
	// Write classes.
	if len(e.classes) > 0 {
		bf.WriteString(space)
		bf.WriteString(e.opts.AttributeNameClass)
		bf.WriteString(equal)
		bf.WriteString(doubleQuote)
		for i, class := range e.classes {
			if i > 0 {
				bf.WriteString(space)
			}
			bf.WriteString(class)
		}
		bf.WriteString(doubleQuote)
	}
	// Write attributes.
	if len(e.attributes) > 0 {

		for _, a := range e.attributes {
			bf.WriteString(space)
			bf.WriteString(a.key)
			if a.value != "" {
				bf.WriteString(equal)
				bf.WriteString(doubleQuote)
				bf.WriteString(a.value)
				bf.WriteString(doubleQuote)
			}
		}
	}
	bf.WriteString(gt)

	// Write a text value
	if e.textValue != "" {
		if e.opts.formatter != nil {
			e.opts.formatter.WritingTextValue(&bf, e)
		}
		bf.WriteString(e.textValue)
	}

	if e.containPlainText {
		bf.WriteString(lf)
	}

	// Write children's HTML.
	if i, err := e.writeChildren(&bf); err != nil {
		return i, err
	}

	// Write a close tag.
	if !e.noCloseTag() {
		if e.opts.formatter != nil {
			e.opts.formatter.ClosingElement(&bf, e)
		}
		bf.WriteString(lt)
		bf.WriteString(slash)
		bf.WriteString(e.tagName)
		bf.WriteString(gt)
	}

	// Write the buffer.
	i, err := w.Write(bf.Bytes())

	return int64(i), err
}
func (e *htmlTag) WriteTo(w io.Writer) (int64, error) {
	var bf bytes.Buffer

	// Write an open tag.
	bf.WriteString(lt)
	bf.WriteString(e.tagName)
	// Write an id.
	if e.id != "" {
		bf.WriteString(space)
		bf.WriteString(attributeNameID)
		bf.WriteString(equal)
		bf.WriteString(doubleQuote)
		bf.WriteString(e.id)
		bf.WriteString(doubleQuote)
	}
	// Write classes.
	if len(e.classes) > 0 {
		bf.WriteString(space)
		bf.WriteString(e.opts.AttributeNameClass)
		bf.WriteString(equal)
		bf.WriteString(doubleQuote)
		for i, class := range e.classes {
			if i > 0 {
				bf.WriteString(space)
			}
			bf.WriteString(class)
		}
		bf.WriteString(doubleQuote)
	}
	// Write attributes.
	if len(e.attributes) > 0 {

		for _, a := range e.attributes {
			bf.WriteString(space)
			bf.WriteString(a.key)
			if a.value != "" {
				bf.WriteString(equal)
				bf.WriteString(doubleQuote)
				bf.WriteString(a.value)
				bf.WriteString(doubleQuote)
			}
		}
	}
	bf.WriteString(gt)

	// Write a text value
	if e.textValue != "" {
		if e.opts.formatter != nil {
			e.opts.formatter.WritingTextValue(&bf, e)
		}
		bf.WriteString(e.textValue)
	}

	if e.containPlainText {
		bf.WriteString(lf)
	}

	// Write children's HTML.
	if i, err := e.writeChildren(&bf); err != nil {
		return i, err
	}

	// Write a close tag.
	if !e.noCloseTag() {
		if e.opts.formatter != nil {
			e.opts.formatter.ClosingElement(&bf, e)
		}
		bf.WriteString(lt)
		bf.WriteString(slash)
		bf.WriteString(e.tagName)
		bf.WriteString(gt)
	}

	// Write the buffer.
	i, err := w.Write(bf.Bytes())

	return int64(i), err
}
// WriteTo writes data to w.