Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for embedding script tags in markdown pages. #305

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions hugolib/page.go
Expand Up @@ -652,7 +652,6 @@ func (page *Page) Convert() error {

func markdownRender(content []byte) []byte {
htmlFlags := 0
htmlFlags |= blackfriday.HTML_SKIP_SCRIPT
htmlFlags |= blackfriday.HTML_USE_XHTML
htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS
htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS
Expand All @@ -672,7 +671,6 @@ func markdownRender(content []byte) []byte {

func markdownRenderWithTOC(content []byte) []byte {
htmlFlags := 0
htmlFlags |= blackfriday.HTML_SKIP_SCRIPT
htmlFlags |= blackfriday.HTML_TOC
htmlFlags |= blackfriday.HTML_USE_XHTML
htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS
Expand Down
16 changes: 16 additions & 0 deletions hugolib/page_test.go
Expand Up @@ -118,6 +118,12 @@ Summary Next Line. {{% img src="/not/real" %}}.
More text here.

Some more text
`

SIMPLE_PAGE_WITH_EMBEDDED_SCRIPT = `---
title: Simple
---
<script type='text/javascript'>alert('the script tags are still there, right?');</script>
`

SIMPLE_PAGE_WITH_SUMMARY_DELIMITER_SAME_LINE = `---
Expand Down Expand Up @@ -340,6 +346,16 @@ func TestPageWithShortCodeInSummary(t *testing.T) {
checkPageLayout(t, p, "page/single.html", "single.html")
}

func TestPageWithEmbeddedScriptTag(t *testing.T) {
p, _ := NewPage("simple.md")
err := p.ReadFrom(strings.NewReader(SIMPLE_PAGE_WITH_EMBEDDED_SCRIPT))
p.Convert()
if err != nil {
t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
}
checkPageContent(t, p, "<script type='text/javascript'>alert('the script tags are still there, right?');</script>\n")
}

func TestTableOfContents(t *testing.T) {
p, _ := NewPage("tocpage.md")
err := p.ReadFrom(strings.NewReader(PAGE_WITH_TOC))
Expand Down