• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang doc.ToText函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中go/doc.ToText函数的典型用法代码示例。如果您正苦于以下问题:Golang ToText函数的具体用法?Golang ToText怎么用?Golang ToText使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ToText函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: writeHelp

func (c *Application) writeHelp(width int, w io.Writer) {
	s := []string{formatArgsAndFlags(c.Name, c.argGroup, c.flagGroup)}
	if len(c.commands) > 0 {
		s = append(s, "<command>", "[<flags>]", "[<args> ...]")
	}

	prefix := "usage: "
	usage := strings.Join(s, " ")
	buf := bytes.NewBuffer(nil)
	doc.ToText(buf, usage, "", preIndent, width-len(prefix))
	lines := strings.Split(strings.TrimRight(buf.String(), "\n"), "\n")

	fmt.Fprintf(w, "%s%s\n", prefix, lines[0])
	for _, l := range lines[1:] {
		fmt.Fprintf(w, "%*s%s\n", len(prefix), "", l)
	}
	if c.Help != "" {
		fmt.Fprintf(w, "\n")
		doc.ToText(w, c.Help, "", preIndent, width)
	}

	c.flagGroup.writeHelp(width, w)
	c.argGroup.writeHelp(width, w)

	if len(c.commands) > 0 {
		fmt.Fprintf(w, "\nCommands:\n")
		c.helpCommands(width, w)
	}
}
开发者ID:jessereynolds,项目名称:coco,代码行数:29,代码来源:usage.go


示例2: godoc

func godoc(member, content string) string {
	undocumented := "// " + exportable(member) + " is undocumented.\n"

	node, err := html.Parse(strings.NewReader(content))
	if err != nil {
		return undocumented
	}

	_, v, err := sandblast.Extract(node)
	if err != nil {
		return undocumented
	}

	v = strings.TrimSpace(v)
	if v == "" {
		return undocumented
	}

	if member != "" {
		v = exportable(member) + " " + strings.ToLower(v[0:1]) + v[1:]
	}

	out := bytes.NewBuffer(nil)
	doc.ToText(out, v, "// ", "", 72)
	return out.String()
}
开发者ID:ComeOn-Wuhan,项目名称:lantern,代码行数:26,代码来源:helpers.go


示例3: printText

func (p *docPrinter) printText(s string) {
	s = strings.TrimRight(s, " \t\n")
	if s != "" {
		p.scratch.Reset()
		godoc.ToText(&p.scratch, s, textIndent, textIndent+"\t", textWidth)
		blank := 0
		for _, line := range bytes.Split(p.scratch.Bytes(), []byte{'\n'}) {
			if len(line) == 0 {
				blank++
			} else {
				const k = len(textIndent) + 1
				if blank == 2 && len(line) > k && line[k] != ' ' {
					p.WriteString("\n")
					p.PushHighlight(headerGroup)
					p.Write(line)
					p.PopHighlight()
					p.WriteString("\n")
				} else {
					for i := 0; i < blank; i++ {
						p.WriteString("\n")
					}
					p.Write(line)
					p.WriteString("\n")
				}
				blank = 0
			}
		}
		p.WriteString("\n")
	}
}
开发者ID:garyburd,项目名称:vigor,代码行数:30,代码来源:doc.go


示例4: packageDoc

// packageDoc prints the docs for the package (package doc plus one-liners of the rest).
func (pkg *Package) packageDoc(showRaml bool) {
	defer pkg.flush()
	if pkg.showInternals() && !showRaml {
		pkg.packageClause(false)
	}

	doc.ToText(&pkg.buf, pkg.doc.Doc, "", indent, indentedWidth)
	pkg.newlines(1)

	if !pkg.showInternals() {
		// Show only package docs for commands.
		return
	}

	pkg.newlines(1)

	if showRaml == true {
		pkg.ramls()
	} else {
		pkg.valueSummary(pkg.doc.Consts)
		pkg.valueSummary(pkg.doc.Vars)
		pkg.funcSummary(pkg.doc.Funcs)
		pkg.typeSummary()
		pkg.bugs()
	}
}
开发者ID:CiscoCloud,项目名称:go,代码行数:27,代码来源:pkg.go


示例5: commentTextFn

