-
Notifications
You must be signed in to change notification settings - Fork 17
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
Handle nested divs in first_item_content #3348
base: main
Are you sure you want to change the base?
Conversation
Amended the first_item_content method so that it accounts for nested div elements and processes their child elements, so that there is sufficient content to consider rendering a list.
e0ba271
to
07c7fd6
Compare
|
||
until element.name == "h2" | ||
first_item_text += element.text if element.name.in?(allowed_elements) | ||
allowed_elements = %w[p ul ol div] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
div
is checked separately in line 53, so adding it here doesn't change anything and is confusing, so it can be removed from this line. So line 55 can be also changed to not exclude it.
|
||
until element.nil? || element.name == "h2" | ||
if element.name == "div" | ||
element.children.each do |child| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first part of if
only checks a single level of divs, so it won't find paragraphs inside nested divs e.g.:
<div>
<div>
<div>
<p>
text...
</p>
</div>
</div>
</div>
It might solve the immediate problem with the particular document, but the problem will reappear when someone adds a document with more deeply nested divs.
If we want to find all nested paragraphs, a recursive solution would work, but is it what we want to do in the first place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that makes sense - I'll change this so I look for more deeply nested divs as like you said I only considered the first level 😅
What
Trello card
This PR addresses an issue where the content list was not displayed on some publication pages due to the way nested content elements were handled in the
show_contents_list?
method.Context:
The
show_contents_list?
method includes several conditions to determine whether a content list should display. These rules were introduced in PR #719.Recently, a Zendesk ticket highlighted an issue on the DVSA Earned Recognition page, where the content list was missing, leaving an empty block of space on the left of the publication.
Debugging:
However, this is not accurate, because the content includes several
h2s
andh3s
:h2
section for "Driver system providers"h3
subsections like "A", "B", and "C", each containingp
elements with contact details, all wrapped insidediv
tags.The content in these sections was not being picked up by the method due to the nesting inside
div
elements. As a result, the condition inshow_contents_list?
were returning false, leading to the missing content list.Solution:
I updated the
first_item_content
method incontents_list.rb
to handle elements nested withindiv
tags. This ensures that valid elements (p
,ul
,ol
) insidedivs
are now considered when determining whether to display the content list.Tests:
I also added two test cases to ensure this functionality works as expected:
div
elements.divs
.Testing:
The page now correctly renders the content list:
Why
Without this fix, pages with only two content items and no long content could fail to render the content list, leaving an empty whitespace that negatively impacts user experience.
Visual Changes
Follow these steps if you are doing a Rails upgrade.