当前位置: 首页>>代码示例>>Golang>>正文


Golang helpers.BytesToHTML函数代码示例

本文整理汇总了Golang中github.com/spf13/hugo/helpers.BytesToHTML函数的典型用法代码示例。如果您正苦于以下问题:Golang BytesToHTML函数的具体用法?Golang BytesToHTML怎么用?Golang BytesToHTML使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了BytesToHTML函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: commonConvert

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}
}
开发者ID:nitoyon,项目名称:hugo,代码行数:27,代码来源:handler_page.go

示例2: setSummary

func (p *Page) setSummary() {

	// at this point, p.rawContent contains placeholders for the short codes,
	// rendered and ready in p.contentShortcodes

	if bytes.Contains(p.rawContent, helpers.SummaryDivider) {
		// If user defines split:
		// Split, replace shortcode tokens, then render
		p.Truncated = true // by definition
		header := bytes.Split(p.rawContent, helpers.SummaryDivider)[0]
		renderedHeader := p.renderBytes(header)
		if len(p.contentShortCodes) > 0 {
			tmpContentWithTokensReplaced, err :=
				replaceShortcodeTokens(renderedHeader, shortcodePlaceholderPrefix, true, p.contentShortCodes)
			if err != nil {
				jww.FATAL.Printf("Failed to replace short code tokens in Summary for %s:\n%s", p.BaseFileName(), err.Error())
			} else {
				renderedHeader = tmpContentWithTokensReplaced
			}
		}
		p.Summary = helpers.BytesToHTML(renderedHeader)
	} else {
		// If hugo defines split:
		// render, strip html, then split
		plain := strings.Join(strings.Fields(p.Plain()), " ")
		p.Summary = helpers.BytesToHTML([]byte(helpers.TruncateWordsToWholeSentence(plain, helpers.SummaryLength)))
		p.Truncated = len(p.Summary) != len(plain)
	}
}
开发者ID:reedobrien,项目名称:hugo,代码行数:29,代码来源:page.go

示例3: Convert

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
}
开发者ID:kuruma,项目名称:hugo,代码行数:14,代码来源:page.go

示例4: setSummary

func (p *Page) setSummary() {
	if bytes.Contains(p.rawContent, helpers.SummaryDivider) {
		// If user defines split:
		// Split then render
		p.Truncated = true // by definition
		header := bytes.Split(p.rawContent, helpers.SummaryDivider)[0]
		p.Summary = helpers.BytesToHTML(p.renderBytes(header))
	} else {
		// If hugo defines split:
		// render, strip html, then split
		plain := strings.TrimSpace(p.Plain())
		p.Summary = helpers.BytesToHTML([]byte(helpers.TruncateWordsToWholeSentence(plain, helpers.SummaryLength)))
		p.Truncated = len(p.Summary) != len(plain)
	}
}
开发者ID:kuruma,项目名称:hugo,代码行数:15,代码来源:page.go

示例5: setSummary

func (p *Page) setSummary() {

	// at this point, p.rawContent contains placeholders for the short codes,
	// rendered and ready in p.contentShortcodes

	if bytes.Contains(p.rawContent, helpers.SummaryDivider) {
		sections := bytes.Split(p.rawContent, helpers.SummaryDivider)
		header := sections[0]
		p.Truncated = true
		if len(sections[1]) < 20 {
			// only whitespace?
			p.Truncated = len(bytes.Trim(sections[1], " \n\r")) > 0
		}

		renderedHeader := p.renderBytes(header)
		if len(p.contentShortCodes) > 0 {
			tmpContentWithTokensReplaced, err :=
				replaceShortcodeTokens(renderedHeader, shortcodePlaceholderPrefix, p.contentShortCodes)
			if err != nil {
				jww.FATAL.Printf("Failed to replace short code tokens in Summary for %s:\n%s", p.BaseFileName(), err.Error())
			} else {
				renderedHeader = tmpContentWithTokensReplaced
			}
		}
		p.Summary = helpers.BytesToHTML(renderedHeader)
	} else {
		// If hugo defines split:
		// render, strip html, then split
		summary, truncated := helpers.TruncateWordsToWholeSentence(p.PlainWords(), helpers.SummaryLength)
		p.Summary = template.HTML(summary)
		p.Truncated = truncated

	}
}
开发者ID:johndunne,项目名称:hugo,代码行数:34,代码来源:page.go

示例6: PageConvert

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}
}
开发者ID:yene,项目名称:huga,代码行数:27,代码来源:handler_page.go

示例7: PageConvert

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}
}
开发者ID:sun-friderick,项目名称:hugo,代码行数:20,代码来源:handler_page.go

示例8: PageConvert

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}
}
开发者ID:johndunne,项目名称:hugo,代码行数:23,代码来源:handler_page.go

示例9: PageConvert

func (h htmlHandler) PageConvert(p *Page, t tpl.Template) HandledResult {
	p.ProcessShortcodes(t)
	var err error

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

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

	p.Content = helpers.BytesToHTML(p.rawContent)
	return HandledResult{err: nil}
}
开发者ID:nitoyon,项目名称:hugo,代码行数:16,代码来源:handler_page.go

示例10: setUserDefinedSummaryIfProvided

// Returns the page as summary and main if a user defined split is provided.
func (p *Page) setUserDefinedSummaryIfProvided() (*summaryContent, error) {

	sc := splitUserDefinedSummaryAndContent(p.Markup, p.rawContentCopy)

	if sc == nil {
		// No divider found
		return nil, nil
	}

	p.Truncated = true
	if len(sc.content) < 20 {
		// only whitespace?
		p.Truncated = len(bytes.Trim(sc.content, " \n\r")) > 0
	}

	p.Summary = helpers.BytesToHTML(sc.summary)

	return sc, nil
}
开发者ID:tarsisazevedo,项目名称:hugo,代码行数:20,代码来源:page.go

示例11: preparePagesForRender

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()

}
开发者ID:yehorh,项目名称:hugo,代码行数:82,代码来源:hugo_sites.go


注:本文中的github.com/spf13/hugo/helpers.BytesToHTML函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。