Пример #1
0
func (h markdownHandler) PageConvert(p *Page, t tpl.Template) HandledResult {
	p.ProcessShortcodes(t)

	tmpContent, tmpTableOfContents := helpers.ExtractTOC(p.renderContent(helpers.RemoveSummaryDivider(p.rawContent)))

	if len(p.contentShortCodes) > 0 {
		replaced, err := replaceShortcodeTokensInsources(shortcodePlaceholderPrefix, p.contentShortCodes,
			tmpContent, tmpTableOfContents)
		if err != nil {
			jww.FATAL.Printf("Fail to replace shortcode tokens in %s:\n%s", p.BaseFileName(), err.Error())
			return HandledResult{err: err}
		}
		tmpContent = replaced[0]
		tmpTableOfContents = replaced[1]
	}

	s := string(tmpContent)
	if viper.GetBool("RemoveHTMLComments") {
		r, _ := regexp.Compile("<!--(.*?)-->")
		s = r.ReplaceAllString(s, "")
	}
	p.Content = template.HTML(s)

	p.TableOfContents = helpers.BytesToHTML(tmpTableOfContents)

	return HandledResult{err: nil}
}
Пример #2
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}
}
Пример #3
0
func (page *Page) Convert() error {
	markupType := page.guessMarkupType()
	switch markupType {
	case "markdown", "rst":
		tmpContent, tmpTableOfContents := helpers.ExtractTOC(page.renderContent(helpers.RemoveSummaryDivider(page.rawContent)))
		page.Content = helpers.BytesToHTML(tmpContent)
		page.TableOfContents = helpers.BytesToHTML(tmpTableOfContents)
	case "html":
		page.Content = helpers.BytesToHTML(page.rawContent)
	default:
		return fmt.Errorf("Error converting unsupported file type '%s' for page '%s'", markupType, page.Source.Path())
	}
	return nil
}
Пример #4
0
func (h markdownHandler) PageConvert(p *Page, t tpl.Template) HandledResult {
	p.ProcessShortcodes(t)

	tmpContent, tmpTableOfContents := helpers.ExtractTOC(p.renderContent(helpers.RemoveSummaryDivider(p.rawContent)))

	if len(p.contentShortCodes) > 0 {
		tmpContentWithTokensReplaced, err := replaceShortcodeTokens(tmpContent, shortcodePlaceholderPrefix, true, p.contentShortCodes)

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

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

	return HandledResult{err: nil}
}
Пример #5
0
func (h asciidocHandler) PageConvert(p *Page, t tpl.Template) HandledResult {
	p.ProcessShortcodes(t)

	// TODO(spf13) Add/Refactor AsciiDoc Logic here
	tmpContent, tmpTableOfContents := helpers.ExtractTOC(p.renderContent(helpers.RemoveSummaryDivider(p.rawContent)))

	if len(p.contentShortCodes) > 0 {
		replaced, err := replaceShortcodeTokensInsources(shortcodePlaceholderPrefix, p.contentShortCodes,
			tmpContent, tmpTableOfContents)
		if err != nil {
			jww.FATAL.Printf("Fail to replace shortcode tokens in %s:\n%s", p.BaseFileName(), err.Error())
			return HandledResult{err: err}
		}
		tmpContent = replaced[0]
		tmpTableOfContents = replaced[1]
	}

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

	//err := p.Convert()
	return HandledResult{page: p, err: nil}
}