// RenderSpecialLink renders mentions, indexes and SHA1 strings to corresponding links.
194793
func RenderSpecialLink(rawBytes []byte, urlPrefix string, metas map[string]string) []byte {
	ms := MentionPattern.FindAll(rawBytes, -1)
	for _, m := range ms {
		m = m[bytes.Index(m, []byte("@")):]
		rawBytes = bytes.Replace(rawBytes, m,
			[]byte(fmt.Sprintf(`<a href="%s/%s">%s</a>`, setting.AppSubURL, m[1:], m)), -1)
	}

	rawBytes = RenderIssueIndexPattern(rawBytes, urlPrefix, metas)
	rawBytes = RenderCrossReferenceIssueIndexPattern(rawBytes, urlPrefix, metas)
	rawBytes = RenderSha1CurrentPattern(rawBytes, urlPrefix)
	return rawBytes
}
669367
func (view *View) RenderFromString(loaderName string, tplSrc string, data map[string]interface{}) (string, error) {
	var buf bytes.Buffer
	// If loaderName is not indicated, use the default template library of Go, no syntax like
	// `extends` or `include` will be supported.
	if loaderName == "" {
		tmpl := template.New("error")
		tmpl.Parse(tplSrc)
		e := tmpl.Execute(&buf, data)
		return buf.String(), e
	}
	loader, ok := view.templateLoader[loaderName]
	if !ok {
		panic(Errorf("Template loader not fount: %s", loaderName))
	}
	e := loader.Render(&buf, tplSrc, data)
	if e != nil {
		return "", e
	}
	return buf.String(), nil
}
1098194
func (c ConstantMap) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
	rt := RootTypeSpec(t)
	if _, isStruct := rt.(*StructSpec); isStruct {
		cs, err := buildConstantStruct(c)
		if err != nil {
			return nil, constantValueCastError{
				Value:  c,
				Type:   t,
				Reason: err,
			}
		}
		return cs.Link(scope, t)
	}

	m, ok := rt.(*MapSpec)
	if !ok {
		return nil, constantValueCastError{Value: c, Type: t}
	}

	items := make([]ConstantValuePair, len(c))
	for i, item := range c {
		key, err := item.Key.Link(scope, m.KeySpec)
		if err != nil {
			return nil, err
		}

		value, err := item.Value.Link(scope, m.ValueSpec)
		if err != nil {
			return nil, err
		}

		// TODO(abg): Duplicate key check
		items[i] = ConstantValuePair{Key: key, Value: value}
	}

	return ConstantMap(items), nil
}
207902
func (s *ServiceSpec) Link(scope Scope) error {
	if s.linked() {
		return nil
	}

	if s.parentSrc != nil {
		parent, err := resolveService(*s.parentSrc, scope)
		if err != nil {
			return compileError{
				Target: s.Name,
				Reason: referenceError{
					Target:    s.parentSrc.Name,
					Line:      s.parentSrc.Line,
					ScopeName: scope.GetName(),
					Reason:    err,
				},
			}
		}

		if err := parent.Link(scope); err != nil {
			return compileError{Target: s.Name, Reason: err}
		}

		s.Parent = parent
		s.parentSrc = nil
	}

	for _, function := range s.Functions {
		if err := function.Link(scope); err != nil {
			return compileError{
				Target: s.Name + "." + function.Name,
				Reason: err,
			}
		}
	}

	return nil
}
1219578
func (s siteRenderContext) renderSingletonPages() bool {
	if s.multihost {
		// 1 per site
		return s.outIdx == 0
	}

	// 1 for all sites
	return s.sitesOutIdx == 0

}
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)
}
250589
func (this *MarkupConfluence) link(anchorName, linkText string) string {
	if linkText == "" {
		return fmt.Sprintf("[#%s]", anchorName)
	}
	return fmt.Sprintf("[%s|#%s]", linkText, anchorName)
}
467994
func (s *LDAPService) LinkDomainToLdap(p *LinkDomainToLdapParams) (*LinkDomainToLdapResponse, error) {
	resp, err := s.cs.newRequest("linkDomainToLdap", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r LinkDomainToLdapResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	return &r, nil
}
271317
func (s *BatchListIncomingTypedLinksResponse) SetLinkSpecifiers(v []*TypedLinkSpecifier) *BatchListIncomingTypedLinksResponse {
	s.LinkSpecifiers = v
	return s
}
226831
func (set *TemplateSet) RenderTemplateString(s string, ctx Context) (string, error) {
	set.firstTemplateCreated = true

	tpl := Must(set.FromString(s))
	result, err := tpl.Execute(ctx)
	if err != nil {
		return "", err
	}
	return result, nil
}
370628
func (e *Editor) RmLink(ctx context.Context, pth string) error {
	splpath := path.SplitList(pth)
	nd, err := e.rmLink(ctx, e.root, splpath)
	if err != nil {
		return err
	}
	e.root = nd
	return nil
}
643953
func (c *ConstantStruct) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
	s, ok := RootTypeSpec(t).(*StructSpec)
	if !ok {
		return nil, constantValueCastError{Value: c, Type: t}
	}

	for _, field := range s.Fields {
		f, ok := c.Fields[field.Name]
		if !ok {
			if field.Default == nil {
				if field.Required {
					return nil, constantValueCastError{
						Value:  c,
						Type:   t,
						Reason: fmt.Errorf("%q is a required field", field.Name),
					}
				}
				continue
			}
			f = field.Default
			c.Fields[field.Name] = f
		}

		f, err := f.Link(scope, field.Type)
		if err != nil {
			return nil, constantValueCastError{
				Value: c,
				Type:  t,
				Reason: constantStructFieldCastError{
					FieldName: field.Name,
					Reason:    err,
				},
			}
		}

		c.Fields[field.Name] = f
	}

	return c, nil
}
299846
func (m *Manifest) Render() string {
	var b bytes.Buffer
	size := len(m.sections) - 1

	for i, section := range m.sections {
		b.WriteString(fmt.Sprintf("[%s]\n", section.key))
		if section.content != "" {
			b.WriteString(section.content)
		}
		for _, x := range section.entries {
			b.WriteString(x)
		}
		if i < size {
			b.WriteString("\n")
		}
	}

	return b.String()
}
436684
func (r *MarkdownRenderer) AutoLink(out *bytes.Buffer, link []byte, kind int) {
	if kind != blackfriday.LINK_TYPE_NORMAL {
		r.Renderer.AutoLink(out, link, kind)
		return
	}

	// Since this method could only possibly serve one link at a time,
	// we do not need to find all.
	if bytes.HasPrefix(link, []byte(setting.AppURL)) {
		m := CommitPattern.Find(link)
		if m != nil {
			m = bytes.TrimSpace(m)
			i := strings.Index(string(m), "commit/")
			j := strings.Index(string(m), "#")
			if j == -1 {
				j = len(m)
			}
			out.WriteString(fmt.Sprintf(` <code><a href="%s">%s</a></code>`, m, tool.ShortSHA1(string(m[i+7:j]))))
			return
		}

		m = IssueFullPattern.Find(link)
		if m != nil {
			m = bytes.TrimSpace(m)
			i := strings.Index(string(m), "issues/")
			j := strings.Index(string(m), "#")
			if j == -1 {
				j = len(m)
			}

			index := string(m[i+7 : j])
			fullRepoURL := setting.AppURL + strings.TrimPrefix(r.urlPrefix, "/")
			var link string
			if strings.HasPrefix(string(m), fullRepoURL) {
				// Use a short issue reference if the URL refers to this repository
				link = fmt.Sprintf(`<a href="%s">#%s</a>`, m, index)
			} else {
				// Use a cross-repository issue reference if the URL refers to a different repository
				repo := string(m[len(setting.AppURL) : i-1])
				link = fmt.Sprintf(`<a href="%s">%s#%s</a>`, m, repo, index)
			}
			out.WriteString(link)
			return
		}
	}

	r.Renderer.AutoLink(out, link, kind)
}
482814
func (m *MapSpec) Link(scope Scope) (TypeSpec, error) {
	if m.linked() {
		return m, nil
	}

	var err error
	m.KeySpec, err = m.KeySpec.Link(scope)
	if err != nil {
		return m, err
	}

	m.ValueSpec, err = m.ValueSpec.Link(scope)
	if err != nil {
		return m, err
	}

	return m, nil
}
1351609
func (s *Site) renderPages(ctx *siteRenderContext) error {

	numWorkers := config.GetNumWorkerMultiplier()

	results := make(chan error)
	pages := make(chan *pageState, numWorkers) // buffered for performance
	errs := make(chan error)

	go s.errorCollator(results, errs)

	wg := &sync.WaitGroup{}

	for i := 0; i < numWorkers; i++ {
		wg.Add(1)
		go pageRenderer(ctx, s, pages, results, wg)
	}

	cfg := ctx.cfg

	if !cfg.PartialReRender && ctx.outIdx == 0 && len(s.headlessPages) > 0 {
		wg.Add(1)
		go headlessPagesPublisher(s, wg)
	}

L:
	for _, page := range s.workAllPages {
		if cfg.shouldRender(page) {
			select {
			case <-s.h.Done():
				break L
			default:
				pages <- page
			}
		}
	}

	close(pages)

	wg.Wait()

	close(results)

	err := <-errs
	if err != nil {
		return errors.Wrap(err, "failed to render pages")
	}
	return nil
}
65969
func (f *FingerprintResponse) RemoveLink(name string) {
	// initialize Links if it has not been already
	if f.Links == nil {
		f.Links = make(map[string]string, 0)
	}

	f.Links[name] = ""
}