// commentTextFn formats a source code comment as text.
func commentTextFn(v string) string {
	const indent = "    "
	var buf bytes.Buffer
	godoc.ToText(&buf, v, indent, "\t", 80-2*len(indent))
	p := buf.Bytes()
	return string(p)
}
开发者ID:jjmiv,项目名称:gddo,代码行数:8,代码来源:template.go


示例6: formatTwoColumns

func formatTwoColumns(w io.Writer, indent, padding, width int, rows [][2]string) {
	// Find size of first column.
	s := 0
	for _, row := range rows {
		if c := len(row[0]); c > s && c < 30 {
			s = c
		}
	}

	indentStr := strings.Repeat(" ", indent)
	offsetStr := strings.Repeat(" ", s+padding)

	for _, row := range rows {
		buf := bytes.NewBuffer(nil)
		doc.ToText(buf, row[1], "", preIndent, width-s-padding-indent)
		lines := strings.Split(strings.TrimRight(buf.String(), "\n"), "\n")
		fmt.Fprintf(w, "%s%-*s%*s", indentStr, s, row[0], padding, "")
		if len(row[0]) >= 30 {
			fmt.Fprintf(w, "\n%s%s", indentStr, offsetStr)
		}
		fmt.Fprintf(w, "%s\n", lines[0])
		for _, line := range lines[1:] {
			fmt.Fprintf(w, "%s%s%s\n", indentStr, offsetStr, line)
		}
	}
}
开发者ID:CameloeAnthony,项目名称:ghostunnel,代码行数:26,代码来源:usage.go


示例7: printMethodDoc

// printMethodDoc prints the docs for matches of symbol.method.
// If symbol is empty, it prints all methods that match the name.
// It reports whether it found any methods.
func (pkg *Package) printMethodDoc(symbol, method string) bool {
	defer pkg.flush()
	types := pkg.findTypes(symbol)
	if types == nil {
		if symbol == "" {
			return false
		}
		pkg.Fatalf("symbol %s is not a type in package %s installed in %q", symbol, pkg.name, pkg.build.ImportPath)
	}
	found := false
	for _, typ := range types {
		if len(typ.Methods) > 0 {
			for _, meth := range typ.Methods {
				if match(method, meth.Name) {
					decl := meth.Decl
					decl.Body = nil
					pkg.emit(meth.Doc, decl)
					found = true
				}
			}
			continue
		}
		// Type may be an interface. The go/doc package does not attach
		// an interface's methods to the doc.Type. We need to dig around.
		spec := pkg.findTypeSpec(typ.Decl, typ.Name)
		inter, ok := spec.Type.(*ast.InterfaceType)
		if !ok {
			// Not an interface type.
			// TODO? Maybe handle struct fields here.
			continue
		}
		for _, iMethod := range inter.Methods.List {
			// This is an interface, so there can be only one name.
			// TODO: Anonymous methods (embedding)
			if len(iMethod.Names) == 0 {
				continue
			}
			name := iMethod.Names[0].Name
			if match(method, name) {
				// pkg.oneLineField(iMethod, 0)
				if iMethod.Doc != nil {
					for _, comment := range iMethod.Doc.List {
						doc.ToText(&pkg.buf, comment.Text, "", indent, indentedWidth)
					}
				}
				s := pkg.oneLineNode(iMethod.Type)
				// Hack: s starts "func" but there is no name present.
				// We could instead build a FuncDecl but it's not worthwhile.
				lineComment := ""
				if iMethod.Comment != nil {
					lineComment = fmt.Sprintf("  %s", iMethod.Comment.List[0].Text)
				}
				pkg.Printf("func %s%s%s\n", name, s[4:], lineComment)
				found = true
			}
		}
	}
	return found
}
开发者ID:achanda,项目名称:go,代码行数:62,代码来源:pkg.go


示例8: writeEnum

func writeEnum(scope Scope, opt Option, delta int) {
	fmt.Println()
	if opt.Description != "" {
		doc.ToText(os.Stdout, opt.Description, "    // ", "", 73)
		// fmt.Printf("	// %s\n", opt.Description)
	}
	fmt.Printf("	%s %s = %d\n", scope.Name+translateName(opt.Name), scope.Name, opt.Code+delta)
}
开发者ID:ptomasroos,项目名称:fdb-go,代码行数:8,代码来源:translate_fdb_options.go


示例9: comment_textFunc

func comment_textFunc(comment, indent, preIndent string) string {
	var buf bytes.Buffer
	doc.ToText(&buf, comment, indent, preIndent, punchCardWidth-2*len(indent))
	if containsOnlySpace(buf.Bytes()) {
		return ""
	}
	return buf.String()
}
开发者ID:iolg,项目名称:golangdoc,代码行数:8,代码来源:godoc.go


示例10: printParagraph

func printParagraph(indent string, bulletCharacter byte, text string) {
	var buf bytes.Buffer
	doc.ToText(&buf, text, indent, indent, 79-len(indent))
	output := buf.Bytes()
	if len(output) > len(indent) && len(indent) > 2 {
		bulletPos := len(indent) - 2
		output[bulletPos] = bulletCharacter
	}
	os.Stdout.Write(output)
}
开发者ID:qt,项目名称:qtqa,代码行数:10,代码来源:main.go


示例11: printText

func (p *docPrinter) printText(s string) {
	s = strings.TrimRight(s, " \t\n")
	if s != "" {
		doc.ToText(&p.buf, s, textIndent, textIndent+"\t", textWidth)
		b := p.buf.Bytes()
		if b[len(b)-1] != '\n' {
			p.buf.WriteByte('\n')
		}
		p.buf.WriteByte('\n')
	}
}
开发者ID:gosuri,项目名称:dotfiles,代码行数:11,代码来源:doc.go


示例12: String

func (d *Doc) String() string {
	buf := &bytes.Buffer{}
	if d.Import != "" {
		fmt.Fprintf(buf, "import \"%s\"\n\n", d.Import)
	}
	fmt.Fprintf(buf, "%s\n\n", d.Decl)
	if d.Doc == "" {
		d.Doc = "Undocumented."
	}
	doc.ToText(buf, d.Doc, indent, preIndent, *linelength)
	return buf.String()
}
开发者ID:zmb3,项目名称:gogetdoc,代码行数:12,代码来源:main.go


示例13: helpCommands

func (c *Application) helpCommands(width int, w io.Writer) {
	for _, cmd := range c.commandOrder {
		fmt.Fprintf(w, "  %s\n", formatArgsAndFlags(cmd.name, cmd.argGroup, cmd.flagGroup))
		buf := bytes.NewBuffer(nil)
		doc.ToText(buf, cmd.help, "", preIndent, width-4)
		lines := strings.Split(strings.TrimRight(buf.String(), "\n"), "\n")
		for _, line := range lines {
			fmt.Fprintf(w, "    %s\n", line)
		}
		fmt.Fprintf(w, "\n")
	}
}
开发者ID:jessereynolds,项目名称:coco,代码行数:12,代码来源:usage.go


示例14: packageDoc

// packageDoc prints the docs for the package (package doc plus one-liners of the rest).
func (pkg *Package) packageDoc() {
	defer pkg.flush()
	pkg.packageClause(false)

	doc.ToText(&pkg.buf, pkg.doc.Doc, "", "\t", 80)
	pkg.newlines(2)

	pkg.valueSummary(pkg.doc.Consts)
	pkg.valueSummary(pkg.doc.Vars)
	pkg.funcSummary(pkg.doc.Funcs)
	pkg.typeSummary()
	pkg.bugs()
}
开发者ID:josharian,项目名称:go.ssa,代码行数:14,代码来源:pkg.go


示例15: emit

// emit prints the node.
func (pkg *Package) emit(comment string, node ast.Node) {
	if node != nil {
		err := format.Node(&pkg.buf, pkg.fs, node)
		if err != nil {
			log.Fatal(err)
		}
		if comment != "" {
			pkg.newlines(2) // Guarantee blank line before comment.
			doc.ToText(&pkg.buf, comment, "    ", indent, indentedWidth)
		}
		pkg.newlines(1)
	}
}
开发者ID:GeorgiCodes,项目名称:go,代码行数:14,代码来源:pkg.go


示例16: emit

// emit prints the node.
func (pkg *Package) emit(comment string, node ast.Node) {
	if node != nil {
		err := format.Node(&pkg.buf, pkg.fs, node)
		if err != nil {
			log.Fatal(err)
		}
		if comment != "" {
			pkg.newlines(1)
			doc.ToText(&pkg.buf, comment, "    ", indent, indentedWidth)
			pkg.newlines(2) // Blank line after comment to separate from next item.
		} else {
			pkg.newlines(1)
		}
	}
}
开发者ID:sreis,项目名称:go,代码行数:16,代码来源:pkg.go


示例17: writeHelp

func (c *cmdGroup) writeHelp(width int, w io.Writer) {
	if len(c.commands) == 0 {
		return
	}
	fmt.Fprintf(w, "\nCommands:\n")
	flattened := c.flattenedCommands()
	for _, cmd := range flattened {
		fmt.Fprintf(w, "  %s\n", formatArgsAndFlags(cmd.FullCommand(), cmd.argGroup, cmd.flagGroup, cmd.cmdGroup))
		buf := bytes.NewBuffer(nil)
		doc.ToText(buf, cmd.help, "", preIndent, width-4)
		lines := strings.Split(strings.TrimRight(buf.String(), "\n"), "\n")
		for _, line := range lines {
			fmt.Fprintf(w, "    %s\n", line)
		}
		fmt.Fprintf(w, "\n")
	}
}
开发者ID:Yossibh,项目名称:envdb,代码行数:17,代码来源:usage.go


示例18: writeSampleDescription

// writeSampleDescription writes the given attribute to w
// prefixed by the given indentation string.
func writeSampleDescription(w io.Writer, f Attr, indent string) {
	previousText := false

	// section marks the start of a new section of the comment;
	// sections are separated with empty lines.
	section := func() {
		if previousText {
			fmt.Fprintf(w, "%s\n", strings.TrimRightFunc(indent, unicode.IsSpace))
		}
		previousText = true
	}

	descr := strings.TrimSpace(f.Description)
	if descr != "" {
		section()
		doc.ToText(w, descr, indent, "    ", textWidth-len(indent))
	}
	vars := make([]string, 0, len(f.EnvVars)+1)
	if f.EnvVar != "" {
		vars = append(vars, "$"+f.EnvVar)
	}
	for _, v := range f.EnvVars {
		vars = append(vars, "$"+v)
	}
	if len(vars) > 0 {
		section()
		fmt.Fprintf(w, "%sDefault value taken from %s.\n", indent, wordyList(vars))
	}
	attrText := ""
	switch {
	case f.Secret && f.Immutable:
		attrText = "immutable and considered secret"
	case f.Secret:
		attrText = "considered secret"
	case f.Immutable:
		attrText = "immutable"
	}
	if attrText != "" {
		section()
		fmt.Fprintf(w, "%sThis attribute is %s.\n", indent, attrText)
	}
	section()
}
开发者ID:cmars,项目名称:oo,代码行数:45,代码来源:sample.go


示例19: godoc

func godoc(name, helpText string, indent string) string {
	node, err := html.Parse(strings.NewReader(helpText))
	if err != nil {
		return "no documentation"
	}

	_, helpText, err = sandblast.Extract(node)
	if err != nil {
		return "no documentation"
	}

	helpText = strings.TrimSpace(helpText)
	if helpText == "" {
		helpText = "no documentation"
	}

	text := upper(name) + " - " + helpText
	out := bytes.NewBuffer(nil)
	doc.ToText(out, text, indent+"// ", "", 100)
	return out.String()
}
开发者ID:carriercomm,项目名称:softlayer-go,代码行数:21,代码来源:types.go


示例20: packageDoc

// packageDoc prints the docs for the package (package doc plus one-liners of the rest).
func (pkg *Package) packageDoc() {
	defer pkg.flush()
	if pkg.showInternals() {
		pkg.packageClause(false)
	}

	doc.ToText(&pkg.buf, pkg.doc.Doc, "", indent, indentedWidth)
	pkg.newlines(1)

	if !pkg.showInternals() {
		// Show only package docs for commands.
		return
	}

	pkg.newlines(2) // Guarantee blank line before the components.
	pkg.valueSummary(pkg.doc.Consts)
	pkg.valueSummary(pkg.doc.Vars)
	pkg.funcSummary(pkg.doc.Funcs)
	pkg.typeSummary()
	pkg.bugs()
}
开发者ID:sreis,项目名称:go,代码行数:22,代码来源:pkg.go



注:本文中的go/doc.ToText函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang doc.Package类代码示例发布时间:2022-05-28
下一篇:
Golang doc.ToHTML函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap