当前位置: 首页>>代码示例>>Golang>>正文


Golang doc.ToText函数代码示例

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


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


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