mirror of
https://github.com/MontFerret/ferret.git
synced 2025-07-03 00:46:51 +02:00
Refactoring/externalized html (#234)
* Externalized HTML drivers * Fixed unit tests * Updated logging * Added support to set default driver * Updated GetIn and SetIn helpers
This commit is contained in:
@ -1,38 +0,0 @@
|
||||
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)
|
||||
}
|
Reference in New Issue
Block a user