Go style: more Html -> HTML renames
This commit is contained in:
parent
02a5ce37ff
commit
0b69796248
|
@ -23,13 +23,13 @@ func runMarkdownBlockWithRenderer(input string, extensions Extensions, renderer
|
|||
}
|
||||
|
||||
func runMarkdownBlock(input string, extensions Extensions) string {
|
||||
renderer := HtmlRenderer(UseXHTML, extensions, "", "")
|
||||
renderer := HTMLRenderer(UseXHTML, extensions, "", "")
|
||||
return runMarkdownBlockWithRenderer(input, extensions, renderer)
|
||||
}
|
||||
|
||||
func runnerWithRendererParameters(parameters HtmlRendererParameters) func(string, Extensions) string {
|
||||
func runnerWithRendererParameters(parameters HTMLRendererParameters) func(string, Extensions) string {
|
||||
return func(input string, extensions Extensions) string {
|
||||
renderer := HtmlRendererWithParameters(UseXHTML, extensions, "", "", parameters)
|
||||
renderer := HTMLRendererWithParameters(UseXHTML, extensions, "", "", parameters)
|
||||
return runMarkdownBlockWithRenderer(input, extensions, renderer)
|
||||
}
|
||||
}
|
||||
|
@ -298,7 +298,7 @@ func TestPrefixHeaderIdExtensionWithPrefixAndSuffix(t *testing.T) {
|
|||
"<h1 id=\"PRE:someid:POST\">Nested header</h1></li>\n</ul></li>\n</ul>\n",
|
||||
}
|
||||
|
||||
parameters := HtmlRendererParameters{
|
||||
parameters := HTMLRendererParameters{
|
||||
HeaderIDPrefix: "PRE:",
|
||||
HeaderIDSuffix: ":POST",
|
||||
}
|
||||
|
@ -406,7 +406,7 @@ func TestPrefixAutoHeaderIdExtensionWithPrefixAndSuffix(t *testing.T) {
|
|||
"<h1 id=\"PRE:header:POST\">Header</h1>\n\n<h1 id=\"PRE:header-1:POST\">Header 1</h1>\n\n<h1 id=\"PRE:header-1-1:POST\">Header</h1>\n\n<h1 id=\"PRE:header-1-2:POST\">Header</h1>\n",
|
||||
}
|
||||
|
||||
parameters := HtmlRendererParameters{
|
||||
parameters := HTMLRendererParameters{
|
||||
HeaderIDPrefix: "PRE:",
|
||||
HeaderIDSuffix: ":POST",
|
||||
}
|
||||
|
|
30
html.go
30
html.go
|
@ -68,7 +68,7 @@ var (
|
|||
reHtmlTag = regexp.MustCompile("(?i)^" + HTMLTag)
|
||||
)
|
||||
|
||||
type HtmlRendererParameters struct {
|
||||
type HTMLRendererParameters struct {
|
||||
// Prepend this text to each relative URL.
|
||||
AbsolutePrefix string
|
||||
// Add this text to each footnote anchor, to ensure uniqueness.
|
||||
|
@ -86,14 +86,14 @@ type HtmlRendererParameters struct {
|
|||
|
||||
// HTML is a type that implements the Renderer interface for HTML output.
|
||||
//
|
||||
// Do not create this directly, instead use the HtmlRenderer function.
|
||||
// Do not create this directly, instead use the HTMLRenderer function.
|
||||
type HTML struct {
|
||||
flags HTMLFlags
|
||||
closeTag string // how to end singleton tags: either " />" or ">"
|
||||
title string // document title
|
||||
css string // optional css file url (used with HTML_COMPLETE_PAGE)
|
||||
|
||||
parameters HtmlRendererParameters
|
||||
parameters HTMLRendererParameters
|
||||
|
||||
// table of contents data
|
||||
tocMarker int
|
||||
|
@ -104,7 +104,7 @@ type HTML struct {
|
|||
// Track header IDs to prevent ID collision in a single generation.
|
||||
headerIDs map[string]int
|
||||
|
||||
w HtmlWriter
|
||||
w HTMLWriter
|
||||
lastOutputLen int
|
||||
disableTags int
|
||||
|
||||
|
@ -116,36 +116,36 @@ const (
|
|||
htmlClose = ">"
|
||||
)
|
||||
|
||||
// HtmlRenderer creates and configures an HTML object, which
|
||||
// HTMLRenderer creates and configures an HTML object, which
|
||||
// satisfies the Renderer interface.
|
||||
//
|
||||
// flags is a set of HTMLFlags ORed together.
|
||||
// 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 HTMLFlags, extensions Extensions, title string, css string) Renderer {
|
||||
return HtmlRendererWithParameters(flags, extensions, title, css, HtmlRendererParameters{})
|
||||
func HTMLRenderer(flags HTMLFlags, extensions Extensions, title string, css string) Renderer {
|
||||
return HTMLRendererWithParameters(flags, extensions, title, css, HTMLRendererParameters{})
|
||||
}
|
||||
|
||||
type HtmlWriter struct {
|
||||
type HTMLWriter struct {
|
||||
output bytes.Buffer
|
||||
}
|
||||
|
||||
func (w *HtmlWriter) Write(p []byte) (n int, err error) {
|
||||
func (w *HTMLWriter) Write(p []byte) (n int, err error) {
|
||||
return w.output.Write(p)
|
||||
}
|
||||
|
||||
func (w *HtmlWriter) WriteString(s string) (n int, err error) {
|
||||
func (w *HTMLWriter) WriteString(s string) (n int, err error) {
|
||||
return w.output.WriteString(s)
|
||||
}
|
||||
|
||||
func (w *HtmlWriter) WriteByte(b byte) error {
|
||||
func (w *HTMLWriter) WriteByte(b byte) error {
|
||||
return w.output.WriteByte(b)
|
||||
}
|
||||
|
||||
// Writes out a newline if the output is not pristine. Used at the beginning of
|
||||
// every rendering func
|
||||
func (w *HtmlWriter) Newline() {
|
||||
func (w *HTMLWriter) Newline() {
|
||||
w.WriteByte('\n')
|
||||
}
|
||||
|
||||
|
@ -153,8 +153,8 @@ func (r *HTML) Write(b []byte) (int, error) {
|
|||
return r.w.Write(b)
|
||||
}
|
||||
|
||||
func HtmlRendererWithParameters(flags HTMLFlags, extensions Extensions, title string,
|
||||
css string, renderParameters HtmlRendererParameters) Renderer {
|
||||
func HTMLRendererWithParameters(flags HTMLFlags, extensions Extensions, title string,
|
||||
css string, renderParameters HTMLRendererParameters) Renderer {
|
||||
// configure the rendering engine
|
||||
closeTag := htmlClose
|
||||
if flags&UseXHTML != 0 {
|
||||
|
@ -165,7 +165,7 @@ func HtmlRendererWithParameters(flags HTMLFlags, extensions Extensions, title st
|
|||
renderParameters.FootnoteReturnLinkContents = `<sup>[return]</sup>`
|
||||
}
|
||||
|
||||
var writer HtmlWriter
|
||||
var writer HTMLWriter
|
||||
return &HTML{
|
||||
flags: flags,
|
||||
extensions: extensions,
|
||||
|
|
|
@ -20,44 +20,44 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
func runMarkdownInline(input string, opts Options, htmlFlags HTMLFlags, params HtmlRendererParameters) string {
|
||||
func runMarkdownInline(input string, opts Options, htmlFlags HTMLFlags, params HTMLRendererParameters) string {
|
||||
opts.Extensions |= Autolink
|
||||
opts.Extensions |= Strikethrough
|
||||
|
||||
htmlFlags |= UseXHTML
|
||||
|
||||
renderer := HtmlRendererWithParameters(htmlFlags, opts.Extensions, "", "", params)
|
||||
renderer := HTMLRendererWithParameters(htmlFlags, opts.Extensions, "", "", params)
|
||||
|
||||
return string(MarkdownOptions([]byte(input), renderer, opts))
|
||||
}
|
||||
|
||||
func doTestsInline(t *testing.T, tests []string) {
|
||||
doTestsInlineParam(t, tests, Options{}, 0, HtmlRendererParameters{})
|
||||
doTestsInlineParam(t, tests, Options{}, 0, HTMLRendererParameters{})
|
||||
}
|
||||
|
||||
func doLinkTestsInline(t *testing.T, tests []string) {
|
||||
doTestsInline(t, tests)
|
||||
|
||||
prefix := "http://localhost"
|
||||
params := HtmlRendererParameters{AbsolutePrefix: prefix}
|
||||
params := HTMLRendererParameters{AbsolutePrefix: prefix}
|
||||
transformTests := transformLinks(tests, prefix)
|
||||
doTestsInlineParam(t, transformTests, Options{}, 0, params)
|
||||
doTestsInlineParam(t, transformTests, Options{}, CommonHtmlFlags, params)
|
||||
}
|
||||
|
||||
func doSafeTestsInline(t *testing.T, tests []string) {
|
||||
doTestsInlineParam(t, tests, Options{}, Safelink, HtmlRendererParameters{})
|
||||
doTestsInlineParam(t, tests, Options{}, Safelink, HTMLRendererParameters{})
|
||||
|
||||
// All the links in this test should not have the prefix appended, so
|
||||
// just rerun it with different parameters and the same expectations.
|
||||
prefix := "http://localhost"
|
||||
params := HtmlRendererParameters{AbsolutePrefix: prefix}
|
||||
params := HTMLRendererParameters{AbsolutePrefix: prefix}
|
||||
transformTests := transformLinks(tests, prefix)
|
||||
doTestsInlineParam(t, transformTests, Options{}, Safelink, params)
|
||||
}
|
||||
|
||||
func doTestsInlineParam(t *testing.T, tests []string, opts Options, htmlFlags HTMLFlags,
|
||||
params HtmlRendererParameters) {
|
||||
params HTMLRendererParameters) {
|
||||
// catch and report panics
|
||||
var candidate string
|
||||
/*
|
||||
|
@ -214,7 +214,7 @@ func TestReferenceOverride(t *testing.T) {
|
|||
}, true
|
||||
}
|
||||
return nil, false
|
||||
}}, 0, HtmlRendererParameters{})
|
||||
}}, 0, HTMLRendererParameters{})
|
||||
}
|
||||
|
||||
func TestStrong(t *testing.T) {
|
||||
|
@ -426,7 +426,7 @@ func TestLineBreak(t *testing.T) {
|
|||
}
|
||||
doTestsInlineParam(t, tests, Options{
|
||||
Extensions: BackslashLineBreak},
|
||||
0, HtmlRendererParameters{})
|
||||
0, HTMLRendererParameters{})
|
||||
}
|
||||
|
||||
func TestInlineLink(t *testing.T) {
|
||||
|
@ -567,7 +567,7 @@ func TestRelAttrLink(t *testing.T) {
|
|||
"<p><a href=\"../bar\">foo</a></p>\n",
|
||||
}
|
||||
doTestsInlineParam(t, nofollowTests, Options{}, Safelink|NofollowLinks,
|
||||
HtmlRendererParameters{})
|
||||
HTMLRendererParameters{})
|
||||
|
||||
var noreferrerTests = []string{
|
||||
"[foo](http://bar.com/foo/)\n",
|
||||
|
@ -577,7 +577,7 @@ func TestRelAttrLink(t *testing.T) {
|
|||
"<p><a href=\"/bar/\">foo</a></p>\n",
|
||||
}
|
||||
doTestsInlineParam(t, noreferrerTests, Options{}, Safelink|NoreferrerLinks,
|
||||
HtmlRendererParameters{})
|
||||
HTMLRendererParameters{})
|
||||
|
||||
var nofollownoreferrerTests = []string{
|
||||
"[foo](http://bar.com/foo/)\n",
|
||||
|
@ -587,7 +587,7 @@ func TestRelAttrLink(t *testing.T) {
|
|||
"<p><a href=\"/bar/\">foo</a></p>\n",
|
||||
}
|
||||
doTestsInlineParam(t, nofollownoreferrerTests, Options{}, Safelink|NofollowLinks|NoreferrerLinks,
|
||||
HtmlRendererParameters{})
|
||||
HTMLRendererParameters{})
|
||||
}
|
||||
|
||||
func TestHrefTargetBlank(t *testing.T) {
|
||||
|
@ -614,7 +614,7 @@ func TestHrefTargetBlank(t *testing.T) {
|
|||
"[foo](http://example.com)\n",
|
||||
"<p><a href=\"http://example.com\" target=\"_blank\">foo</a></p>\n",
|
||||
}
|
||||
doTestsInlineParam(t, tests, Options{}, Safelink|HrefTargetBlank, HtmlRendererParameters{})
|
||||
doTestsInlineParam(t, tests, Options{}, Safelink|HrefTargetBlank, HTMLRendererParameters{})
|
||||
}
|
||||
|
||||
func TestSafeInlineLink(t *testing.T) {
|
||||
|
@ -1002,7 +1002,7 @@ what happens here
|
|||
}
|
||||
|
||||
func TestFootnotes(t *testing.T) {
|
||||
doTestsInlineParam(t, footnoteTests, Options{Extensions: Footnotes}, 0, HtmlRendererParameters{})
|
||||
doTestsInlineParam(t, footnoteTests, Options{Extensions: Footnotes}, 0, HTMLRendererParameters{})
|
||||
}
|
||||
|
||||
func TestFootnotesWithParameters(t *testing.T) {
|
||||
|
@ -1022,7 +1022,7 @@ func TestFootnotesWithParameters(t *testing.T) {
|
|||
tests[i] = test
|
||||
}
|
||||
|
||||
params := HtmlRendererParameters{
|
||||
params := HTMLRendererParameters{
|
||||
FootnoteAnchorPrefix: prefix,
|
||||
FootnoteReturnLinkContents: returnText,
|
||||
}
|
||||
|
@ -1055,7 +1055,7 @@ func TestNestedFootnotes(t *testing.T) {
|
|||
`,
|
||||
}
|
||||
doTestsInlineParam(t, tests, Options{Extensions: Footnotes}, 0,
|
||||
HtmlRendererParameters{})
|
||||
HTMLRendererParameters{})
|
||||
}
|
||||
|
||||
func TestInlineComments(t *testing.T) {
|
||||
|
@ -1084,7 +1084,7 @@ func TestInlineComments(t *testing.T) {
|
|||
"blahblah\n<!--- foo -->\nrhubarb\n",
|
||||
"<p>blahblah\n<!--- foo -->\nrhubarb</p>\n",
|
||||
}
|
||||
doTestsInlineParam(t, tests, Options{Extensions: Smartypants | SmartypantsDashes}, 0, HtmlRendererParameters{})
|
||||
doTestsInlineParam(t, tests, Options{Extensions: Smartypants | SmartypantsDashes}, 0, HTMLRendererParameters{})
|
||||
}
|
||||
|
||||
func TestSmartDoubleQuotes(t *testing.T) {
|
||||
|
@ -1096,7 +1096,7 @@ func TestSmartDoubleQuotes(t *testing.T) {
|
|||
"two pair of \"some\" quoted \"text\".\n",
|
||||
"<p>two pair of “some” quoted “text”.</p>\n"}
|
||||
|
||||
doTestsInlineParam(t, tests, Options{Extensions: Smartypants}, 0, HtmlRendererParameters{})
|
||||
doTestsInlineParam(t, tests, Options{Extensions: Smartypants}, 0, HTMLRendererParameters{})
|
||||
}
|
||||
|
||||
func TestSmartAngledDoubleQuotes(t *testing.T) {
|
||||
|
@ -1108,7 +1108,7 @@ func TestSmartAngledDoubleQuotes(t *testing.T) {
|
|||
"two pair of \"some\" quoted \"text\".\n",
|
||||
"<p>two pair of «some» quoted «text».</p>\n"}
|
||||
|
||||
doTestsInlineParam(t, tests, Options{Extensions: Smartypants | SmartypantsAngledQuotes}, 0, HtmlRendererParameters{})
|
||||
doTestsInlineParam(t, tests, Options{Extensions: Smartypants | SmartypantsAngledQuotes}, 0, HTMLRendererParameters{})
|
||||
}
|
||||
|
||||
func TestSmartFractions(t *testing.T) {
|
||||
|
@ -1118,7 +1118,7 @@ func TestSmartFractions(t *testing.T) {
|
|||
"1/2/2015, 1/4/2015, 3/4/2015; 2015/1/2, 2015/1/4, 2015/3/4.\n",
|
||||
"<p>1/2/2015, 1/4/2015, 3/4/2015; 2015/1/2, 2015/1/4, 2015/3/4.</p>\n"}
|
||||
|
||||
doTestsInlineParam(t, tests, Options{Extensions: Smartypants}, 0, HtmlRendererParameters{})
|
||||
doTestsInlineParam(t, tests, Options{Extensions: Smartypants}, 0, HTMLRendererParameters{})
|
||||
|
||||
tests = []string{
|
||||
"1/2, 2/3, 81/100 and 1000000/1048576.\n",
|
||||
|
@ -1126,7 +1126,7 @@ func TestSmartFractions(t *testing.T) {
|
|||
"1/2/2015, 1/4/2015, 3/4/2015; 2015/1/2, 2015/1/4, 2015/3/4.\n",
|
||||
"<p>1/2/2015, 1/4/2015, 3/4/2015; 2015/1/2, 2015/1/4, 2015/3/4.</p>\n"}
|
||||
|
||||
doTestsInlineParam(t, tests, Options{Extensions: Smartypants | SmartypantsFractions}, 0, HtmlRendererParameters{})
|
||||
doTestsInlineParam(t, tests, Options{Extensions: Smartypants | SmartypantsFractions}, 0, HTMLRendererParameters{})
|
||||
}
|
||||
|
||||
func TestDisableSmartDashes(t *testing.T) {
|
||||
|
@ -1137,7 +1137,7 @@ func TestDisableSmartDashes(t *testing.T) {
|
|||
"<p>foo -- bar</p>\n",
|
||||
"foo --- bar\n",
|
||||
"<p>foo --- bar</p>\n",
|
||||
}, Options{}, 0, HtmlRendererParameters{})
|
||||
}, Options{}, 0, HTMLRendererParameters{})
|
||||
doTestsInlineParam(t, []string{
|
||||
"foo - bar\n",
|
||||
"<p>foo – bar</p>\n",
|
||||
|
@ -1145,7 +1145,7 @@ func TestDisableSmartDashes(t *testing.T) {
|
|||
"<p>foo — bar</p>\n",
|
||||
"foo --- bar\n",
|
||||
"<p>foo —– bar</p>\n",
|
||||
}, Options{Extensions: Smartypants | SmartypantsDashes}, 0, HtmlRendererParameters{})
|
||||
}, Options{Extensions: Smartypants | SmartypantsDashes}, 0, HTMLRendererParameters{})
|
||||
doTestsInlineParam(t, []string{
|
||||
"foo - bar\n",
|
||||
"<p>foo - bar</p>\n",
|
||||
|
@ -1154,7 +1154,7 @@ func TestDisableSmartDashes(t *testing.T) {
|
|||
"foo --- bar\n",
|
||||
"<p>foo — bar</p>\n",
|
||||
}, Options{Extensions: Smartypants | SmartypantsLatexDashes | SmartypantsDashes}, 0,
|
||||
HtmlRendererParameters{})
|
||||
HTMLRendererParameters{})
|
||||
doTestsInlineParam(t, []string{
|
||||
"foo - bar\n",
|
||||
"<p>foo - bar</p>\n",
|
||||
|
@ -1164,5 +1164,5 @@ func TestDisableSmartDashes(t *testing.T) {
|
|||
"<p>foo --- bar</p>\n",
|
||||
}, Options{Extensions: Smartypants | SmartypantsLatexDashes},
|
||||
0,
|
||||
HtmlRendererParameters{})
|
||||
HTMLRendererParameters{})
|
||||
}
|
||||
|
|
4
latex.go
4
latex.go
|
@ -21,7 +21,7 @@ import "bytes"
|
|||
//
|
||||
// Do not create this directly, instead use the LatexRenderer function.
|
||||
type Latex struct {
|
||||
w HtmlWriter
|
||||
w HTMLWriter
|
||||
}
|
||||
|
||||
// LatexRenderer creates and configures a Latex object, which
|
||||
|
@ -30,7 +30,7 @@ type Latex struct {
|
|||
// flags is a set of LATEX_* options ORed together (currently no such options
|
||||
// are defined).
|
||||
func LatexRenderer(flags int) Renderer {
|
||||
var writer HtmlWriter
|
||||
var writer HTMLWriter
|
||||
return &Latex{
|
||||
w: writer,
|
||||
}
|
||||
|
|
|
@ -344,7 +344,7 @@ type Options struct {
|
|||
func MarkdownBasic(input []byte) []byte {
|
||||
// set up the HTML renderer
|
||||
htmlFlags := UseXHTML
|
||||
renderer := HtmlRenderer(htmlFlags, CommonExtensions, "", "")
|
||||
renderer := HTMLRenderer(htmlFlags, CommonExtensions, "", "")
|
||||
|
||||
// set up the parser
|
||||
return MarkdownOptions(input, renderer, Options{Extensions: 0})
|
||||
|
@ -371,7 +371,7 @@ func MarkdownBasic(input []byte) []byte {
|
|||
// * Custom Header IDs
|
||||
func MarkdownCommon(input []byte) []byte {
|
||||
// set up the HTML renderer
|
||||
renderer := HtmlRenderer(CommonHtmlFlags, CommonExtensions, "", "")
|
||||
renderer := HTMLRenderer(CommonHtmlFlags, CommonExtensions, "", "")
|
||||
return MarkdownOptions(input, renderer, DefaultOptions)
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ import (
|
|||
)
|
||||
|
||||
func runMarkdownReference(input string, flag Extensions) string {
|
||||
renderer := HtmlRenderer(0, flag, "", "")
|
||||
renderer := HTMLRenderer(0, flag, "", "")
|
||||
return string(Markdown([]byte(input), renderer, flag))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue