Skip to content

Commit

Permalink
Add basic support for rendering code and other preformatted text
Browse files Browse the repository at this point in the history
Works by having a list of file extensions to render.
  • Loading branch information
bloodearnest committed Oct 19, 2023
1 parent a0ff2e3 commit 6f8f355
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 6f8f355

Please sign in to comment.