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} }
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} }
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 }
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} }
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} }
func (s *Site) preparePagesForRender(cfg BuildCfg, changed whatChanged) { pageChan := make(chan *Page) wg := &sync.WaitGroup{} for i := 0; i < getGoMaxProcs()*4; i++ { wg.Add(1) go func(pages <-chan *Page, wg *sync.WaitGroup) { defer wg.Done() for p := range pages { if !changed.other && p.rendered { // No need to process it again. continue } // If we got this far it means that this is either a new Page pointer // or a template or similar has changed so wee need to do a rerendering // of the shortcodes etc. // Mark it as rendered p.rendered = true // If in watch mode, we need to keep the original so we can // repeat this process on rebuild. if cfg.Watching { p.rawContentCopy = make([]byte, len(p.rawContent)) copy(p.rawContentCopy, p.rawContent) } else { // Just reuse the same slice. p.rawContentCopy = p.rawContent } if err := handleShortcodes(p, s.owner.tmpl); err != nil { jww.ERROR.Printf("Failed to handle shortcodes for page %s: %s", p.BaseFileName(), err) } if p.Markup == "markdown" { tmpContent, tmpTableOfContents := helpers.ExtractTOC(p.rawContentCopy) p.TableOfContents = helpers.BytesToHTML(tmpTableOfContents) p.rawContentCopy = tmpContent } if p.Markup != "html" { // Now we know enough to create a summary of the page and count some words summaryContent, err := p.setUserDefinedSummaryIfProvided() if err != nil { jww.ERROR.Printf("Failed to set user defined summary for page %q: %s", p.Path(), err) } else if summaryContent != nil { p.rawContentCopy = summaryContent.content } p.Content = helpers.BytesToHTML(p.rawContentCopy) if summaryContent == nil { p.setAutoSummary() } } else { p.Content = helpers.BytesToHTML(p.rawContentCopy) } // no need for this anymore p.rawContentCopy = nil //analyze for raw stats p.analyzePage() } }(pageChan, wg) } for _, p := range s.Pages { pageChan <- p } close(pageChan) wg.Wait() }