From 437afafa74dc3591e2fbd523d3da73a2c8adf49f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Teichgr=C3=A4ber?= Date: Thu, 9 Aug 2012 20:36:43 +0200 Subject: [PATCH] output.go: slightly rearrange padding, add br() and sp() methods --- output.go | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/output.go b/output.go index 80e0083..4a90302 100644 --- a/output.go +++ b/output.go @@ -53,23 +53,35 @@ func (f *htmlOut) FormatBlock(tree *element) { } func (f *htmlOut) Finish() { if len(f.endNotes) != 0 { - f.pad(2) + f.sp() f.printEndnotes() } f.WriteByte('\n') } -// pad - add newlines if needed +// pad - add a number of newlines, the value of the +// argument minus the value of `padded' +// One newline means a line break, similar to troff's .br +// request, two newlines mean a line break plus an +// empty line, similar to troff's .sp request func (h *htmlOut) pad(n int) *htmlOut { for ; n > h.padded; n-- { h.WriteByte('\n') } - h.padded = n + h.padded = 0 return h } -func (h *htmlOut) pset(n int) *htmlOut { - h.padded = n +func (h *htmlOut) br() *htmlOut { + return h.pad(1) +} + +func (h *htmlOut) sp() *htmlOut { + return h.pad(2) +} + +func (h *htmlOut) skipPadding() *htmlOut { + h.padded = 2 return h } @@ -130,10 +142,10 @@ func (w *htmlOut) inline(tag string, el *element) *htmlOut { return w.s(tag).children(el).s("" /* assumes H1 ... H6 are in order */ - w.pad(2).inline(h, elt).pset(0) + w.sp().inline(h, elt) case PLAIN: - w.pad(1).children(elt).pset(0) + w.br().children(elt) case PARA: - w.pad(2).inline("

", elt).pset(0) + w.sp().inline("

", elt) case HRULE: - w.pad(2).s("


").pset(0) + w.sp().s("
") case HTMLBLOCK: - w.pad(2).s(elt.contents.str).pset(0) + w.sp().s(elt.contents.str) case VERBATIM: - w.pad(2).s("
").str(elt.contents.str).s("
").pset(0) + w.sp().s("
").str(elt.contents.str).s("
") case BULLETLIST: w.listBlock("