Skip to content

Commit db8faaa

Browse files
committed
Merge branch 'milestone3m' of https://github.com/solidos/solid-panes into milestone3m
2 parents ac35aac + 657ba09 commit db8faaa

2 files changed

Lines changed: 36 additions & 8 deletions

File tree

jest.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ export default {
1616
'^SolidLogic$': 'solid-logic',
1717
'^UI$': 'solid-ui',
1818
'^\\$rdf$': 'rdflib',
19+
'\\.svg\\?raw$': '<rootDir>/test/__mocks__/fileMock.js',
1920
'\\.(svg)$': '<rootDir>/test/__mocks__/fileMock.js',
21+
'\\.(png|jpe?g|gif|webp|avif)$': '<rootDir>/test/__mocks__/fileMock.js',
2022
'\\.css$': '<rootDir>/test/__mocks__/styleMock.js'
2123
},
2224
setupFilesAfterEnv: ['./test/helpers/setup.ts'],

src/humanReadablePane.js

Lines changed: 34 additions & 8 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)
@@ -175,6 +176,7 @@ const humanReadablePane = {
175176

176177
// @@ When we can, use CSP to turn off scripts within the iframe
177178
div.setAttribute('class', 'docView')
179+
div.setAttribute('style', 'display: block; width: 100%; max-width: 100%; box-sizing: border-box;')
178180

179181
// render markdown to html in a DIV element
180182
const renderMarkdownContent = function (frame) {
@@ -185,26 +187,49 @@ const humanReadablePane = {
185187
const clean = DOMPurify.sanitize(res)
186188
frame.innerHTML = clean
187189
frame.setAttribute('class', 'doc')
188-
frame.setAttribute('style', `border: 1px solid; padding: 1em; height: ${lines}em; max-width: 100%; width: 100%; box-sizing: border-box; resize: both; overflow: auto;`)
190+
frame.setAttribute('style', `display: block; border: 1px solid; padding: 1em; height: ${lines}em; max-width: 100%; width: 100%; box-sizing: border-box; resize: both; overflow: auto;`)
189191
}).catch(error => {
190192
console.error('Error fetching markdown content:', error)
191193
frame.innerHTML = '<p>Error loading content</p>'
192194
})
193195
}
194196

197+
// render plain text in a PRE element
198+
const renderPlainTextContent = function (frame) {
199+
kb.fetcher.webOperation('GET', subject.uri).then(response => {
200+
const plainText = response.responseText
201+
const lines = Math.min(30, plainText.split(/\n/).length + 5)
202+
frame.textContent = plainText
203+
frame.setAttribute('class', 'doc')
204+
frame.setAttribute('style', `display: block; border: 1px solid; padding: 1em; height: ${lines}em; max-width: 100%; width: 100%; box-sizing: border-box; resize: both; overflow: auto; font-family: monospace; white-space: pre-wrap; word-wrap: break-word;`)
205+
}).catch(error => {
206+
console.error('Error fetching plain text content:', error)
207+
frame.textContent = 'Error loading content'
208+
})
209+
}
210+
195211
const setIframeAttributes = (frame, lines) => {
196212
frame.setAttribute('src', subject.uri)
197213
frame.setAttribute('class', 'doc')
198-
frame.setAttribute('style', `border: 1px solid; padding: 1em; height: ${lines}em; max-width: 100%; width: 100%; box-sizing: border-box; resize: both; overflow: auto;`)
214+
frame.setAttribute('style', `display: block; border: 1px solid; padding: 1em; height: ${lines}em; max-width: 100%; width: 100%; box-sizing: border-box; resize: both; overflow: auto;`)
199215
}
200216

201217
if (isMarkdown) {
202218
// For markdown, use a DIV element and render the content
203219
const frame = myDocument.createElement('DIV')
204220
renderMarkdownContent(frame)
205-
const tr = myDocument.createElement('TR')
206-
tr.appendChild(frame)
207-
div.appendChild(tr)
221+
const frameContainer = myDocument.createElement('div')
222+
frameContainer.setAttribute('style', 'display: block; width: 100%; max-width: 100%; box-sizing: border-box;')
223+
frameContainer.appendChild(frame)
224+
div.appendChild(frameContainer)
225+
} else if (isPlainText) {
226+
// For plain text, use a PRE element and render the content
227+
const frame = myDocument.createElement('PRE')
228+
renderPlainTextContent(frame)
229+
const frameContainer = myDocument.createElement('div')
230+
frameContainer.setAttribute('style', 'display: block; width: 100%; max-width: 100%; box-sizing: border-box;')
231+
frameContainer.appendChild(frame)
232+
div.appendChild(frameContainer)
208233
} else {
209234
// For other content types, use IFRAME
210235
const frame = myDocument.createElement('IFRAME')
@@ -232,9 +257,10 @@ const humanReadablePane = {
232257
setIframeAttributes(frame, 30)
233258
})
234259

235-
const tr = myDocument.createElement('TR')
236-
tr.appendChild(frame)
237-
div.appendChild(tr)
260+
const frameContainer = myDocument.createElement('div')
261+
frameContainer.setAttribute('style', 'display: block; width: 100%; max-width: 100%; box-sizing: border-box;')
262+
frameContainer.appendChild(frame)
263+
div.appendChild(frameContainer)
238264
}
239265

240266
return div

0 commit comments

Comments
 (0)