Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic support for rendering code and other preformatted text #240

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code comment is now out of date, as it's no longer just checking for ".txt"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

* @param {string} ext - file extension
* @returns {boolean}
*/
export function isTxt(ext) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be tempted to rename the function as isText to make it clearer that it's not just checking for a .txt extension.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, will do

return ext.toLowerCase() === "txt";
return TEXT_TYPES.includes(ext.toLowerCase());
}

/**
Expand Down