diff options
author | Austin Ziegler <austin@zieglers.ca> | 2014-10-29 01:08:31 -0400 |
---|---|---|
committer | spf13 <steve.francia@gmail.com> | 2014-11-24 18:01:57 -0500 |
commit | 8f9cea7f58e8acbffd2a14bc41225f4609963584 (patch) | |
tree | 89842296a5c842a497f30a1f93297725ad2d2100 /helpers/content.go | |
parent | 0282c922b4d788dcb9a281f036fe24280edd0054 (diff) |
Enable descriptive header IDs.
Enable blackfriday.EXTENSION_AUTO_HEADER_IDS to generate the name of the
header ID from the text in the header. Works for prefix and underline
headers.
- TOC extraction had to be modified to look for `<li><a href="#`>
instead of `#toc_` because of this change.
- Fixed a number of tests that depended on the presence of `toc_` with
as an `id` or as a `href` value.
- Renames the earlier parameter `footnoteref` to `documentId` as it more
accurately represents the nature of the parameter. The `documentId` is
appended to all generated headers through the new HTML renderer
parameter `HeaderIDSuffix`.
Diffstat (limited to 'helpers/content.go')
-rw-r--r-- | helpers/content.go | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/helpers/content.go b/helpers/content.go index 96e84e5cf..9b46bbe83 100644 --- a/helpers/content.go +++ b/helpers/content.go @@ -69,15 +69,15 @@ func BytesToHTML(b []byte) template.HTML { return template.HTML(string(b)) } -func GetHtmlRenderer(defaultFlags int, footnoteref string) blackfriday.Renderer { +func GetHtmlRenderer(defaultFlags int, documentId string) blackfriday.Renderer { renderParameters := blackfriday.HtmlRendererParameters{ FootnoteAnchorPrefix: viper.GetString("FootnoteAnchorPrefix"), FootnoteReturnLinkContents: viper.GetString("FootnoteReturnLinkContents"), } - if len(footnoteref) != 0 { - renderParameters.FootnoteAnchorPrefix = footnoteref + ":" + - renderParameters.FootnoteAnchorPrefix + if len(documentId) != 0 { + renderParameters.FootnoteAnchorPrefix = documentId + ":" + renderParameters.FootnoteAnchorPrefix + renderParameters.HeaderIDSuffix = ":" + documentId } htmlFlags := defaultFlags @@ -95,17 +95,17 @@ func GetMarkdownExtensions() int { blackfriday.EXTENSION_TABLES | blackfriday.EXTENSION_FENCED_CODE | blackfriday.EXTENSION_AUTOLINK | blackfriday.EXTENSION_STRIKETHROUGH | blackfriday.EXTENSION_SPACE_HEADERS | blackfriday.EXTENSION_FOOTNOTES | - blackfriday.EXTENSION_HEADER_IDS + blackfriday.EXTENSION_HEADER_IDS | blackfriday.EXTENSION_AUTO_HEADER_IDS } -func MarkdownRender(content []byte, footnoteref string) []byte { - return blackfriday.Markdown(content, GetHtmlRenderer(0, footnoteref), +func MarkdownRender(content []byte, documentId string) []byte { + return blackfriday.Markdown(content, GetHtmlRenderer(0, documentId), GetMarkdownExtensions()) } -func MarkdownRenderWithTOC(content []byte, footnoteref string) []byte { +func MarkdownRenderWithTOC(content []byte, documentId string) []byte { return blackfriday.Markdown(content, - GetHtmlRenderer(blackfriday.HTML_TOC, footnoteref), + GetHtmlRenderer(blackfriday.HTML_TOC, documentId), GetMarkdownExtensions()) } @@ -132,7 +132,7 @@ func ExtractTOC(content []byte) (newcontent []byte, toc []byte) { return StripEmptyNav(content), toc } // Need to peek ahead to see if this nav element is actually the right one. - correctNav := bytes.Index(content[startOfTOC:peekEnd], []byte(`#toc_0`)) + correctNav := bytes.Index(content[startOfTOC:peekEnd], []byte(`<li><a href="#`)) if correctNav < 0 { // no match found return content, toc } @@ -144,23 +144,23 @@ func ExtractTOC(content []byte) (newcontent []byte, toc []byte) { return } -func RenderBytesWithTOC(content []byte, pagefmt string, footnoteref string) []byte { +func RenderBytesWithTOC(content []byte, pagefmt string, documentId string) []byte { switch pagefmt { default: - return MarkdownRenderWithTOC(content, footnoteref) + return MarkdownRenderWithTOC(content, documentId) case "markdown": - return MarkdownRenderWithTOC(content, footnoteref) + return MarkdownRenderWithTOC(content, documentId) case "rst": return []byte(GetRstContent(content)) } } -func RenderBytes(content []byte, pagefmt string, footnoteref string) []byte { +func RenderBytes(content []byte, pagefmt string, documentId string) []byte { switch pagefmt { default: - return MarkdownRender(content, footnoteref) + return MarkdownRender(content, documentId) case "markdown": - return MarkdownRender(content, footnoteref) + return MarkdownRender(content, documentId) case "rst": return []byte(GetRstContent(content)) } |