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 18, 2023
1 parent 2f244cd commit d00a7ab
Show file tree
Hide file tree
Showing 2 changed files with 10 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
10 changes: 9 additions & 1 deletion assets/src/scripts/_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@ export const isCsv = (ext) => ext.toLowerCase() === "csv";
export const isImg = (ext) =>
["gif", "jpg", "jpeg", "png", "svg"].includes(ext.toLowerCase());

export const TEXT_TYPES = [

Check failure on line 14 in assets/src/scripts/_utils.js

View workflow job for this annotation

GitHub Actions / check

Replace `⏎··"txt",⏎··"md",⏎··"py",⏎··"yaml",⏎··"R",⏎··"log",⏎]` with `"txt",·"md",·"py",·"yaml",·"R",·"log"];`
"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 d00a7ab

Please sign in to comment.