Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/humanReadablePane.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,12 @@

// 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)
} else {
console.log('humanReadablePane: unknown content-type?')

Check warning on line 174 in src/humanReadablePane.js

View workflow job for this annotation

GitHub Actions / build (24)

Unexpected console statement

Check warning on line 174 in src/humanReadablePane.js

View workflow job for this annotation

GitHub Actions / build (22)

Unexpected console statement
}

// @@ When we can, use CSP to turn off scripts within the iframe
Expand All @@ -187,11 +188,25 @@
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 markdown content:', error)

Check warning on line 191 in src/humanReadablePane.js

View workflow job for this annotation

GitHub Actions / build (24)

Unexpected console statement

Check warning on line 191 in src/humanReadablePane.js

View workflow job for this annotation

GitHub Actions / build (22)

Unexpected console statement
frame.innerHTML = '<p>Error loading content</p>'
})
}

// 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')
Expand All @@ -205,6 +220,13 @@
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')
Expand Down
Loading