From bc63c9fa3585c3ce60fa663c2442caf5112d30c2 Mon Sep 17 00:00:00 2001 From: Alain Bourgeois Date: Tue, 21 Apr 2026 23:56:29 +0200 Subject: [PATCH] render text/plain --- src/humanReadablePane.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/humanReadablePane.js b/src/humanReadablePane.js index f054c9bb..ed5eebb4 100644 --- a/src/humanReadablePane.js +++ b/src/humanReadablePane.js @@ -166,6 +166,7 @@ const humanReadablePane = { // Fallback: detect markdown by file extension if content-type is not text/markdown const isMarkdown = ct === 'text/markdown' || isMarkdownFile(subject.uri) + const isPlainText = ct === 'text/plain' if (ct) { // console.log('humanReadablePane: c-t:' + ct) @@ -192,6 +193,20 @@ const humanReadablePane = { }) } + // render plain text in a PRE element + const renderPlainTextContent = function (frame) { + kb.fetcher.webOperation('GET', subject.uri).then(response => { + const plainText = response.responseText + const lines = Math.min(30, plainText.split(/\n/).length + 5) + frame.textContent = plainText + frame.setAttribute('class', 'doc') + frame.setAttribute('style', `border: 1px solid; padding: 1em; height: ${lines}em; width: 800px; resize: both; overflow: auto;`) + }).catch(error => { + console.error('Error fetching plain text content:', error) + frame.textContent = 'Error loading content' + }) + } + const setIframeAttributes = (frame, lines) => { frame.setAttribute('src', subject.uri) frame.setAttribute('class', 'doc') @@ -205,6 +220,13 @@ const humanReadablePane = { const tr = myDocument.createElement('TR') tr.appendChild(frame) div.appendChild(tr) + } else if (isPlainText) { + // For plain text, use a PRE element and render the content + const frame = myDocument.createElement('PRE') + renderPlainTextContent(frame) + const tr = myDocument.createElement('TR') + tr.appendChild(frame) + div.appendChild(tr) } else { // For other content types, use IFRAME const frame = myDocument.createElement('IFRAME')