label_parser

package module
v0.0.0-...-da187f6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Name = goparsify.Regex(`[^<>&'"=,]+`)

	Value = goparsify.Until(",").Map(func(r *goparsify.Result) {
		*r = goparsify.Result{
			Result: r.Token,
		}
	})

	ValueParen = goparsify.Seq("'", goparsify.Until("'"), "'").Map(func(r *goparsify.Result) {
		value := r.Child[1]
		*r = goparsify.Result{
			Result: value.Token,
		}
	})

	SingleValue = goparsify.Seq("=", goparsify.Any(ValueParen, Value)).Map(func(r *goparsify.Result) {
		if value, ok := r.Child[1].Result.(string); ok {
			*r = goparsify.Result{
				Result: value,
			}
		}
	})

	Single = goparsify.Seq(Name, goparsify.Maybe(SingleValue)).Map(func(r *goparsify.Result) {
		name := r.Child[0].Token
		maybeValue := r.Child[1]

		if maybeValue.Result == nil {
			*r = goparsify.Result{
				Result: html.UnescapeString(name),
			}
		}

		if val, ok := maybeValue.Result.(string); ok {
			*r = goparsify.Result{
				Result: html.Attribute{
					Key: name,
					Val: html.UnescapeString(val),
				},
			}
		}
	})

	Multiple = goparsify.Some(Single, ",").Map(func(r *goparsify.Result) {
		var attributes []html.Attribute
		var innerText string

		for _, interfaceVal := range r.Child {
			switch interfaceVal.Result.(type) {
			case html.Attribute:
				attributes = append(attributes, interfaceVal.Result.(html.Attribute))
			case string:
				innerText = interfaceVal.Result.(string)
			}
		}

		*r = goparsify.Result{
			Result: TagResult{
				InnerText:  innerText,
				Attributes: attributes,
			},
		}
	})
)

Functions

This section is empty.

Types

type TagResult

type TagResult struct {
	InnerText  string
	Attributes []html.Attribute
}

func ParseTagAttributes

func ParseTagAttributes(input string) (TagResult, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL