From 6f8f355c36ac2790a1bc0b7f9b31cd8c15a56338 Mon Sep 17 00:00:00 2001 From: Simon Davy Date: Wed, 18 Oct 2023 12:42:33 +0100 Subject: [PATCH] Add basic support for rendering code and other preformatted text Works by having a list of file extensions to render. --- assets/src/scripts/_file-elements.js | 2 +- assets/src/scripts/_utils.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/assets/src/scripts/_file-elements.js b/assets/src/scripts/_file-elements.js index 4d9bdbab..946a205b 100644 --- a/assets/src/scripts/_file-elements.js +++ b/assets/src/scripts/_file-elements.js @@ -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); diff --git a/assets/src/scripts/_utils.js b/assets/src/scripts/_utils.js index 16087ff8..afc6f9c6 100644 --- a/assets/src/scripts/_utils.js +++ b/assets/src/scripts/_utils.js @@ -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()); } /**