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


Golang Node.Content方法代碼示例

本文整理匯總了Golang中github.com/moovweb/gokogiri/xml.Node.Content方法的典型用法代碼示例。如果您正苦於以下問題:Golang Node.Content方法的具體用法?Golang Node.Content怎麽用?Golang Node.Content使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/moovweb/gokogiri/xml.Node的用法示例。


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

示例1: writeCodeBlock

// Writes code blocks to the buffer.
func (self *Formatter) writeCodeBlock(node xml.Node) {
	block := []byte(strings.Trim(node.Content(), "\n\r\v"))
	node.SetContent("")

	if len(block) == 0 {
		return
	}
	self.buf.Write(block)
	self.buf.Write([]byte{'\n', '\n'})
}
開發者ID:ushis,項目名稱:textmail,代碼行數:11,代碼來源:textmail.go

示例2: linkDensity

func linkDensity(node xml.Node) float64 {
	links, err := node.Search("a")
	if err != nil {
		return 0.0
	}

	llength := 0.0
	for _, link := range links {
		llength += float64(len(link.Content()))
	}
	tlength := float64(len(node.Content()))
	return llength / tlength
}
開發者ID:oxmcvusd,項目名稱:readability-1,代碼行數:13,代碼來源:util.go

示例3: writeBlock

// Writes text blocks to the buffer.
func (self *Formatter) writeBlock(node xml.Node, prefix string) {
	block := []byte(strings.TrimSpace(node.Content()))
	node.SetContent("")

	if len(block) == 0 {
		return
	}
	// Position of last space, line break and max length.
	sp, br, max := 0, 0, 79-len(prefix)
	self.buf.WriteString(prefix)

	for i, c := range block {
		// Break line if exceeded max length and the position of the last space
		// is greater than the position of the last line break. Don't break very
		// long words.
		if i-br > max && sp > br {
			self.buf.WriteByte('\n')
			br = sp
			// Only the first line is prefixed.
			for j := 0; j < len(prefix); j++ {
				self.buf.WriteByte(' ')
			}
		}
		if whitespace[c] {
			// The last character was a space, so ignore this one.
			if sp == i {
				sp++
				br++
				continue
			}
			// Write the last word to the buffer, append a space and update
			// the position of the last space.
			if sp > br {
				self.buf.WriteByte(' ')
			}
			self.buf.Write(block[sp:i])
			sp = i + 1
		}
	}

	// Write the last word to the buffer.
	if sp < len(block) {
		if sp > br {
			self.buf.WriteByte(' ')
		}
		self.buf.Write(block[sp:])
	}

	// Close block with 2 breaks.
	self.buf.Write([]byte{'\n', '\n'})
}
開發者ID:ushis,項目名稱:textmail,代碼行數:52,代碼來源:textmail.go

示例4: parseAppDiv

// parseAppDiv extracts timestamp and blockindex from an appointment div
func parseAppDiv(div xml.Node) (timestamp int64, blockIndex string, err error) {

	idValues := idBlockPattern.FindStringSubmatch(div.Attr("id"))
	timestamp, err = strconv.ParseInt(idValues[1], 10, 64)
	if err != nil {
		return
	}

	blockIndexValues := blockIndexPattern.FindStringSubmatch(div.Content())
	if len(blockIndexValues) == 1 {
		blockIndex = blockIndexValues[0]
	}
	return
}
開發者ID:allonhadaya,項目名稱:boa,代碼行數:15,代碼來源:block.go

示例5: ProcessField

// ProcessField method fetches data from passed document
func (f *Field) ProcessField(d *html.HtmlDocument) interface{} {
	var value interface{}
	var node xml.Node
	selector := xpath.Compile(f.Selector)
	result, _ := d.Root().Search(selector)

	if len(result) > 0 {
		node = result[0]
	} else {
		return ""
	}

	if f.Callback != nil {
		value = f.Callback(&node)
	} else {
		value = node.Content()
	}

	return value
}
開發者ID:Alkemic,項目名稱:goscraper,代碼行數:21,代碼來源:scrape.go

示例6: handleNode

