// StripHTML accepts a string, strips out all HTML tags and returns it.
557920
func StripHTML(s string) string {

	// Shortcut strings with no tags in them
	if !strings.ContainsAny(s, "<>") {
		return s
	}
	s = stripHTMLReplacer.Replace(s)

	// Walk through the string removing all tags
	b := bp.GetBuffer()
	defer bp.PutBuffer(b)
	var inTag, isSpace, wasSpace bool
	for _, r := range s {
		if !inTag {
			isSpace = false
		}

		switch {
		case r == '<':
			inTag = true
		case r == '>':
			inTag = false
		case unicode.IsSpace(r):
			isSpace = true
			fallthrough
		default:
			if !inTag && (!isSpace || (isSpace && !wasSpace)) {
				b.WriteRune(r)
			}
		}

		wasSpace = isSpace

	}
	return b.String()
}
482906
func stripURLParts(url string) string {
	// Lower case the url
	url = strings.ToLower(url)

	// Strip protocol
	if index := strings.Index(url, "://"); index > -1 {
		url = url[index+3:]
	}

	// Now, if the url looks like this: username:password@www.example.com/path?query=?
	// we remove the content before the '@' symbol
	if index := strings.Index(url, "@"); index > -1 {
		url = url[index+1:]
	}

	// Strip path (and query with it)
	if index := strings.Index(url, "/"); index > -1 {
		url = url[:index]
	} else if index := strings.Index(url, "?"); index > -1 { // Strip query if path is not found
		url = url[:index]
	}

	// Convert domain to unicode
	if strings.Index(url, "xn--") != -1 {
		var err error
		url, err = idna.ToUnicode(url)
		if err != nil {
			return ""
		}
	}

	// Return domain
	return url
}
1233887
func (p *Pages) GetHTMLURL() string {
	if p == nil || p.HTMLURL == nil {
		return ""
	}
	return *p.HTMLURL
}
709988
func (t *TextView) GetText(stripTags bool) string {
	// Get the buffer.
	buffer := t.buffer
	if !stripTags {
		buffer = append(buffer, string(t.recentBytes))
	}

	// Add newlines again.
	text := strings.Join(buffer, "\n")

	// Strip from tags if required.
	if stripTags {
		if t.regions {
			text = regionPattern.ReplaceAllString(text, "")
		}
		if t.dynamicColors {
			text = colorPattern.ReplaceAllString(text, "")
		}
		if t.regions || t.dynamicColors {
			text = escapePattern.ReplaceAllString(text, `[$1$2]`)
		}
	}

	return text
}
114697
func (ctx *Context) HTML(code int, str string) error {
	ctx.Type(MIMETextHTMLCharsetUTF8)
	return ctx.End(code, []byte(str))
}
1051749
func StripFormat(s string) string {
	r := regexp.MustCompile(reFormat)
	return r.ReplaceAllString(s, "")
}
285890
func (i *Installation) GetHTMLURL() string {
	if i == nil || i.HTMLURL == nil {
		return ""
	}
	return *i.HTMLURL
}
154719
func (c *Context) HTML(status int, name string) {
	log.Trace("Template: %s", name)
	c.Context.HTML(status, name)
}
454329
func (r *Render) Html(w http.ResponseWriter, status int, name string, binding interface{}) error {
	if r.opt.IsDevelopment {
		r.compile()
	}

	if tSet, ok := r.templates[name]; !ok {
		return fmt.Errorf("Cannot find template %q in Render", name)
	} else {
		if r.opt.UseBufPool {
			buf := r.bufPool.Get()
			if err := tSet.template.Execute(buf, binding); err != nil {
				return fmt.Errorf("Template execution error, %s", err)
			}
			w.Header().Set("Content-Type", kContentHtml+kContentCharset)
			w.WriteHeader(status)
			_, err := buf.WriteTo(w)
			r.bufPool.Put(buf)
			return err
		} else {
			out := new(bytes.Buffer)
			if err := tSet.template.Execute(out, binding); err != nil {
				return fmt.Errorf("Template execution error, %s", err)
			}
			w.Header().Set("Content-Type", kContentHtml+kContentCharset)
			w.WriteHeader(status)
			_, err := io.Copy(w, out)
			return err
		}
	}
}
1175351
func (r *Render) HTML(w io.Writer, status int, name string, binding interface{}, htmlOpt ...HTMLOptions) error {
	r.templatesLk.Lock()
	defer r.templatesLk.Unlock()

	// If we are in development mode, recompile the templates on every HTML request.
	if r.opt.IsDevelopment {
		r.compileTemplates()
	}

	opt := r.prepareHTMLOptions(htmlOpt)
	// Assign a layout if there is one.
	if len(opt.Layout) > 0 {
		r.addLayoutFuncs(name, binding)
		name = opt.Layout
	}

	head := Head{
		ContentType: r.opt.HTMLContentType + r.compiledCharset,
		Status:      status,
	}

	h := HTML{
		Head:      head,
		Name:      name,
		Templates: r.templates,
	}

	return r.Render(w, h, binding)
}
543043
public static String stripHtml(String html) {
		return (html == null) ? "" : Jsoup.parse(html).text();
	}
