mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
helpers: Unexport some internals
This commit is contained in:
parent
aedb13b219
commit
5d915e7e96
3 changed files with 35 additions and 35 deletions
|
@ -147,8 +147,8 @@ func StripHTML(s string) string {
|
|||
return b.String()
|
||||
}
|
||||
|
||||
// StripEmptyNav strips out empty <nav> tags from content.
|
||||
func StripEmptyNav(in []byte) []byte {
|
||||
// stripEmptyNav strips out empty <nav> tags from content.
|
||||
func stripEmptyNav(in []byte) []byte {
|
||||
return bytes.Replace(in, []byte("<nav>\n</nav>\n\n"), []byte(``), -1)
|
||||
}
|
||||
|
||||
|
@ -157,8 +157,8 @@ func BytesToHTML(b []byte) template.HTML {
|
|||
return template.HTML(string(b))
|
||||
}
|
||||
|
||||
// GetHTMLRenderer creates a new Renderer with the given configuration.
|
||||
func GetHTMLRenderer(defaultFlags int, ctx *RenderingContext) blackfriday.Renderer {
|
||||
// getHTMLRenderer creates a new Renderer with the given configuration.
|
||||
func getHTMLRenderer(defaultFlags int, ctx *RenderingContext) blackfriday.Renderer {
|
||||
renderParameters := blackfriday.HtmlRendererParameters{
|
||||
FootnoteAnchorPrefix: viper.GetString("FootnoteAnchorPrefix"),
|
||||
FootnoteReturnLinkContents: viper.GetString("FootnoteReturnLinkContents"),
|
||||
|
@ -227,18 +227,18 @@ func getMarkdownExtensions(ctx *RenderingContext) int {
|
|||
}
|
||||
|
||||
func markdownRender(ctx *RenderingContext) []byte {
|
||||
return blackfriday.Markdown(ctx.Content, GetHTMLRenderer(0, ctx),
|
||||
return blackfriday.Markdown(ctx.Content, getHTMLRenderer(0, ctx),
|
||||
getMarkdownExtensions(ctx))
|
||||
}
|
||||
|
||||
func markdownRenderWithTOC(ctx *RenderingContext) []byte {
|
||||
return blackfriday.Markdown(ctx.Content,
|
||||
GetHTMLRenderer(blackfriday.HTML_TOC, ctx),
|
||||
getHTMLRenderer(blackfriday.HTML_TOC, ctx),
|
||||
getMarkdownExtensions(ctx))
|
||||
}
|
||||
|
||||
// GetMmarkHtmlRenderer returns markdown html renderer.
|
||||
func GetMmarkHtmlRenderer(defaultFlags int, ctx *RenderingContext) mmark.Renderer {
|
||||
// getMmarkHtmlRenderer returns markdown html renderer.
|
||||
func getMmarkHtmlRenderer(defaultFlags int, ctx *RenderingContext) mmark.Renderer {
|
||||
renderParameters := mmark.HtmlRendererParameters{
|
||||
FootnoteAnchorPrefix: viper.GetString("FootnoteAnchorPrefix"),
|
||||
FootnoteReturnLinkContents: viper.GetString("FootnoteReturnLinkContents"),
|
||||
|
@ -259,8 +259,8 @@ func GetMmarkHtmlRenderer(defaultFlags int, ctx *RenderingContext) mmark.Rendere
|
|||
}
|
||||
}
|
||||
|
||||
// GetMmarkExtensions returns markdown extensions.
|
||||
func GetMmarkExtensions(ctx *RenderingContext) int {
|
||||
// getMmarkExtensions returns markdown extensions.
|
||||
func getMmarkExtensions(ctx *RenderingContext) int {
|
||||
flags := 0
|
||||
flags |= mmark.EXTENSION_TABLES
|
||||
flags |= mmark.EXTENSION_FENCED_CODE
|
||||
|
@ -284,10 +284,10 @@ func GetMmarkExtensions(ctx *RenderingContext) int {
|
|||
return flags
|
||||
}
|
||||
|
||||
// MmarkRender renders markdowns.
|
||||
func MmarkRender(ctx *RenderingContext) []byte {
|
||||
return mmark.Parse(ctx.Content, GetMmarkHtmlRenderer(0, ctx),
|
||||
GetMmarkExtensions(ctx)).Bytes()
|
||||
// mmarkRender renders markdowns.
|
||||
func mmarkRender(ctx *RenderingContext) []byte {
|
||||
return mmark.Parse(ctx.Content, getMmarkHtmlRenderer(0, ctx),
|
||||
getMmarkExtensions(ctx)).Bytes()
|
||||
}
|
||||
|
||||
// ExtractTOC extracts Table of Contents from content.
|
||||
|
@ -311,7 +311,7 @@ func ExtractTOC(content []byte) (newcontent []byte, toc []byte) {
|
|||
}
|
||||
|
||||
if startOfTOC < 0 {
|
||||
return StripEmptyNav(content), toc
|
||||
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(`<li><a href="#`))
|
||||
|
@ -355,11 +355,11 @@ func RenderBytesWithTOC(ctx *RenderingContext) []byte {
|
|||
case "markdown":
|
||||
return markdownRenderWithTOC(ctx)
|
||||
case "asciidoc":
|
||||
return []byte(GetAsciidocContent(ctx.Content))
|
||||
return []byte(getAsciidocContent(ctx.Content))
|
||||
case "mmark":
|
||||
return MmarkRender(ctx)
|
||||
return mmarkRender(ctx)
|
||||
case "rst":
|
||||
return []byte(GetRstContent(ctx.Content))
|
||||
return []byte(getRstContent(ctx.Content))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -371,11 +371,11 @@ func RenderBytes(ctx *RenderingContext) []byte {
|
|||
case "markdown":
|
||||
return markdownRender(ctx)
|
||||
case "asciidoc":
|
||||
return []byte(GetAsciidocContent(ctx.Content))
|
||||
return []byte(getAsciidocContent(ctx.Content))
|
||||
case "mmark":
|
||||
return MmarkRender(ctx)
|
||||
return mmarkRender(ctx)
|
||||
case "rst":
|
||||
return []byte(GetRstContent(ctx.Content))
|
||||
return []byte(getRstContent(ctx.Content))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -446,9 +446,9 @@ func TruncateWordsToWholeSentence(words []string, max int) (string, bool) {
|
|||
return strings.Join(words[:max], " "), true
|
||||
}
|
||||
|
||||
// GetAsciidocContent calls asciidoctor or asciidoc as an external helper
|
||||
// getAsciidocContent calls asciidoctor or asciidoc as an external helper
|
||||
// to convert AsciiDoc content to HTML.
|
||||
func GetAsciidocContent(content []byte) string {
|
||||
func getAsciidocContent(content []byte) string {
|
||||
cleanContent := bytes.Replace(content, SummaryDivider, []byte(""), 1)
|
||||
|
||||
path, err := exec.LookPath("asciidoctor")
|
||||
|
@ -473,9 +473,9 @@ func GetAsciidocContent(content []byte) string {
|
|||
return out.String()
|
||||
}
|
||||
|
||||
// GetRstContent calls the Python script rst2html as an external helper
|
||||
// getRstContent calls the Python script rst2html as an external helper
|
||||
// to convert reStructuredText content to HTML.
|
||||
func GetRstContent(content []byte) string {
|
||||
func getRstContent(content []byte) string {
|
||||
cleanContent := bytes.Replace(content, SummaryDivider, []byte(""), 1)
|
||||
|
||||
path, err := exec.LookPath("rst2html")
|
||||
|
|
|
@ -23,7 +23,7 @@ import (
|
|||
// Renders a codeblock using Blackfriday
|
||||
func render(input string) string {
|
||||
ctx := &RenderingContext{}
|
||||
render := GetHTMLRenderer(0, ctx)
|
||||
render := getHTMLRenderer(0, ctx)
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
render.BlockCode(buf, []byte(input), "html")
|
||||
|
@ -33,7 +33,7 @@ func render(input string) string {
|
|||
// Renders a codeblock using Mmark
|
||||
func renderWithMmark(input string) string {
|
||||
ctx := &RenderingContext{}
|
||||
render := GetMmarkHtmlRenderer(0, ctx)
|
||||
render := getMmarkHtmlRenderer(0, ctx)
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
render.BlockCode(buf, []byte(input), "html", []byte(""), false, false)
|
||||
|
@ -72,7 +72,7 @@ func TestCodeFence(t *testing.T) {
|
|||
expectedRe, err := regexp.Compile(d.expected)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Invalid regexp", err)
|
||||
t.Fatal("Invalid regexp", err)
|
||||
}
|
||||
matched := expectedRe.MatchString(result)
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ func BenchmarkStripHTML(b *testing.B) {
|
|||
}
|
||||
|
||||
func TestStripEmptyNav(t *testing.T) {
|
||||
cleaned := StripEmptyNav([]byte("do<nav>\n</nav>\n\nbedobedo"))
|
||||
cleaned := stripEmptyNav([]byte("do<nav>\n</nav>\n\nbedobedo"))
|
||||
assert.Equal(t, []byte("dobedobedo"), cleaned)
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ func TestTruncateWordsByRune(t *testing.T) {
|
|||
|
||||
func TestGetHTMLRendererFlags(t *testing.T) {
|
||||
ctx := &RenderingContext{}
|
||||
renderer := GetHTMLRenderer(blackfriday.HTML_USE_XHTML, ctx)
|
||||
renderer := getHTMLRenderer(blackfriday.HTML_USE_XHTML, ctx)
|
||||
flags := renderer.GetFlags()
|
||||
if flags&blackfriday.HTML_USE_XHTML != blackfriday.HTML_USE_XHTML {
|
||||
t.Errorf("Test flag: %d was not found amongs set flags:%d; Result: %d", blackfriday.HTML_USE_XHTML, flags, flags&blackfriday.HTML_USE_XHTML)
|
||||
|
@ -158,7 +158,7 @@ func TestGetHTMLRendererAllFlags(t *testing.T) {
|
|||
ctx.Config.SmartDashes = true
|
||||
ctx.Config.Smartypants = true
|
||||
ctx.Config.SourceRelativeLinksEval = true
|
||||
renderer := GetHTMLRenderer(defaultFlags, ctx)
|
||||
renderer := getHTMLRenderer(defaultFlags, ctx)
|
||||
actualFlags := renderer.GetFlags()
|
||||
var expectedFlags int
|
||||
//OR-ing flags together...
|
||||
|
@ -176,7 +176,7 @@ func TestGetHTMLRendererAnchors(t *testing.T) {
|
|||
ctx.Config = ctx.getConfig()
|
||||
ctx.Config.PlainIDAnchors = false
|
||||
|
||||
actualRenderer := GetHTMLRenderer(0, ctx)
|
||||
actualRenderer := getHTMLRenderer(0, ctx)
|
||||
headerBuffer := &bytes.Buffer{}
|
||||
footnoteBuffer := &bytes.Buffer{}
|
||||
expectedFootnoteHref := []byte("href=\"#fn:testid:href\"")
|
||||
|
@ -199,7 +199,7 @@ func TestGetMmarkHtmlRenderer(t *testing.T) {
|
|||
ctx.DocumentID = "testid"
|
||||
ctx.Config = ctx.getConfig()
|
||||
ctx.Config.PlainIDAnchors = false
|
||||
actualRenderer := GetMmarkHtmlRenderer(0, ctx)
|
||||
actualRenderer := getMmarkHtmlRenderer(0, ctx)
|
||||
|
||||
headerBuffer := &bytes.Buffer{}
|
||||
footnoteBuffer := &bytes.Buffer{}
|
||||
|
@ -318,7 +318,7 @@ func TestGetMmarkExtensions(t *testing.T) {
|
|||
{mmark.EXTENSION_INCLUDE},
|
||||
}
|
||||
|
||||
actualFlags := GetMmarkExtensions(ctx)
|
||||
actualFlags := getMmarkExtensions(ctx)
|
||||
for _, e := range allExtensions {
|
||||
if actualFlags&e.testFlag != e.testFlag {
|
||||
t.Errorf("Flag %v was not found in the list of extensions.", e)
|
||||
|
@ -330,7 +330,7 @@ func TestMmarkRender(t *testing.T) {
|
|||
ctx := &RenderingContext{}
|
||||
ctx.Content = []byte("testContent")
|
||||
ctx.Config = ctx.getConfig()
|
||||
actualRenderedMarkdown := MmarkRender(ctx)
|
||||
actualRenderedMarkdown := mmarkRender(ctx)
|
||||
expectedRenderedMarkdown := []byte("<p>testContent</p>\n")
|
||||
if !bytes.Equal(actualRenderedMarkdown, expectedRenderedMarkdown) {
|
||||
t.Errorf("Actual rendered Markdown (%s) did not match expected markdown (%s)", actualRenderedMarkdown, expectedRenderedMarkdown)
|
||||
|
|
Loading…
Reference in a new issue