Improve NewHTMLWriter() defaults

HTMLWriter uses the document to look up export options and adapt it's
behaviour. The writer.document & log are set in the Before() method during
normal use via document.Write().

Sometimes the writer is used separately and won't have it's Before method
called - in those cases we should use the defaults rather than crashing.
This commit is contained in:
Niklas Fasching 2019-01-07 21:43:50 +01:00
parent 6dd8e90bb8
commit cec002db22

View file

@ -47,7 +47,10 @@ var listItemStatuses = map[string]string{
var cleanHeadlineTitleForHTMLAnchorRegexp = regexp.MustCompile(`</?a[^>]*>`) // nested a tags are not valid HTML var cleanHeadlineTitleForHTMLAnchorRegexp = regexp.MustCompile(`</?a[^>]*>`) // nested a tags are not valid HTML
func NewHTMLWriter() *HTMLWriter { func NewHTMLWriter() *HTMLWriter {
defaultConfig := New()
return &HTMLWriter{ return &HTMLWriter{
document: &Document{Configuration: defaultConfig},
log: defaultConfig.Log,
htmlEscape: true, htmlEscape: true,
HighlightCodeBlock: func(source, lang string) string { HighlightCodeBlock: func(source, lang string) string {
return fmt.Sprintf("%s\n<pre>\n%s\n</pre>\n</div>", `<div class="highlight">`, html.EscapeString(source)) return fmt.Sprintf("%s\n<pre>\n%s\n</pre>\n</div>", `<div class="highlight">`, html.EscapeString(source))