235732
func MinifyHTML(data []byte, options *Options) (out []byte, err error) {
	if options == nil {
		options = DefaultOptions
	}
	var b bytes.Buffer
	z := html.NewTokenizer(bytes.NewReader(data))
	raw := false
	javascript := false
	style := false
	for {
		tt := z.Next()
		switch tt {
		case html.ErrorToken:
			err := z.Err()
			if err == io.EOF {
				return b.Bytes(), nil
			}
			return nil, err
		case html.StartTagToken, html.SelfClosingTagToken:
			tagName, hasAttr := z.TagName()
			switch string(tagName) {
			case "script":
				javascript = true
				raw = true
			case "style":
				style = true
				raw = true
			case "pre", "code", "textarea":
				raw = true
			default:
				raw = false
			}
			b.WriteByte('<')
			b.Write(tagName)
			var k, v []byte
			isFirst := true
			for hasAttr {
				k, v, hasAttr = z.TagAttr()
				if javascript && string(k) == "type" && string(v) != "text/javascript" {
					javascript = false
				}
				if string(k) == "style" && options.MinifyStyles {
					v = []byte("a{" + string(v) + "}") // simulate "full" CSS
					v, _ = MinifyCSS(v)
					v = v[2 : len(v)-1] // strip simulation
				}
				if isFirst {
					b.WriteByte(' ')
					isFirst = false
				}
				b.Write(k)
				b.WriteByte('=')
				if quoteChar := valueQuoteChar(v); quoteChar != 0 {
					// Quoted value.
					b.WriteByte(quoteChar)
					b.WriteString(html.EscapeString(string(v)))
					b.WriteByte(quoteChar)
				} else {
					// Unquoted value.
					b.Write(v)
				}
				if hasAttr {
					b.WriteByte(' ')
				}
			}
			b.WriteByte('>')
		case html.EndTagToken:
			tagName, _ := z.TagName()
			raw = false
			if javascript && string(tagName) == "script" {
				javascript = false
			}
			if style && string(tagName) == "style" {
				style = false
			}
			b.Write([]byte("</"))
			b.Write(tagName)
			b.WriteByte('>')
		case html.CommentToken:
			if bytes.HasPrefix(z.Raw(), []byte("<!--[if")) ||
				bytes.HasPrefix(z.Raw(), []byte("<!--//")) {
				// Preserve IE conditional and special style comments.
				b.Write(z.Raw())
			}
			// ... otherwise, skip.
		case html.TextToken:
			if javascript && options.MinifyScripts {
				min, err := MinifyJS(z.Raw())
				if err != nil {
					// Just write it as is.
					b.Write(z.Raw())
				} else {
					b.Write(min)
				}
			} else if style && options.MinifyStyles {
				v, _ := MinifyCSS(z.Raw())
				b.Write(v)
			} else if raw {
				b.Write(z.Raw())
			} else {
				b.Write(trimTextToken(z.Raw()))
			}
		default:
			b.Write(z.Raw())
		}

	}
}
833423
func (ctx *Context) OkHTML(str string) error {
	return ctx.HTML(http.StatusOK, str)
}
42480
func (b *XMLBase) ResolveHTML(relHTML string) (string, error) {
	if b.CurrentBase() == "" {
		return relHTML, nil
	}

	htmlReader := strings.NewReader(relHTML)

	doc, err := html.Parse(htmlReader)
	if err != nil {
		return relHTML, err
	}

	var visit func(*html.Node)

	// recursively traverse HTML resolving any relative URIs in attributes
	visit = func(n *html.Node) {
		if n.Type == html.ElementNode {
			for i, a := range n.Attr {
				if htmlURIAttrs[a.Key] {
					absVal, err := b.ResolveURL(a.Val)
					if err == nil {
						n.Attr[i].Val = absVal
					}
					break
				}
			}
		}
		for c := n.FirstChild; c != nil; c = c.NextSibling {
			visit(c)
		}
	}

	visit(doc)
	var w bytes.Buffer
	err = html.Render(&w, doc)
	if err != nil {
		return relHTML, err
	}

	// html.Render() always writes a complete html5 document, so strip the html
	// and body tags
	absHTML := w.String()
	absHTML = strings.TrimPrefix(absHTML, "<html><head></head><body>")
	absHTML = strings.TrimSuffix(absHTML, "</body></html>")

	return absHTML, err
}
216578
func OuterHTML(sel interface{}, html *string, opts ...QueryOption) Action {
	if html == nil {
		panic("html cannot be nil")
	}
	return JavascriptAttribute(sel, "outerHTML", html, opts...)
}
1048487
func (i *Issue) GetHTMLURL() string {
	if i == nil || i.HTMLURL == nil {
		return ""
	}
	return *i.HTMLURL
}
1082553
func HTML(d *DiffSolution) string {
	// closest contains the number of lines to the *next* changed lines
	maxContext := 10
	maxContext++ // + 1 for lines to hide
	nextChange := make([]int, len(d.Lines))
	lastChangedLine := len(d.Lines) + 10
	for i := len(d.Lines) - 1; i > -1; i-- {
		switch LineSource(d.Lines[i][2]) {
		case LineFromA, LineFromB, LineFromBothEdit:
			lastChangedLine = i
		case LineFromBoth:
			if d.Lines[i][0] != d.Lines[i][1] {
				lastChangedLine = i
			}
		}
		nextChange[i] = lastChangedLine - i
		if nextChange[i] > maxContext {
			nextChange[i] = maxContext
		}
	}

	li, ri := 0, 0
	lg := bytes.NewBufferString("<div id='gutter-left' class='gutter'>\n")
	rg := bytes.NewBufferString("<div id='gutter-right' class='gutter'>\n")
	lb := bytes.NewBufferString("<div id='diff-left' class='diff-pane'><div class='diff-pane-contents'>\n")
	rb := bytes.NewBufferString("<div id='diff-right' class='diff-pane'><div class='diff-pane-contents'>\n")
	lastChangedLine = -maxContext

	lastSource := LineFromBoth
	lineHeight := 16
	ll := bytes.NewBufferString(fmt.Sprintf(`<div><svg width="16" height="%d">`, lineHeight*len(d.Lines)))

	for i, l := range d.Lines {
		ls := LineSource(l[2])
		if ls != lastSource {
			lastSource = ls
			if l[0] != l[1] {
				ll.WriteString(
					fmt.Sprintf(`<line x1="%d" x2="%d" y1="%d" y2="%d" stroke-width="1" class="connector-%s" />`,
						0, 16, lineHeight*li, lineHeight*ri, svgClasses[lastSource],
					),
				)
			}
		}

		// closestChange keeps track of how close we are to the *previous* change.
		closestChange := 0
		if ls == LineFromBoth && l[0] == l[1] {
			closestChange = i - lastChangedLine
			if closestChange > nextChange[i] {
				closestChange = nextChange[i]
			}
			if closestChange == maxContext {
				closestChange = -1
			}
		} else {
			lastChangedLine = i
		}
		lc := "lc-" + strconv.Itoa(closestChange) + " line "
		if ls == LineFromA {
			li++
			must(div.Execute(lg, elem{lc + "la", li}))
			must(div.Execute(rg, elem{lc, ""}))
			must(div.Execute(lb, elem{lc + "la", l[0]}))
			must(div.Execute(rb, elem{lc, ""}))
		} else if ls == LineFromB {
			ri++
			must(div.Execute(lg, elem{lc, ""}))
			must(div.Execute(rg, elem{lc + "la", ri}))
			must(div.Execute(lb, elem{lc, ""}))
			must(div.Execute(rb, elem{lc + "la", l[1]}))
		} else if ls == LineFromBothEdit {
			li++
			ri++
			dl, dr := "", ""
			sol := DiffLine(l[0], l[1])
			if sol != nil {
				dl, dr = HTMLLine(sol)
			} else {
				dl = template.HTMLEscapeString(l[0])
				dr = template.HTMLEscapeString(l[1])
			}
			must(div.Execute(lg, elem{lc + "ln", li}))
			must(div.Execute(rg, elem{lc + "ln", ri}))
			must(div.Execute(lb, elem{lc + "ln", template.HTML(dl)}))
			must(div.Execute(rb, elem{lc + "ln", template.HTML(dr)}))
		} else if l[0] != l[1] {
			li++
			ri++
			must(div.Execute(lg, elem{lc + "line-ws", li}))
			must(div.Execute(rg, elem{lc + "line-ws", ri}))
			must(div.Execute(lb, elem{lc + "line-ws", l[0]}))
			must(div.Execute(rb, elem{lc + "line-ws", l[1]}))
		} else if ls == LineFromBoth {
			li++
			ri++
			must(div.Execute(lg, elem{lc + "lm", li}))
			must(div.Execute(rg, elem{lc + "lm", ri}))
			must(div.Execute(lb, elem{lc + "lm", l[0]}))
			must(div.Execute(rb, elem{lc + "lm", l[1]}))
		}
	}

	lg.WriteString("</div>")
	rg.WriteString("</div>")
	lb.WriteString("</div></div>")
	rb.WriteString("</div></div>")
	ll.WriteString("</div>")
	lbs := strings.Replace(lb.String(), "\t", `<span class="delta-tab"> </span>`, -1)
	rbs := strings.Replace(rb.String(), "\t", `<span class="delta-tab"> </span>`, -1)
	if li == 0 {
		return rg.String() + rbs
	}
	if ri == 0 {
		return lg.String() + lbs
	}
	return lg.String() + lbs + rg.String() + rbs
}