Skip to content

Fix response parsing in HTML viewer - #842

Merged
ajolipa merged 2 commits into
developfrom
rb/html-viewer-fix
Nov 12, 2026
Merged

ajolipa merged 2 commits into
developfrom
rb/html-viewer-fix

Conversation

@ajolipa

@ajolipa ajolipa commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

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-text to 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.

@netlify

netlify Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for padp-staging ready!

Name Link
🔨 Latest commit 5f50e35
🔍 Latest deploy log https://app.netlify.com/projects/padp-staging/deploys/6af616f52dd14e9d3022ab55
😎 Deploy Preview https://deploy-preview-842--padp-staging.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for opi-staging ready!

Name Link
🔨 Latest commit 5f50e35
🔍 Latest deploy log https://app.netlify.com/projects/opi-staging/deploys/6af616f52e5b71f32721049f
😎 Deploy Preview https://deploy-preview-842--opi-staging.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for marronage-staging ready!

Name Link
🔨 Latest commit 5f50e35
🔍 Latest deploy log https://app.netlify.com/projects/marronage-staging/deploys/6af616f5d886ac3d95a33a1d
😎 Deploy Preview https://deploy-preview-842--marronage-staging.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for pss-scavenger-hunt ready!

Name Link
🔨 Latest commit 5f50e35
🔍 Latest deploy log https://app.netlify.com/projects/pss-scavenger-hunt/deploys/6af616f4849f6b0bde61ef22
😎 Deploy Preview https://deploy-preview-842--pss-scavenger-hunt.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for relnet-staging ready!

Name Link
🔨 Latest commit 5f50e35
🔍 Latest deploy log https://app.netlify.com/projects/relnet-staging/deploys/6af616f535044d30ff9093c6
😎 Deploy Preview https://deploy-preview-842--relnet-staging.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@ajolipa
ajolipa requested review from blms and camdendotlol November 12, 2026 16:58
Comment thread src/apps/detailPages/HtmlViewer.astro Outdated
Comment on lines 14 to 18
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>'
: '';

@blms blms Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 after tei-text without removing it, so the > or space after tei-text stays 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:

Suggested change
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>'
: '';

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@ajolipa
ajolipa requested a review from blms November 12, 2026 19:44

@blms blms left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@ajolipa
ajolipa merged commit 7bf274a into develop Nov 12, 2026
24 checks passed
@ajolipa
ajolipa deleted the rb/html-viewer-fix branch November 12, 2026 20:50
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.

3 participants