當前位置: 首頁>>代碼示例>>Golang>>正文


Golang html.Render函數代碼示例

本文整理匯總了Golang中code/google/com/p/go/net/html.Render函數的典型用法代碼示例。如果您正苦於以下問題:Golang Render函數的具體用法?Golang Render怎麽用?Golang Render使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Render函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: finalizeEntity

// Archive / upload final entity HTML
func finalizeEntity(entity *Entity, doc *html.Node, entDir string) {
	log.Println("Entity tmp directory: ", entDir)

	var finalHTML bytes.Buffer
	bl := html.Render(&finalHTML, doc)
	if bl != nil {
		log.Println(bl)
	}

	err := StoreHTML(finalHTML, entDir)
	if err != nil {
		log.Println("Error in StoreHTML: ", err)
	}

	zipName, err := ArchiveFinalFiles(entDir)
	if err != nil {
		log.Println("Error archiving files: ", err)
	}

	err = Update(entity, bson.M{"uuid": entity.UUID}, bson.M{"$set": bson.M{"status": UploadingStatus}})
	if err != nil {
		log.Println("Error updating entity: ", err)
	}

	awsLink, err := UploadEntity(zipName, entity)
	if err != nil {
		log.Println("Error uploading final files: ", err)
	}

	err = Update(entity, bson.M{"uuid": entity.UUID}, bson.M{"$set": bson.M{"aws_link": awsLink, "status": CompleteStatus}})
	if err != nil {
		log.Println("Error updating entity: ", err)
	}
}
開發者ID:yeah-right,項目名稱:webhog,代碼行數:35,代碼來源:parse.go

示例2: FetchFullDescription

func FetchFullDescription(link string) string {
	res, err := http.Get(link)
	if err != nil {
		log.Fatal(err)
	}
	body, err := ioutil.ReadAll(res.Body)
	res.Body.Close()
	if err != nil {
		log.Fatal(err)
	}
	doc, err := html.Parse(strings.NewReader(string(body)))
	content := ""
	var f func(*html.Node)
	f = func(n *html.Node) {
		if n.Type == html.ElementNode && n.Data == "section" {
			for _, a := range n.Attr {
				if a.Key == "class" && a.Val == "entry-content cf" {
					var buf bytes.Buffer
					html.Render(&buf, n)
					content = buf.String()
					break
				}
			}
		}
		for c := n.FirstChild; c != nil; c = c.NextSibling {
			f(c)
		}
	}
	f(doc)
	return content
}
開發者ID:john-griffin,項目名稱:bcool,代碼行數:31,代碼來源:bcool.go

示例3: fixHtml

// FixHtml parses bytes as HTML and returns well-formed HTML if the parse
// was successful, or escaped HTML, if not.
func fixHtml(linkUrl string, wild []byte) (well []byte) {
	n, err := html.Parse(bytes.NewReader(wild))
	if err != nil {
		return []byte(html.EscapeString(string(wild)))
	}

	fixImgs(linkUrl, n)

	defer func() {
		if err := recover(); err == bytes.ErrTooLarge {
			well = []byte(html.EscapeString(string(wild)))
		} else if err != nil {
			panic(err)
		}
	}()
	buf := bytes.NewBuffer(make([]byte, 0, len(wild)*2))
	if err := html.Render(buf, n); err != nil {
		return []byte(html.EscapeString(string(wild)))
	}

	well = buf.Bytes()
	openBody := []byte("<body>")
	i := bytes.Index(well, openBody)
	if i < 0 {
		return []byte(html.EscapeString(string(wild)))
	}
	well = well[i+len(openBody):]

	closeBody := []byte("</body>")
	i = bytes.Index(well, closeBody)
	if i < 0 {
		return []byte(html.EscapeString(string(wild)))
	}
	return well[:i]
}
開發者ID:eaburns,項目名稱:feedme,代碼行數:37,代碼來源:webfeed.go

示例4: StrFromNodes

// StrFromNodes returns the string of the rendered html.Nodes.
func StrFromNodes(nodes []*html.Node) string {
	buf := bytes.NewBuffer([]byte{})
	for _, h := range nodes {
		html.Render(buf, h)
	}
	return buf.String()
}
開發者ID:kleopatra999,項目名稱:piccolo,代碼行數:8,代碼來源:main.go

示例5: String

func (n *node) String() string {
	var buf bytes.Buffer
	if err := html.Render(&buf, n.node); err != nil {
		panic(err)
	}
	return buf.String()
}
開發者ID:rainycape,項目名稱:macaco,代碼行數:7,代碼來源:html.go

示例6: DomTree2HTML

func DomTree2HTML(DOMTree []*html.Node) {
	HTML5 := bytes.NewBuffer([]byte{})
	for _, node := range DOMTree {
		html.Render(HTML5, node)
	}
	fmt.Printf("Node: %s", HTML5)
}
開發者ID:tav,項目名稱:oldproto,代碼行數:7,代碼來源:ui.go

示例7: Redact

