Skip to content

Add new GREL jsoup function "data()" to support HTML <script> and <style> tag data extraction #4189

@thadguidry

Description

@thadguidry

Data does not only exist in HTML or XML TextNode's but also in <script> and <style> nodes.
Useful JSON data is also sometimes contained in <script type="application/json"> as well as JSON-LD data in <script type="application/ld+json">
Jsoup provides a different method data() for working with Elements that are a DataNode for handling the contents of style, script tags etc, where contents of those tags do not show with TextNode's text() - our GREL htmlText()

Proposed solution

  1. Add support for jsoup's data() functionality for Element's as defined at https://jsoup.org/apidocs/org/jsoup/nodes/Element.html#data()
  2. data() will operate similarly to our existing htmlText() for TextNode's but instead work with DataNodes

Alternatives considered

Manually parsing based on root element and splitting the entire document as a single string

Additional context

  1. Example tests of data() are here.
  2. :containsData() is already available currently from within our GREL select() function.
  3. parseJson() should be immediately applicable to parse the JSON data string.
    Ex. value.parseHtml().select("script")[2].data().parseJson().sitecore.context

Metadata

Metadata

Assignees

Labels

Type: Feature RequestIdentifies requests for new features or enhancements. These involve proposing new improvements.grelThe default expression language, GREL, could be improved in many ways!

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions