Repository navigation
Fix response parsing in HTML viewer - #842
Conversation
✅ Deploy Preview for padp-staging ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for opi-staging ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for marronage-staging ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for pss-scavenger-hunt ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for relnet-staging ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| const text = resp.includes('<tei-text') | ||
| && !resp.toLowerCase().includes('<script') | ||
| && !resp.toLowerCase().includes('<style') | ||
| ? '<tei-text' + resp.split('<tei-text')[1].split('</tei-text>')[0] + '</tei-text>' | ||
| ? '<tei-text' + resp.split(/tei-text[\s>]/)[1].split('</tei-text>')[0] + '</tei-text>' | ||
| : ''; |
There was a problem hiding this comment.
This makes sense and I think it's the right approach generally, but it looks like it's outputting malformed structure now. I'm seeing <tei-text><tei-body> get transformed into <tei-text<tei-body>, at least from local testing of this code on dummy tei.
Two small changes could help:
- Using a lookahead like
(?=[\s>])to check the next character aftertei-textwithout removing it, so the>or space aftertei-textstays in the output - Using the same pattern in both the conditional and the split logic, so the conditional ensures the split doesn't result in an error in cases where they don't line up
Something like:
| const text = resp.includes('<tei-text') | |
| && !resp.toLowerCase().includes('<script') | |
| && !resp.toLowerCase().includes('<style') | |
| ? '<tei-text' + resp.split('<tei-text')[1].split('</tei-text>')[0] + '</tei-text>' | |
| ? '<tei-text' + resp.split(/tei-text[\s>]/)[1].split('</tei-text>')[0] + '</tei-text>' | |
| : ''; | |
| const TEI_TEXT_OPENTAG = /<tei-text(?=[\s>])/; | |
| const text = TEI_TEXT_OPENTAG.test(resp) | |
| && !resp.toLowerCase().includes('<script') | |
| && !resp.toLowerCase().includes('<style') | |
| ? '<tei-text' + resp.split(TEI_TEXT_OPENTAG)[1].split('</tei-text>')[0] + '</tei-text>' | |
| : ''; |
There was a problem hiding this comment.
Oh damn great catches, thanks! Defeated by regular expressions once again...this is why the machines will replace me. But meanwhile I shall make these fixes!
In this PR
Fixes a bug where responses from fetching the TEI to display in the HTML text viewer were being incorrectly truncated; specifically, we had previously just been looking for the first occurrence of
<tei-textto identify the beginning of the text body, but this fails when the document contains e.g.<tei-textClass>elements, observed in some of the JUEL IATH documents. This PR updates it to look for either<tei-text>or<tei-text, which should be more reliable. Tested and working with existing IATH docs that are broken on the current site.