1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-25 01:32:13 +02:00
ferret/pkg/stdlib/html/parse.go

38 lines
810 B
Go
Raw Normal View History

package html
import (
"context"
2018-10-14 19:06:27 +02:00
"github.com/MontFerret/ferret/pkg/drivers"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
)
// Parse parses a given HTML string and returns a HTML document.
2018-10-14 19:06:27 +02:00
// Returned HTML document is always static.
// @param html (String) - Target HTML string.
// @returns (HTMLDocument) - Parsed HTML static document.
func Parse(ctx context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 1, 1)
if err != nil {
return values.None, err
}
err = core.ValidateType(args[0], core.StringType)
if err != nil {
return values.None, err
}
drv, err := drivers.StaticFrom(ctx)
if err != nil {
return values.None, err
}
str := args[0].(values.String)
return drv.ParseDocument(ctx, str)
}