Skip to content

Commit 4ce7b63

Browse files
authored
Merge pull request #621 from SolidOS/fix/issue#619
render text/plain
2 parents d932380 + bc63c9f commit 4ce7b63

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/humanReadablePane.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ const humanReadablePane = {
166166

167167
// Fallback: detect markdown by file extension if content-type is not text/markdown
168168
const isMarkdown = ct === 'text/markdown' || isMarkdownFile(subject.uri)
169+
const isPlainText = ct === 'text/plain'
169170

170171
if (ct) {
171172
// console.log('humanReadablePane: c-t:' + ct)
@@ -192,6 +193,20 @@ const humanReadablePane = {
192193
})
193194
}
194195

196+
// render plain text in a PRE element
197+
const renderPlainTextContent = function (frame) {
198+
kb.fetcher.webOperation('GET', subject.uri).then(response => {
199+
const plainText = response.responseText
200+
const lines = Math.min(30, plainText.split(/\n/).length + 5)
201+
frame.textContent = plainText
202+
frame.setAttribute('class', 'doc')
203+
frame.setAttribute('style', `border: 1px solid; padding: 1em; height: ${lines}em; width: 800px; resize: both; overflow: auto;`)
204+
}).catch(error => {
205+
console.error('Error fetching plain text content:', error)
206+
frame.textContent = 'Error loading content'
207+
})
208+
}
209+
195210
const setIframeAttributes = (frame, lines) => {
196211
frame.setAttribute('src', subject.uri)
197212
frame.setAttribute('class', 'doc')
@@ -205,6 +220,13 @@ const humanReadablePane = {
205220
const tr = myDocument.createElement('TR')
206221
tr.appendChild(frame)
207222
div.appendChild(tr)
223+
} else if (isPlainText) {
224+
// For plain text, use a PRE element and render the content
225+
const frame = myDocument.createElement('PRE')
226+
renderPlainTextContent(frame)
227+
const tr = myDocument.createElement('TR')
228+
tr.appendChild(frame)
229+
div.appendChild(tr)
208230
} else {
209231
// For other content types, use IFRAME
210232
const frame = myDocument.createElement('IFRAME')

0 commit comments

Comments
 (0)