The <!--more--> (summary divider) now works even if it is on the same line as content

This commit is contained in:
Mark Sanborn 2013-08-31 21:07:22 -07:00
parent 0fdea0c2c2
commit 5b6021000d
4 changed files with 37 additions and 12 deletions

View file

@ -270,6 +270,10 @@ func WordCount(s string) map[string]int {
return m
}
func RemoveSummaryDivider(content []byte) []byte {
return bytes.Replace(content, summaryDivider, []byte(""), -1)
}
func StripHTML(s string) string {
output := ""

View file

@ -481,7 +481,7 @@ func (page *Page) convertMarkdown(lines io.Reader) {
b := new(bytes.Buffer)
b.ReadFrom(lines)
content := b.Bytes()
page.Content = template.HTML(string(blackfriday.MarkdownCommon(content)))
page.Content = template.HTML(string(blackfriday.MarkdownCommon(RemoveSummaryDivider(content))))
summary, plain := getSummaryString(content)
if plain {
page.Summary = template.HTML(string(summary))

View file

@ -100,6 +100,14 @@ Simple Page
Some more text
`
var SIMPLE_PAGE_WITH_SUMMARY_DELIMITER_SAME_LINE = `---
title: Simple
---
Simple Page<!--more-->
Some more text
`
func checkError(t *testing.T, err error, expected string) {
if err == nil {
t.Fatalf("err is nil")
@ -175,7 +183,20 @@ func TestPageWithDelimiter(t *testing.T) {
t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
}
checkPageTitle(t, p, "Simple")
checkPageContent(t, p, "<p>Simple Page</p>\n\n<!--more-->\n\n<p>Some more text</p>\n")
checkPageContent(t, p, "<p>Simple Page</p>\n\n<p>Some more text</p>\n")
checkPageSummary(t, p, "<p>Simple Page</p>\n")
checkPageType(t, p, "page")
checkPageLayout(t, p, "page/single.html")
}
func TestPageWithMoreTag(t *testing.T) {
p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE_WITH_SUMMARY_DELIMITER_SAME_LINE), "simple")
if err != nil {
t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
}
checkPageTitle(t, p, "Simple")
checkPageContent(t, p, "<p>Simple Page</p>\n\n<p>Some more text</p>\n")
checkPageSummary(t, p, "<p>Simple Page</p>\n")
checkPageType(t, p, "page")
checkPageLayout(t, p, "page/single.html")

View file

@ -31,16 +31,16 @@ import (
var DefaultTimer = nitro.Initalize()
type Site struct {
Config Config
Pages Pages
Tmpl *template.Template
Indexes IndexList
Files []string
Sections Index
Info SiteInfo
Shortcodes map[string]ShortcodeFunc
timer *nitro.B
Target target.Publisher
Config Config
Pages Pages
Tmpl *template.Template
Indexes IndexList
Files []string
Sections Index
Info SiteInfo
Shortcodes map[string]ShortcodeFunc
timer *nitro.B
Target target.Publisher
}
type SiteInfo struct {