func Redact(r io.Reader) (string, error) {
	doc, err := html.Parse(r)
	if err != nil {
		return "", err
	}
	var f func(*html.Node)
	f = func(n *html.Node) {
		for c := n.FirstChild; c != nil; c = c.NextSibling {
			if c.Type == html.ElementNode {
				switch c.Data {
				case "style", "script", "head", "meta":
					n.RemoveChild(c)
					return
				case "img":
					for i, attr := range c.Attr {
						if attr.Key == "src" {
							c.Attr[i].Key = "data-redacted-src"
						}
					}
				}
			} else if c.Type == html.CommentNode {
				n.RemoveChild(c)
				return
			}
			f(c)
		}
	}
	f(doc)
	buf := bytes.NewBufferString("")
	err = html.Render(buf, doc)
	return buf.String(), err
}
開發者ID:samlecuyer,項目名稱:redactomat,代碼行數:32,代碼來源:redact.go

示例8: renderHtml

func renderHtml(tree *html.Node, t *testing.T) string {
	var wr bytes.Buffer
	if err := html.Render(&wr, tree); err != nil {
		t.Errorf("html rendering error: %s", err.Error())
	}
	return wr.String()

}
開發者ID:rygorous,項目名稱:wp2block,代碼行數:8,代碼來源:shortcode_test.go

示例9: Print

func (p Xpath) Print(w io.Writer, n *html.Node) error {
	node, err := p.Parse(n)
	if err != nil {
		return err
	}
	html.Render(w, node)
	return nil
}
開發者ID:bashtian,項目名稱:htmlparser,代碼行數:8,代碼來源:xpath.go

示例10: html_write_file

func html_write_file(article *html.Node, dir string) (string, error) {
	f, err := ioutil.TempFile(dir, "html.")
	if err != nil {
		return "", err
	}
	defer f.Close()
	err = html.Render(f, article)
	return f.Name(), err
}
開發者ID:heartszhang,項目名稱:famous,代碼行數:9,代碼來源:feedentry_doc.go

示例11: renderHTML

func renderHTML(options Options, file HTMLFile) string {
	handle := must(os.Open(file.File.LocalPath)).(*os.File)
	defer handle.Close()

	doc := must(html.Parse(handle)).(*html.Node)

	var f func(*html.Node)
	f = func(n *html.Node) {
		for c := n.FirstChild; c != nil; c = c.NextSibling {
			f(c)
		}

		if n.Type == html.ElementNode {
			switch n.Data {
			case "script":
				for i, a := range n.Attr {
					if a.Key == "src" {
						for _, dep := range file.Deps {
							if dep.InstPath == a.Val {
								n.Attr[i].Val = formatHref(dep.File.UploadedPath)
								break
							}
						}
					}
				}
			case "link":
				stylesheet := false
				for _, a := range n.Attr {
					if a.Key == "rel" {
						stylesheet = a.Val == "stylesheet"
						break
					}
				}
				if !stylesheet {
					return
				}

				for i, a := range n.Attr {
					if a.Key == "href" {
						for _, dep := range file.Deps {
							if dep.InstPath == a.Val {
								n.Attr[i].Val = formatHref(dep.File.UploadedPath)
								break
							}
						}
					}
				}
			}
		}
	}
	f(doc)

	buf := bytes.NewBuffer([]byte{})
	panicIf(html.Render(buf, doc))

	return buf.String()
}
開發者ID:gdb,項目名稱:Stout,代碼行數:57,代碼來源:deploy.go

示例12: RenderNodes

func RenderNodes(w io.Writer, ns []*html.Node) error {
	for _, n := range ns {
		err := html.Render(w, n)
		if err != nil {
			return err
		}
	}
	return nil
}
開發者ID:jShi-git,項目名稱:goquery_sample,代碼行數:9,代碼來源:h5.go

示例13: WriteHtmlFile2

// write html.Node to tmp file
// return tmp_filename, utf-8 encoded
func WriteHtmlFile2(doc *html.Node) (string, error) {
	of, err := ioutil.TempFile(tmp_dir, prefix)
	if err != nil {
		return "", err
	}
	defer of.Close()

	html.Render(of, doc)
	return of.Name(), nil
}
開發者ID:heartszhang,項目名稱:gextract,代碼行數:12,代碼來源:downloader.go

示例14: write_file

func write_file(doc *html.Node, temp string) (string, error) {
	of, err := ioutil.TempFile(temp, "html.")
	if err != nil {
		return "", err
	}
	defer of.Close()

	html.Render(of, doc)
	return of.Name(), nil
}
開發者ID:heartszhang,項目名稱:famous,代碼行數:10,代碼來源:extract.go

示例15: writeXpaths

func writeXpaths(w io.Writer, doc *html.Node, xpath []string) error {
	for _, p := range xpath {
		c, err := NewXpath(p).Parse(doc)
		if err != nil {
			return err
		}
		html.Render(w, c)
	}
	return nil
}
開發者ID:bashtian,項目名稱:htmlparser,代碼行數:10,代碼來源:parser.go


注:本文中的code/google/com/p/go/net/html.Render函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。