// AutoLink defines how auto-detected links should be processed to produce corresponding HTML elements.
// Reference for kind: https://github.com/russross/blackfriday/blob/master/markdown.go#L69-L76
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)
}
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
}
620200
func (e *EmbeddedBox) Link() {
	for _, ed := range e.Dirs {
		ed.ChildDirs = make([]*EmbeddedDir, 0)
		ed.ChildFiles = make([]*EmbeddedFile, 0)
	}
	for path, ed := range e.Dirs {
		// skip for root, it'll create a recursion
		if path == "" {
			continue
		}
		parentDirpath, _ := filepath.Split(path)
		if strings.HasSuffix(parentDirpath, "/") {
			parentDirpath = parentDirpath[:len(parentDirpath)-1]
		}
		parentDir := e.Dirs[parentDirpath]
		if parentDir == nil {
			panic("parentDir `" + parentDirpath + "` is missing in embedded box")
		}
		parentDir.ChildDirs = append(parentDir.ChildDirs, ed)
	}
	for path, ef := range e.Files {
		dirpath, _ := filepath.Split(path)
		if strings.HasSuffix(dirpath, "/") {
			dirpath = dirpath[:len(dirpath)-1]
		}
		dir := e.Dirs[dirpath]
		if dir == nil {
			panic("dir `" + dirpath + "` is missing in embedded box")
		}
		dir.ChildFiles = append(dir.ChildFiles, ef)
	}
}
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
}
134959
func (tx *Transaction) AddLink(args ...string) {
	tx.exec(append([]string{"link", "add", tx.link}, args...))
}
221166
func Link(doners ...Doner) C {
	c := make(chan struct{})
	cancel := func() { close(c) }

	var once sync.Once
	for _, d := range doners {
		Defer(d, func() { once.Do(cancel) })
	}

	return c
}
1041103
func autoDiscover(body []byte) (feedURL string, err error) {
	r := bytes.NewReader(body)
	z := html.NewTokenizer(r)
	for {
		if z.Next() == html.ErrorToken {
			break
		}
		t := z.Token()
		switch t.DataAtom {
		case atom.Link:
			if t.Type == html.StartTagToken || t.Type == html.SelfClosingTagToken {
				attrs := make(map[string]string)
				for _, a := range t.Attr {
					attrs[a.Key] = a.Val
				}
				if attrs["rel"] == "alternate" && attrs["href"] != "" &&
					(attrs["type"] == "application/rss+xml" || attrs["type"] == "application/atom+xml") {
					return attrs["href"], nil
				}
			}
		}
	}
	return "", fmt.Errorf("No feed link found")
}
939804
func (i *HTTPInstaller) link(from string) error {
	debug("symlinking %s to %s", from, i.Path())
	return os.Symlink(from, i.Path())
}
858145
func (b BuilderID) SelfLink(project string) string {
	return model.BuilderIDLink(string(b), project)
}
599821
func (a *AddressTx) Link() string {
	if a.MergedTxnCount > 0 {
		direction := "in"
		if a.IsFunding {
			direction = "out"
		}
		return fmt.Sprintf("/tx/%s/%s/%d", a.TxID, direction, a.InOutID)
	}
	return fmt.Sprintf("/tx/%s", a.TxID)
}
1319611
func (e *AutoscalingGroup) TerraformLink() *terraform.Literal {
	return terraform.LiteralProperty("aws_autoscaling_group", fi.StringValue(e.Name), "id")
}
1070244
func (z *Zing) GetDirectLink(link string) ([]glod.Response, error) {
	if link == "" {
		return nil, errors.New("Empty Link")
	}

	var listLink []string

	if strings.Contains(link, zingSong) {
		if len(strings.Split(link, "/")) < 6 {
			return nil, errors.New("Invalid link")
		}
		listLink = append(listLink, link)
	} else if strings.Contains(link, zingAlbum) || strings.Contains(link, playList) {
		doc, err := goquery.NewDocument(link)
		if err != nil {
			return nil, err
		}
		doc.Find(".item-song").Find("a").Each(func(i int, s *goquery.Selection) {
			url, _ := s.Attr("href")
			if strings.Contains(url, "bai-hat") {
				listLink = append(listLink, url)
			}
		})
	}

	listSong := GetSongs(listLink)

	return listSong, nil
}
374918
func (b *Browser) Symlink(_, _ string) (err error) {
	return errors.New("browser cannot make symlinks")
}
36299
func Auto() {
	app.OnInit(func() error {
		if !config.Exist(optionKey) {
			return errors.New("can't find option: " + optionKey)
		}

		var opts Options
		err := config.UnmarshalOption(optionKey, &opts)
		if err != nil {
			return errors.Wrap(err, "failed to parse options")
		}

		err = opts.ensure()
		if err != nil {
			return errors.Wrap(err, "invalid options")
		}

		//metricsFactory := metrics.NullFactory
		tracer, closer, err := newConfig(&opts).New(opts.Name, jc.Logger(&loggerAdapter{}))
		if err != nil {
			return errors.Wrap(err, "failed to initialize jaeger tracer")
		}
		trace.SetTracer(tracer)

		app.OnClose(func() {
			err := closer.Close()
			if err != nil {
				log.Get(PkgName).Warn(err)
			}
		})
		return nil
	})
}
847078
func stripLink(input string) (output string) {
	stringPattern := regexp.MustCompile("^(.*)$")
	stringWithLinkPattern := regexp.MustCompile("^<a .*</a>(.*)$")
	if matches := stringWithLinkPattern.FindSubmatch([]byte(input)); matches != nil {
		return string(matches[1])
	} else if matches := stringPattern.FindSubmatch([]byte(input)); matches != nil {
		return string(matches[1])
	} else {
		return input
	}
}
36798
func ValidateLink(val string) (string, error) {
	_, _, err := ParseLink(val)
	return val, err
}
210981
func Auto() (server *Server) {
	c := &Options{}
	err := config.UnmarshalOption("web", c)
	if err != nil {
		panic(err)
	}
	return New(c)
}