1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-03-19 21:28:32 +02:00
ferret/pkg/stdlib/html/get_inner_html_all.go

39 lines
994 B
Go
Raw Normal View History

package html
import (
"context"
2018-10-14 20:06:27 +03:00
"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"
)
2019-09-07 14:03:17 -04:00
// INNER_HTML_ALL returns an array of inner HTML strings of matched elements.
// @param {HTMLPage | HTMLDocument | HTMLElement} node - Target html node.
// @param {String} selector - String of CSS selector.
// @return {String[]} - An array of inner HTML strings if all matched elements, otherwise empty array.
func GetInnerHTMLAll(ctx context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 2, 2)
if err != nil {
return values.None, err
}
err = core.ValidateType(args[1], types.String)
if err != nil {
return values.None, err
}
el, err := drivers.ToElement(args[0])
if err != nil {
return values.None, err
}
selector := args[1].(values.String)
return el.GetInnerHTMLBySelectorAll(ctx, selector)
}