// FormattedHTML return formated seo setting as HTML
327277
func (setting Setting) FormattedHTML(context *qor.Context) template.HTML {
	basicMeta := fmt.Sprintf("<title>%s</title>\n<meta name=\"description\" content=\"%s\">\n<meta name=\"keywords\" content=\"%s\"/>", setting.Title, setting.Description, setting.Keywords)

	toAbsoluteURL := func(str string) string {
		if u, err := url.Parse(str); err == nil {
			if u.IsAbs() {
				return str
			}

			if u.Host == "" && context.Request != nil {
				u.Host = context.Request.Host
			}

			if u.Scheme == "" {
				if context.Request != nil && context.Request.URL.Scheme != "" {
					u.Scheme = context.Request.URL.Scheme
				} else {
					u.Scheme = "http"
				}
			}
			return u.String()
		}
		return str
	}

	openGraphData := map[string]string{}

	if setting.OpenGraphURL != "" {
		openGraphData["og:url"] = toAbsoluteURL(setting.OpenGraphURL)
	}

	if setting.OpenGraphType != "" {
		openGraphData["og:type"] = setting.OpenGraphType
	}

	if len(setting.OpenGraphImageFromMediaLibrary.Files) > 0 {
		openGraphData["og:image"] = toAbsoluteURL(setting.OpenGraphImageFromMediaLibrary.URL())
	} else {
		openGraphData["og:image"] = toAbsoluteURL(setting.OpenGraphImageURL)
	}

	for _, metavalue := range setting.OpenGraphMetadata {
		openGraphData[metavalue.Property] = metavalue.Content
	}

	if _, ok := openGraphData["og:title"]; !ok {
		openGraphData["og:title"] = setting.Title
	}

	if _, ok := openGraphData["og:description"]; !ok {
		openGraphData["og:description"] = setting.Description
	}

	for key, value := range openGraphData {
		basicMeta += fmt.Sprintf("<meta property=\"%v\" name=\"%v\" content=\"%v\"/>", key, key, value)
	}

	return template.HTML(basicMeta)
}
19837
func (c *C) HTML(name string, data interface{}) {
	c.render.Render(c.Writer, name, data)
}
1283745
func cleanHTML(r io.Reader, all bool) string {
	output := ""
	if !all {
		output = "<html><head></head>"
	}
	mainSection := false
	junkSection := false

	d := html.NewTokenizer(r)
	for {
		// token type
		tokenType := d.Next()
		if tokenType == html.ErrorToken {
			return output
		}
		token := d.Token()

		switch tokenType {
		case html.StartTagToken: // <tag>
			if token.Data == "body" || (token.Data == "html" && all) {
				mainSection = true
			}
			if !acceptedHTMLTag(token.Data) {
				junkSection = true
			}

			if !junkSection && mainSection {
				output += "<" + token.Data + ">"
			}

		case html.TextToken: // text between start and end tag
			if !junkSection && mainSection {
				output += token.Data
			}

		case html.EndTagToken: // </tag>
			if !junkSection && mainSection {
				output += "</" + token.Data + ">"
			}
			if !acceptedHTMLTag(token.Data) {
				junkSection = false
			}

		case html.SelfClosingTagToken: // <tag/>
			if !junkSection && mainSection {
				output += "<" + token.Data + " />" // TODO: Can probably keep attributes from the meta tags
			}
		}
	}
}
733040
func (s *Selection) AfterHtml(html string) *Selection {
	return s.AfterNodes(parseHtml(html)...)
}
64382
func (ctx *Context) HTML(src ...string) *Context {
	ctx.SetContentType(htmlCT)
	if len(src) > 0 {
		_, e := ctx.WriteString(src[0])
		_ = e
	}
	return ctx
}
1267937
func (c *CommitResult) GetHTMLURL() string {
	if c == nil || c.HTMLURL == nil {
		return ""
	}
	return *c.HTMLURL
}
943727
func chunksToHTML(chunks []formatChunk) template.HTML {
	buf := bytes.Buffer{}
	for _, chunk := range chunks {
		if len(chunk.html) != 0 {
			buf.WriteString(string(chunk.html))
		} else {
			buf.WriteString(template.HTMLEscapeString(chunk.str))
		}
	}
	return template.HTML(buf.String())
}
295466
func (c Markdown) ToHTML() template.HTML {
	return template.HTML(blackfriday.Run([]byte(string(c))))
}
154719
func (c *Context) HTML(status int, name string) {
	log.Trace("Template: %s", name)
	c.Context.HTML(status, name)
}
636051
func (s *Selection) SetHtml(html string) *Selection {
	return setHtmlNodes(s, parseHtml(html)...)
}
220554
func ServeFormatted(w http.ResponseWriter, r *http.Request, v interface{}) {
	accept := r.Header.Get("Accept")
	switch accept {
	case applicationJson:
		ServeJson(w, v)
	case applicationXml, textXml:
		ServeXml(w, v)
	default:
		ServeJson(w, v)
	}

	return
}
219533
func (p *Page) GetHTMLURL() string {
	if p == nil || p.HTMLURL == nil {
		return ""
	}
	return *p.HTMLURL
}
81645
func (og *OpenGraph) ProcessHTML(buffer io.Reader) error {
	z := html.NewTokenizer(buffer)
	for {
		tt := z.Next()
		switch tt {
		case html.ErrorToken:
			if z.Err() == io.EOF {
				return nil
			}
			return z.Err()
		case html.StartTagToken, html.SelfClosingTagToken, html.EndTagToken:
			name, hasAttr := z.TagName()
			if atom.Lookup(name) == atom.Body {
				return nil // OpenGraph is only in head, so we don't need body
			}
			if atom.Lookup(name) != atom.Meta || !hasAttr {
				continue
			}
			m := make(map[string]string)
			var key, val []byte
			for hasAttr {
				key, val, hasAttr = z.TagAttr()
				m[atom.String(key)] = string(val)
			}
			og.ProcessMeta(m)
		}
	}
}
850611
func (l *Link) HTML() template.HTML {
	if l == nil {
		return ""
	}
	buf := bytes.Buffer{}
	if err := linkifyTemplate.Execute(&buf, l); err != nil {
		panic(err)
	}
	return template.HTML(buf.Bytes())
}
994636
func writeHTMLBadRequest(w http.ResponseWriter, str string) {
	w.Header().Set("Content-Type", "text/html; charset=utf-8")
	w.WriteHeader(http.StatusBadRequest)
	io.WriteString(w, str)
}
127476
func (s *Body) SetHtml(v *Content) *Body {
	s.Html = v
	return s
}
587191
func (d *Databook) HTML() *Exportable {
	b := newBuffer()

	for _, s := range d.sheets {
		b.WriteString("<h1>" + s.title + "</h1>\n")
		b.Write(s.dataset.HTML().Bytes())
		b.WriteString("\n\n")
	}

	return newExportable(b)
}