Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip style elements from snippets for #3146 #3268

Merged
merged 2 commits into from
Aug 22, 2022

Conversation

sylvieed
Copy link
Collaborator

@sylvieed sylvieed commented Aug 19, 2022

Resolves #3146

This uses Nokogiri to remove the style element and its contents from collections' intro_blocks when they're being shown as a snippet on the Find a Project page, because previously the contents of the style element were showing up instead of the collection's description.

With this PR, there is no HTML in the snippet and ampersands show up correctly.

snippet

strip_tags(intro_block) vs. Loofah.fragment(intro_block).text

We were initially using strip_tags to remove HTML tags from the collection's description and shorten it for the Find a Project page. strip_tags automatically removed the style element and its contents, so there was no HTML shown like there is in this issue. However, strip_tags escaped special characters like & to &, which we did not want.
So we switched to Loofah.fragment.text, which gives the option to not encode_special_chars. However, Loofah.fragment.text does not remove the contents of the style element, making this PR necessary.

Changes made

I added a helper function to_snippet(intro_block) that does the following:

  1. Removes the style element and its contents from the intro block
  2. Strips the tags from the intro_block using Loofah.fragment.text
  3. Truncates the intro_block

2 and 3 were previously done in the view, but I moved them to this helper function to consolidate everything into one place, as this sequence is repeated in multiple places in the Find a Project view.

@sylvieed sylvieed linked an issue Aug 19, 2022 that may be closed by this pull request
@benwbrum benwbrum merged commit f711cdb into development Aug 22, 2022
@benwbrum benwbrum deleted the 3146-html-in-findaproject branch December 6, 2022 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

html in find a project carousel
2 participants