output.go: move padding stuff to a new type baseWriter
This commit is contained in:
parent
437afafa74
commit
71df3d7aa2
26
output.go
26
output.go
@ -33,9 +33,13 @@ type Writer interface {
|
|||||||
WriteByte(byte) error
|
WriteByte(byte) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type htmlOut struct {
|
type baseWriter struct {
|
||||||
Writer
|
Writer
|
||||||
padded int
|
padded int
|
||||||
|
}
|
||||||
|
|
||||||
|
type htmlOut struct {
|
||||||
|
baseWriter
|
||||||
obfuscate bool
|
obfuscate bool
|
||||||
|
|
||||||
notenum int
|
notenum int
|
||||||
@ -44,8 +48,7 @@ type htmlOut struct {
|
|||||||
|
|
||||||
func ToHTML(w Writer) Formatter {
|
func ToHTML(w Writer) Formatter {
|
||||||
f := new(htmlOut)
|
f := new(htmlOut)
|
||||||
f.Writer = w
|
f.baseWriter = baseWriter{w, 2}
|
||||||
f.padded = 2
|
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
func (f *htmlOut) FormatBlock(tree *element) {
|
func (f *htmlOut) FormatBlock(tree *element) {
|
||||||
@ -64,20 +67,21 @@ func (f *htmlOut) Finish() {
|
|||||||
// One newline means a line break, similar to troff's .br
|
// One newline means a line break, similar to troff's .br
|
||||||
// request, two newlines mean a line break plus an
|
// request, two newlines mean a line break plus an
|
||||||
// empty line, similar to troff's .sp request
|
// empty line, similar to troff's .sp request
|
||||||
func (h *htmlOut) pad(n int) *htmlOut {
|
func (w *baseWriter) pad(n int) {
|
||||||
for ; n > h.padded; n-- {
|
for ; n > w.padded; n-- {
|
||||||
h.WriteByte('\n')
|
w.WriteByte('\n')
|
||||||
}
|
}
|
||||||
h.padded = 0
|
w.padded = 0
|
||||||
return h
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *htmlOut) br() *htmlOut {
|
func (h *htmlOut) br() *htmlOut {
|
||||||
return h.pad(1)
|
h.pad(1)
|
||||||
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *htmlOut) sp() *htmlOut {
|
func (h *htmlOut) sp() *htmlOut {
|
||||||
return h.pad(2)
|
h.pad(2)
|
||||||
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *htmlOut) skipPadding() *htmlOut {
|
func (h *htmlOut) skipPadding() *htmlOut {
|
||||||
|
Loading…
Reference in New Issue
Block a user