question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lists in json source cause HTML problems with `<p>` wrapping

See original GitHub issue

Where to find the issue

Pages on https://www.coronawarn.app/ generated from json source containing lists <ul> or <ol>.

Describe the issue

When a <ul> (unordered list) or an <ol> (ordered list) is included in a json source file for the cwa-website, the default conversion to html wraps the list in paragraph <p> ... </p> tags which makes it invalid HTML.

See for instance https://stackoverflow.com/questions/7168723/unordered-list-in-a-paragraph-element. A paragraph <p> is allowed to contain phrasing content. <ul> and <ol> do not belong to the category of phrasing content.

Steps to reproduce

Run https://validator.w3.org on https://www.coronawarn.app/en/ and note error:

  • “No p element in scope but a p end tag seen”

This is due to the following source. I have added new lines for readability:

<p>
<ol>
<li>Download the current version of the app (iOS: 2.28.0 or Android: 2.28.3)</li><li>Keep operating systems up-to-date (at least iOS 12.5 or iOS 13.5 depending on your iPhone model or at least Android 6 with current Google Play services)</li>
<li><a href='faq/results/#background_updates'>Keep background updates switched on and check them regularly</a></li>
<li>To be on the safe side, open the app once a day</li>
</ol>
</p>

This is a simple example from the main page. More importantly it is also a problem in the FAQs on https://www.coronawarn.app/en/faq/results/.

Analysis

In the example, the source link is from:

https://github.com/corona-warn-app/cwa-website/blob/4157d4b0b2cd1b4780ae3eeb9982f5eec6939e62/src/data/index.json#L46-L48

which is processed by the following and this wraps the list incorrectly in <p> ... </p>

https://github.com/corona-warn-app/cwa-website/blob/4157d4b0b2cd1b4780ae3eeb9982f5eec6939e62/src/partials/text-component.html#L12-L14

Suggestion

Some way needs to be found to prevent lists in the middle of textblocks being wrapped in <p> ... </p> so that the generated HTML is correct.

A special case (linkList) was already implemented for lists of internal URLs in FAQs. See https://github.com/corona-warn-app/cwa-website/blob/4157d4b0b2cd1b4780ae3eeb9982f5eec6939e62/src/partials/page-faq-results.html#L95-L106

Perhaps this could be made more generic?


Internal Tracking ID: EXPOSUREAPP-14392

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
brianebelingcommented, Dec 8, 2022

After a review of this issue it seems unlikely that it causes unwanted behaviour, considering there are other places where there is no visible change, but with the structure we want and also a small test showed no difference in Chrome. That was not on the full scale of this issue though.

This might turn out to be a bit time consuming, we will keep it on the backlog till the priorities are a bit clearer as its not breaking any functionality. Pull Requests are welcome of course.

1reaction
brianebelingcommented, Dec 8, 2022

I think this is actually an issue. We should try to keep the relevant information here, so you don’t have to search for it. Something more generic like “Which HTML issues should we prioritize” would be a good topic for a discussion. In this case we have something specific that is actionable though, so relevant information should also go here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

4 Things You Must Do When Putting HTML in JSON
There are 4 things you must do when putting HTML in JSON data structures. ... a number, a boolean, an object, an array,...
Read more >
How do I handle newlines in JSON? - Stack Overflow
+ 1. I was having trouble understanding JSON-encoding but "will become a newline in the JSON source, not the JSON data" made it...
Read more >
What Is JSON and How to Handle an “Unexpected Token” Error
To ensure the error happens on the exact line we think it does, we can wrap the JSON parsing code in a try-catch...
Read more >
JSONP - W3Schools
JSONP stands for JSON with Padding. Requesting a file from another domain can cause problems, due to cross-domain policy. Requesting an external script...
Read more >
Understanding JSON Schema
JSON Schema is a powerful tool for validating the structure of JSON data. However, learning to use it by reading its.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found