mirror of
https://github.com/MontFerret/ferret.git
synced 2024-12-14 11:23:02 +02:00
1af8b37a0f
* New type system * Fixed dot notation for HTML elements
39 lines
864 B
Go
39 lines
864 B
Go
package html
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/MontFerret/ferret/pkg/drivers"
|
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
|
"github.com/MontFerret/ferret/pkg/runtime/values/types"
|
|
)
|
|
|
|
// Parse parses a given HTML string and returns a HTML document.
|
|
// 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], types.String)
|
|
|
|
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)
|
|
}
|