Skip to content

Commit

Permalink
Merge pull request #240 from opensafely-core/code
Browse files Browse the repository at this point in the history
Add basic support for rendering code and other preformatted text
  • Loading branch information
bloodearnest committed Oct 24, 2023
2 parents a0ff2e3 + 6f8f355 commit 28b27d7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion assets/src/scripts/_file-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function createTextElement(el, ext, url) {
const data = await fileLoader(ext, url);

const textEl = document.createElement("pre");
textEl.classList.add("break-words", "text-sm", "whitespace-pre-line");
textEl.classList.add("break-words", "text-sm");
textEl.innerText = data;

el.appendChild(textEl);
Expand Down
3 changes: 2 additions & 1 deletion assets/src/scripts/_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ export const isCsv = (ext) => ext.toLowerCase() === "csv";
export const isImg = (ext) =>
["gif", "jpg", "jpeg", "png", "svg"].includes(ext.toLowerCase());

export const TEXT_TYPES = ["txt", "md", "py", "yaml", "R", "log"];
/**
* Confirm if file is .txt
* @param {string} ext - file extension
* @returns {boolean}
*/
export function isTxt(ext) {
return ext.toLowerCase() === "txt";
return TEXT_TYPES.includes(ext.toLowerCase());
}

/**
Expand Down

0 comments on commit 28b27d7

Please sign in to comment.