sync with current Go (gofix go1rename, error)

This commit is contained in:
Michael Teichgräber 2011-11-18 18:25:39 +01:00
parent 18aa4e492b
commit d265ac0f21

View File

@ -20,25 +20,24 @@ package markdown
// HTML output functions // HTML output functions
import ( import (
"os"
"fmt" "fmt"
"log" "log"
"rand" "math/rand"
"strings" "strings"
) )
type Writer interface { type Writer interface {
WriteString(string) (int, os.Error) WriteString(string) (int, error)
WriteRune(int) (int, os.Error) WriteRune(int) (int, error)
WriteByte(byte) os.Error WriteByte(byte) error
} }
type htmlOut struct { type htmlOut struct {
Writer Writer
padded int padded int
notenum int notenum int
endNotes []*element /* List of endnotes to print after main content. */ endNotes []*element /* List of endnotes to print after main content. */
} }
// WriteHtml prints a document tree in HTML format using the specified Writer. // WriteHtml prints a document tree in HTML format using the specified Writer.
@ -76,7 +75,6 @@ func (w *htmlOut) s(s string) *htmlOut {
return w return w
} }
/* print string, escaping for HTML /* print string, escaping for HTML
* If obfuscate selected, convert characters to hex or decimal entities at random * If obfuscate selected, convert characters to hex or decimal entities at random
*/ */
@ -159,7 +157,7 @@ func (w *htmlOut) elem(elt *element, obfuscate bool) *htmlOut {
s = elt.contents.str s = elt.contents.str
case LINK: case LINK:
if strings.Index(elt.contents.link.url, "mailto:") == 0 { if strings.Index(elt.contents.link.url, "mailto:") == 0 {
obfuscate = true /* obfuscate mailto: links */ obfuscate = true /* obfuscate mailto: links */
} }
w.s(`<a href="`).str(elt.contents.link.url, obfuscate).s(`"`) w.s(`<a href="`).str(elt.contents.link.url, obfuscate).s(`"`)
if len(elt.contents.link.title) > 0 { if len(elt.contents.link.title) > 0 {
@ -183,7 +181,7 @@ func (w *htmlOut) elem(elt *element, obfuscate bool) *htmlOut {
/* Shouldn't occur - these are handled by process_raw_blocks() */ /* Shouldn't occur - these are handled by process_raw_blocks() */
log.Fatalf("RAW") log.Fatalf("RAW")
case H1, H2, H3, H4, H5, H6: case H1, H2, H3, H4, H5, H6:
h := "h" + string('1'+elt.key-H1) + ">" /* assumes H1 ... H6 are in order */ h := "h" + string('1'+elt.key-H1) + ">" /* assumes H1 ... H6 are in order */
w.pad(2).s("<").s(h).elist(elt.children, obfuscate).s("</").s(h).pset(0) w.pad(2).s("<").s(h).elist(elt.children, obfuscate).s("</").s(h).pset(0)
case PLAIN: case PLAIN:
w.pad(1).elist(elt.children, obfuscate).pset(0) w.pad(1).elist(elt.children, obfuscate).pset(0)
@ -216,7 +214,7 @@ func (w *htmlOut) elem(elt *element, obfuscate bool) *htmlOut {
* is a note block that has been incorporated into the notes list * is a note block that has been incorporated into the notes list
*/ */
if elt.contents.str == "" { if elt.contents.str == "" {
w.endNotes = append(w.endNotes, elt) /* add an endnote to global endnotes list */ w.endNotes = append(w.endNotes, elt) /* add an endnote to global endnotes list */
w.notenum++ w.notenum++
nn := w.notenum nn := w.notenum
s = fmt.Sprintf(`<a class="noteref" id="fnref%d" href="#fn%d" title="Jump to note %d">[%d]</a>`, s = fmt.Sprintf(`<a class="noteref" id="fnref%d" href="#fn%d" title="Jump to note %d">[%d]</a>`,
@ -231,7 +229,6 @@ func (w *htmlOut) elem(elt *element, obfuscate bool) *htmlOut {
return w return w
} }
func (w *htmlOut) printEndnotes() { func (w *htmlOut) printEndnotes() {
counter := 0 counter := 0