Problem/Motivation

This is a follow-up of #2874641: Select Text Format in Views Field for textual content with values from search index and is described in this comment: https://www.drupal.org/project/search_api/issues/2874641#comment-12305025
There are cases where entities contain markup that should never be displayed such as <script> tags used to include microdata. When rendering excerpts of search results, is converted to plain text. The contents of <script> tags are not removed and end up as plain text in the search results.

Proposed resolution

Provide an option in the views field to strip certain HTML tags completely from the search result excerpt.

Remaining tasks

TBD

User interface changes

TBD

API changes

TBD

Data model changes

TBD

Comments

Lukas von Blarer created an issue. See original summary.

drunken monkey’s picture

Are you sure the conversion to plain text only happens in the Views plugin, on output? I think that normally already occurs when the excerpt is created. Therefore, that would probably be the right moment to remove such elements’ contents.
If it’s just about <script> tags (and maybe <style> and a few others), I think we could just add this without any configuration. It seems doubtful anyone (or, more than a handful of people) would ever actually want those elements’ contents in an excerpt.
But if you also want this functionality for other tags, we’d have to add a config option for this as well.

borisson_’s picture

If it’s just about

tags (and maybe and a few others), I think we could just add this without any configuration. It seems doubtful anyone (or, more than a handful of people) would ever actually want those elements’ contents in an excerpt.
I think this would be a great start. Hoping to pass this on to someone at drupalcon.
andrewsizz’s picture

ok, we start working on this!

andrewsizz’s picture

Ok I had possibility to reproduce an issue with Search: Excerpt in views.
Attached patch which fix an issue, so in patch we remove

tags with its content
andrewsizz’s picture

Status: Active » Needs review
drunken monkey’s picture

Thanks a lot, looks good!
However, I think we can be more concise and do this with a single regexp. (Also, please no blank line at the start of the method body!)

Finally, this still needed test coverage, which I’ve also added. Patch attached, please test/review!

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

Looks great!

andrewsizz’s picture

For me also works!

drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

Excellent, thanks a lot for testing/reviewing!
Committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.