Beispiel #1
0
func commonConvert(p *Page, t tpl.Template) HandledResult {
	p.ProcessShortcodes(t)

	var err error

	if viper.GetBool("EnableEmoji") {
		p.rawContent = helpers.Emojify(p.rawContent)
	}

	renderedContent := p.renderContent(helpers.RemoveSummaryDivider(p.rawContent))

	if len(p.contentShortCodes) > 0 {
		renderedContent, err = replaceShortcodeTokens(renderedContent, shortcodePlaceholderPrefix, p.contentShortCodes)

		if err != nil {
			jww.FATAL.Printf("Failed to replace shortcode tokens in %s:\n%s", p.BaseFileName(), err.Error())
			return HandledResult{err: err}
		}
	}

	tmpContent, tmpTableOfContents := helpers.ExtractTOC(renderedContent)

	p.Content = helpers.BytesToHTML(tmpContent)
	p.TableOfContents = helpers.BytesToHTML(tmpTableOfContents)

	return HandledResult{err: nil}
}
Beispiel #2
0
// emojify "emojifies" the given string.
//
// See http://www.emoji-cheat-sheet.com/
func emojify(in interface{}) (template.HTML, error) {
	str, err := cast.ToStringE(in)

	if err != nil {
		return "", err
	}
	return template.HTML(helpers.Emojify([]byte(str))), nil
}
Beispiel #3
0
func commonConvert(p *Page, t tpl.Template) HandledResult {

	if p.rendered {
		panic(fmt.Sprintf("Page %q already rendered, does not need conversion", p.BaseFileName()))
	}

	p.ProcessShortcodes(t)

	// TODO(bep) these page handlers need to be re-evaluated, as it is hard to
	// process a page in isolation. See the new preRender func.
	if viper.GetBool("EnableEmoji") {
		p.rawContent = helpers.Emojify(p.rawContent)
	}

	// We have to replace the <!--more--> with something that survives all the
	// rendering engines.
	// TODO(bep) inline replace
	p.rawContent = bytes.Replace(p.rawContent, []byte(helpers.SummaryDivider), internalSummaryDivider, 1)
	p.rawContent = p.renderContent(p.rawContent)

	return HandledResult{err: nil}
}