2018-10-07 04:33:39 +02:00
|
|
|
package html
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2018-10-14 19:06:27 +02:00
|
|
|
|
2018-12-22 06:14:41 +02:00
|
|
|
"github.com/MontFerret/ferret/pkg/drivers"
|
2018-10-07 04:33:39 +02:00
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
|
|
|
)
|
|
|
|
|
2018-12-22 06:14:41 +02:00
|
|
|
// 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.
|
2018-12-22 06:14:41 +02:00
|
|
|
func Parse(ctx context.Context, args ...core.Value) (core.Value, error) {
|
2018-10-07 04:33:39 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-12-22 06:14:41 +02:00
|
|
|
drv, err := drivers.StaticFrom(ctx)
|
2018-10-07 04:33:39 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return values.None, err
|
|
|
|
}
|
|
|
|
|
|
|
|
str := args[0].(values.String)
|
|
|
|
|
2018-12-22 06:14:41 +02:00
|
|
|
return drv.ParseDocument(ctx, str)
|
2018-10-07 04:33:39 +02:00
|
|
|
}
|