// Formats the content of inline elements and writes the content of block
// elements to the buffer.
func (self *Formatter) handleNode(node xml.Node) {
	name := node.Name()

	switch {
	case ignore[name]:
		// Remove ignored elements.
		node.SetContent("")
	case name == "pre":
		// Treat pre elements as code blocks.
		self.writeCodeBlock(node)
	case heading[name]:
		// Headings are prefixed with "# ".
		self.writeBlock(node, "# ")
	case name == "li":
		// List items are prefixed with "- ".
		self.writeBlock(node, "- ")
	case name == "br":
		// Preserve explicit line breaks.
		node.SetContent("\n")
	case italic[name]:
		// Wrap italic elements with /.
		node.SetContent("/" + node.Content() + "/")
	case bold[name]:
		// Wrap bold elements with *.
		node.SetContent("*" + node.Content() + "*")
	case name == "img":
		// Collect the src of images and replace them with (alt)[url index]
		alt, src := node.Attr("alt"), node.Attr("src")

		if len(alt) > 0 && len(src) > 0 {
			node.SetContent(fmt.Sprintf("(%s)[%d]", alt, len(self.links)))
			self.links = append(self.links, src)
		}
	case name == "a":
		// Collect the href and and the url index.
		href, content := node.Attr("href"), node.Content()

		if len(href) > 0 && len(content) > 0 {
			node.SetContent(fmt.Sprintf("%s[%d]", content, len(self.links)))
			self.links = append(self.links, href)
		}
	case block[name]:
		// Write the content of block elements to the buffer.
		self.writeBlock(node, "")
	}
}
開發者ID:ushis,項目名稱:textmail,代碼行數:48,代碼來源:textmail.go

示例7: unmarshal

func (p *Decoder) unmarshal(val reflect.Value, start gokoxml.Node) error {
	// Find first xml node.
	if start == nil {
		start = p.doc.Root().XmlNode
	}

	// Unpacks a pointer
	if pv := val; pv.Kind() == reflect.Ptr {
		if pv.IsNil() {
			pv.Set(reflect.New(pv.Type().Elem()))
		}
		val = pv.Elem()
	}

	var (
		sv    reflect.Value
		tinfo *typeInfo
		err   error
	)

	switch v := val; v.Kind() {
	default:
		return errors.New("unknown type " + v.Type().String())

		// TODO: Implement this once i understand Skip()
		// case reflect.Interface:
		// 	return p.Skip()

	case reflect.Slice:
		typ := v.Type()
		if typ.Elem().Kind() == reflect.Uint8 {
			// []byte
			if err := copyValue(v, start.Content()); err != nil {
				return err
			}
			break
		}

		// Slice of element values.
		// Grow slice.
		n := v.Len()
		if n >= v.Cap() {
			ncap := 2 * n
			if ncap < 4 {
				ncap = 4
			}
			new := reflect.MakeSlice(typ, n, ncap)
			reflect.Copy(new, v)
			v.Set(new)
		}
		v.SetLen(n + 1)

		// Recur to read element into slice.
		if err := p.unmarshal(v.Index(n), start); err != nil {
			v.SetLen(n)
			return err
		}
		return nil

	case reflect.Bool, reflect.Float32, reflect.Float64, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, reflect.String:
		if err := copyValue(v, start.Content()); err != nil {
			return err
		}

	case reflect.Struct:
		typ := v.Type()
		if typ == nameType {
			v.Set(reflect.ValueOf(xml.Name{Local: start.Name()}))
			break
		}
		if typ == timeType {
			if err := copyValue(v, start.Content()); err != nil {
				return err
			}
			break
		}

		sv = v
		tinfo, err = getTypeInfo(typ)
		if err != nil {
			return err
		}

		// Validate and assign element name.
		if tinfo.xmlname != nil {
			// var space string
			finfo := tinfo.xmlname
			if finfo.name != "" && finfo.name != start.Name() {
				return UnmarshalError("expected element type <" + finfo.name + "> but have <" + start.Name() + ">")
			}

			fv := sv.FieldByIndex(finfo.idx)
			if _, ok := fv.Interface().(xml.Name); ok {
				fv.Set(reflect.ValueOf(xml.Name{Local: start.Name()}))
			}
		}

		var saveComment reflect.Value
		var doSaveComment = false
		_ = saveComment
//.........這裏部分代碼省略.........
開發者ID:pcdummy,項目名稱:golxml,代碼行數:101,代碼來源:xml.go


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