// Massage enhances the SVG output from DOT to provide better
// panning inside a web browser. It uses the SVGPan library, which is
// included directly.
439425
func Massage(in bytes.Buffer) string {
	svg := string(in.Bytes())

	// Work around for dot bug which misses quoting some ampersands,
	// resulting on unparsable SVG.
	svg = strings.Replace(svg, "&;", "&amp;;", -1)

	//Dot's SVG output is
	//
	//    <svg width="___" height="___"
	//     viewBox="___" xmlns=...>
	//    <g id="graph0" transform="...">
	//    ...
	//    </g>
	//    </svg>
	//
	// Change it to
	//
	//    <svg width="100%" height="100%"
	//     xmlns=...>
	//    <script>...</script>
	//    <g id="viewport" transform="translate(0,0)">
	//    <g id="graph0" transform="...">
	//    ...
	//    </g>
	//    </g>
	//    </svg>

	if loc := viewBox.FindStringIndex(svg); loc != nil {
		svg = svg[:loc[0]] +
			`<svg width="100%" height="100%"` +
			svg[loc[1]:]
	}

	if loc := graphId.FindStringIndex(svg); loc != nil {
		svg = svg[:loc[0]] +
			`<script type="text/ecmascript"><![CDATA[` + svgPanJS + `]]></script>` +
			`<g id="viewport" transform="scale(0.5,0.5) translate(0,0)">` +
			svg[loc[0]:]
	}

	if loc := svgClose.FindStringIndex(svg); loc != nil {
		svg = svg[:loc[0]] +
			`</g>` +
			svg[loc[0]:]
	}

	return svg
}
85904
func UseHTTP(h rest.HTTPHandlers) Option {
	return func(p *Plugin) {
		p.Deps.HTTP = h
	}
}
1175210
func MakeMagicEndpoint(magic *Magic) endpoint.Endpoint {
	return func(ctx context.Context, request interface{}) (interface{}, error) {
		req := request.(Workload)
		result, err := magic.DoMagic(req)
		return result, err
	}
}
465392
func (c *Callbacks) OnCMsgDOTACombatLogEntry(fn func(*dota.CMsgDOTACombatLogEntry) error) {
	c.onCMsgDOTACombatLogEntry = append(c.onCMsgDOTACombatLogEntry, fn)
}
613143
func (m Metric) Format(f fmt.State, _ rune) {
	buf := bufferPool.Get().(*buffer)
	buf.b = appendMetric(buf.b[:0], m)
	f.Write(buf.b)
	bufferPool.Put(buf)
}
48266
func (this *MarkupMarkDown) link(anchorName, linkText string) string {
	if linkText == "" {
		return fmt.Sprintf("[%s](#%s)", anchorName, anchorName)
	}
	return fmt.Sprintf("[%s](#%s)", linkText, anchorName)
}
815857
func Generate(args map[string]string) string {
	p := pattern.New(args)

	return p.SvgStr()
}
229848
func (b *BmPrefix) Dump(indent string) string {
	buf := &bytes.Buffer{}

	fmt.Fprintf(buf, "%sBM Pattern: %s\n%sPositive: ", indent, string(b.pattern), indent)
	for i := 0; i < len(b.positive); i++ {
		buf.WriteString(strconv.Itoa(b.positive[i]))
		buf.WriteRune(' ')
	}
	buf.WriteRune('\n')

	if b.negativeASCII != nil {
		buf.WriteString(indent)
		buf.WriteString("Negative table\n")
		for i := 0; i < len(b.negativeASCII); i++ {
			if b.negativeASCII[i] != len(b.pattern) {
				fmt.Fprintf(buf, "%s  %s %s\n", indent, Escape(string(rune(i))), strconv.Itoa(b.negativeASCII[i]))
			}
		}
	}

	return buf.String()
}
1280476
func SVGWithCSS(css string, nonce string) (func(width, height int)(Renderer, error)) {
	return func(width, height int) (Renderer, error) {
		buffer := bytes.NewBuffer([]byte{})
		canvas := newCanvas(buffer)
		canvas.css = css
		canvas.nonce = nonce
		canvas.Start(width, height)
		return &vectorRenderer{
			b:   buffer,
			c:   canvas,
			s:   &Style{},
			p:   []string{},
			dpi: DefaultDPI,
		}, nil
	}
}
719890
func (e *Element) Augment(m ...Markup) {
	if !e.allowChildren {
		return
	}
	for _, mo := range m {
		mo.Apply(e)
	}
}
638545
func (hl *Highlight) Source() interface{} {
	// Returns the map inside of "highlight":
	// "highlight":{
	//   ... this ...
	// }
	source := make(map[string]interface{})
	if hl.tagsSchema != nil {
		source["tags_schema"] = *hl.tagsSchema
	}
	if hl.preTags != nil && len(hl.preTags) > 0 {
		source["pre_tags"] = hl.preTags
	}
	if hl.postTags != nil && len(hl.postTags) > 0 {
		source["post_tags"] = hl.postTags
	}
	if hl.order != nil {
		source["order"] = *hl.order
	}
	if hl.highlightFilter != nil {
		source["highlight_filter"] = *hl.highlightFilter
	}
	if hl.fragmentSize != nil {
		source["fragment_size"] = *hl.fragmentSize
	}
	if hl.numOfFragments != nil {
		source["number_of_fragments"] = *hl.numOfFragments
	}
	if hl.encoder != nil {
		source["encoder"] = *hl.encoder
	}
	if hl.requireFieldMatch != nil {
		source["require_field_match"] = *hl.requireFieldMatch
	}
	if hl.boundaryMaxScan != nil {
		source["boundary_max_scan"] = *hl.boundaryMaxScan
	}
	if hl.boundaryChars != nil && len(hl.boundaryChars) > 0 {
		source["boundary_chars"] = hl.boundaryChars
	}
	if hl.highlighterType != nil {
		source["type"] = *hl.highlighterType
	}
	if hl.fragmenter != nil {
		source["fragmenter"] = *hl.fragmenter
	}
	if hl.highlightQuery != nil {
		source["highlight_query"] = hl.highlightQuery.Source()
	}
	if hl.noMatchSize != nil {
		source["no_match_size"] = *hl.noMatchSize
	}
	if hl.phraseLimit != nil {
		source["phrase_limit"] = *hl.phraseLimit
	}
	if hl.options != nil && len(hl.options) > 0 {
		source["options"] = hl.options
	}
	if hl.forceSource != nil {
		source["force_source"] = *hl.forceSource
	}

	if hl.fields != nil && len(hl.fields) > 0 {
		if hl.useExplicitFieldOrder {
			// Use a slice for the fields
			fields := make([]map[string]interface{}, 0)
			for _, field := range hl.fields {
				fmap := make(map[string]interface{})
				fmap[field.Name] = field.Source()
				fields = append(fields, fmap)
			}
			source["fields"] = fields
		} else {
			// Use a map for the fields
			fields := make(map[string]interface{}, 0)
			for _, field := range hl.fields {
				fields[field.Name] = field.Source()
			}
			source["fields"] = fields
		}
	}

	return source

	/*
		highlightS := make(map[string]interface{})

		if hl.tagsSchema != "" {
			highlightS["tags_schema"] = hl.tagsSchema
		}
		if len(hl.preTags) > 0 {
			highlightS["pre_tags"] = hl.preTags
		}
		if len(hl.postTags) > 0 {
			highlightS["post_tags"] = hl.postTags
		}
		if hl.order != "" {
			highlightS["order"] = hl.order
		}
		if hl.encoder != "" {
			highlightS["encoder"] = hl.encoder
		}
		if hl.requireFieldMatch != nil {
			highlightS["require_field_match"] = *hl.requireFieldMatch
		}
		if hl.highlighterType != "" {
			highlightS["type"] = hl.highlighterType
		}
		if hl.fragmenter != "" {
			highlightS["fragmenter"] = hl.fragmenter
		}
		if hl.highlightQuery != nil {
			highlightS["highlight_query"] = hl.highlightQuery.Source()
		}
		if hl.noMatchSize != nil {
			highlightS["no_match_size"] = *hl.noMatchSize
		}
		if len(hl.options) > 0 {
			highlightS["options"] = hl.options
		}
		if hl.forceSource != nil {
			highlightS["force_source"] = *hl.forceSource
		}
		if len(hl.fields) > 0 {
			fieldsS := make(map[string]interface{})
			for _, field := range hl.fields {
				fieldsS[field.Name] = field.Source()
			}
			highlightS["fields"] = fieldsS
		}

		return highlightS
	*/
}
1185301
func (ns *Namespace) HTMLEscape(s interface{}) (string, error) {
	ss, err := cast.ToStringE(s)
	if err != nil {
		return "", err
	}

	return html.EscapeString(ss), nil
}
234190
func (s *SVG) header() string {
	return fmt.Sprintf("<svg xmlns='http://www.w3.org/2000/svg' width='%v' height='%v'>", s.width, s.height)
}
77675
func (z *TokenBuffer) Attributes(hashes ...svg.Hash) ([]*Token, *Token) {
	n := 0
	for {
		if t := z.Peek(n); t.TokenType != xml.AttributeToken {
			break
		}
		n++
	}
	if len(hashes) > cap(z.attrBuffer) {
		z.attrBuffer = make([]*Token, len(hashes))
	} else {
		z.attrBuffer = z.attrBuffer[:len(hashes)]
		for i := range z.attrBuffer {
			z.attrBuffer[i] = nil
		}
	}
	var replacee *Token
	for i := z.pos; i < z.pos+n; i++ {
		attr := &z.buf[i]
		for j, hash := range hashes {
			if hash == attr.Hash {
				z.attrBuffer[j] = attr
				replacee = attr
			}
		}
	}
	return z.attrBuffer, replacee
}
786073
func (vr *vectorRenderer) MeasureText(body string) (box Box) {
	if vr.s.GetFont() != nil {
		vr.fc = &font.Drawer{
			Face: truetype.NewFace(vr.s.GetFont(), &truetype.Options{
				DPI:  vr.dpi,
				Size: vr.s.FontSize,
			}),
		}
		w := vr.fc.MeasureString(body).Ceil()

		box.Right = w
		box.Bottom = int(drawing.PointsToPixels(vr.dpi, vr.s.FontSize))
		if vr.c.textTheta == nil {
			return
		}
		box = box.Corners().Rotate(util.Math.RadiansToDegrees(*vr.c.textTheta)).Box()
	}
	return
}
449753
func (s *SVG) Polyline(str string, args map[string]interface{}) {
	polylineStr := fmt.Sprintf("<polyline points='%s' %s />", str, s.WriteArgs(args))
	s.svgString += polylineStr
}
94953
func (h *Histo) Metric() (*metricpb.Metric, error) {
	return &metricpb.Metric{
		Name: h.Name,
		Tags: h.Tags,
		Type: metricpb.Type_Histogram,
		Value: &metricpb.Metric_Histogram{&metricpb.HistogramValue{
			TDigest: h.Value.Data(),
		}},
	}, nil
}