diff --git a/block_test.go b/block_test.go index 15c3421..3c37202 100644 --- a/block_test.go +++ b/block_test.go @@ -21,7 +21,7 @@ func runMarkdownBlock(input string, extensions int) string { htmlFlags := 0 htmlFlags |= HTML_USE_XHTML - renderer := HtmlRenderer(htmlFlags, "", "", "") + renderer := HtmlRenderer(htmlFlags, "", "") return string(Markdown([]byte(input), renderer, extensions)) } diff --git a/html.go b/html.go index a63be74..f8eafbe 100644 --- a/html.go +++ b/html.go @@ -41,7 +41,7 @@ const ( HTML_USE_SMARTYPANTS // enable smart punctuation substitutions HTML_SMARTYPANTS_FRACTIONS // enable smart fractions (with HTML_USE_SMARTYPANTS) HTML_SMARTYPANTS_LATEX_DASHES // enable LaTeX-style dashes (with HTML_USE_SMARTYPANTS) - HTML_ABSOLUTE_LINKS // convert all links to absolute links + HTML_ABSOLUTE_LINKS // convert all links to absolute links, using AbsolutePrefix ) var ( @@ -55,15 +55,21 @@ var ( htmlEntity = regexp.MustCompile(`&[a-z]{2,5};`) ) +type HtmlRendererParameters struct { + AbsolutePrefix string + FootnotePrefix string +} + // Html is a type that implements the Renderer interface for HTML output. // // Do not create this directly, instead use the HtmlRenderer function. type Html struct { - flags int // HTML_* options - closeTag string // how to end singleton tags: either " />\n" or ">\n" - title string // document title - css string // optional css file url (used with HTML_COMPLETE_PAGE) - absolutePrefix string + flags int // HTML_* options + closeTag string // how to end singleton tags: either " />\n" or ">\n" + title string // document title + css string // optional css file url (used with HTML_COMPLETE_PAGE) + + parameters HtmlRendererParameters // table of contents data tocMarker int @@ -86,7 +92,12 @@ const ( // title is the title of the document, and css is a URL for the document's // stylesheet. // title and css are only used when HTML_COMPLETE_PAGE is selected. -func HtmlRenderer(flags int, title string, css string, absolutePrefix string) Renderer { +func HtmlRenderer(flags int, title string, css string) Renderer { + return HtmlRendererWithParameters(flags, title, css, HtmlRendererParameters{}) +} + +func HtmlRendererWithParameters(flags int, title string, + css string, renderParameters HtmlRendererParameters) Renderer { // configure the rendering engine closeTag := htmlClose if flags&HTML_USE_XHTML != 0 { @@ -94,11 +105,11 @@ func HtmlRenderer(flags int, title string, css string, absolutePrefix string) Re } return &Html{ - flags: flags, - closeTag: closeTag, - title: title, - css: css, - absolutePrefix: absolutePrefix, + flags: flags, + closeTag: closeTag, + title: title, + css: css, + parameters: renderParameters, headerCount: 0, currentLevel: 0, @@ -352,7 +363,9 @@ func (options *Html) FootnoteItem(out *bytes.Buffer, name, text []byte, flags in if flags&LIST_ITEM_CONTAINS_BLOCK != 0 || flags&LIST_ITEM_BEGINNING_OF_LIST != 0 { doubleSpace(out) } - out.WriteString(`