From 318858ce0ab159884488d2647f2d8d15423434f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Teichgr=C3=A4ber?= Date: Thu, 26 Apr 2012 21:35:18 +0200 Subject: [PATCH] output.go: move some code into methods --- output.go | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/output.go b/output.go index 2b101dd..68f9a4c 100644 --- a/output.go +++ b/output.go @@ -119,6 +119,19 @@ func (w *htmlOut) str(s string) *htmlOut { return w } +func (w *htmlOut) children(el *element) *htmlOut { + return w.elist(el.children) +} +func (w *htmlOut) inline(tag string, el *element) *htmlOut { + return w.s(tag).children(el).s("").str(elt.contents.str).s("") case HTML: @@ -175,21 +188,21 @@ func (w *htmlOut) elem(elt *element) *htmlOut { } w.s(" />") case EMPH: - w.s("").elist(elt.children).s("") + w.inline("", elt) case STRONG: - w.s("").elist(elt.children).s("") + w.inline("", elt) case LIST: - w.elist(elt.children) + w.children(elt) case RAW: /* Shouldn't occur - these are handled by process_raw_blocks() */ log.Fatalf("RAW") case H1, H2, H3, H4, H5, H6: - h := "h" + string('1'+elt.key-H1) + ">" /* assumes H1 ... H6 are in order */ - w.pad(2).s("<").s(h).elist(elt.children).s("" /* assumes H1 ... H6 are in order */ + w.pad(2).inline(h, elt).pset(0) case PLAIN: - w.pad(1).elist(elt.children).pset(0) + w.pad(1).children(elt).pset(0) case PARA: - w.pad(2).s("

").elist(elt.children).s("

").pset(0) + w.pad(2).inline("

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


").pset(0) case HTMLBLOCK: @@ -197,19 +210,19 @@ func (w *htmlOut) elem(elt *element) *htmlOut { case VERBATIM: w.pad(2).s("
").str(elt.contents.str).s("
").pset(0) case BULLETLIST: - w.pad(2).s("
    ").pset(0).elist(elt.children).pad(1).s("
").pset(0) + w.listBlock("
    ", elt) case ORDEREDLIST: - w.pad(2).s("
      ").pset(0).elist(elt.children).pad(1).s("
    ").pset(0) + w.listBlock("
      ", elt) case DEFINITIONLIST: - w.pad(2).s("
      ").pset(0).elist(elt.children).pad(1).s("
      ").pset(0) + w.listBlock("
      ", elt) case DEFTITLE: - w.pad(1).s("
      ").pset(2).elist(elt.children).s("
      ").pset(0) + w.listItem("
      ", elt) case DEFDATA: - w.pad(1).s("
      ").pset(2).elist(elt.children).s("
      ").pset(0) + w.listItem("
      ", elt) case LISTITEM: - w.pad(1).s("
    1. ").pset(2).elist(elt.children).s("
    2. ").pset(0) + w.listItem("
    3. ", elt) case BLOCKQUOTE: - w.pad(2).s("
      \n").pset(2).elist(elt.children).pad(1).s("
      ").pset(0) + w.pad(2).s("
      \n").pset(2).children(elt).pad(1).s("
      ").pset(0) case REFERENCE: /* Nonprinting */ case NOTE: @@ -239,7 +252,7 @@ func (w *htmlOut) printEndnotes() { for _, elt := range w.endNotes { counter++ w.pad(1).s(fmt.Sprintf("
    4. \n", counter)).pset(2) - w.elist(elt.children) + w.children(elt) w.s(fmt.Sprintf(" [back]", counter)) w.pad(1).s("
    5. ") }