Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add extension to the snippet to help rendering with highlights
  • Loading branch information
ACR1209 committed Jan 16, 2025
commit 29f8cc65d81bca75689d3453706d32042e9c607a
7 changes: 1 addition & 6 deletions src/components/SnippetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import { SnippetType } from "@types";
import { LeftAngleArrowIcon } from "./Icons";
import SnippetModal from "./SnippetModal";

const extensions: { [key: string]: string } = {
REACT: "tsx",
FASTAPI: "py",
};

const SnippetList = () => {
const { language, snippet, setSnippet } = useAppContext();
const { fetchedSnippets } = useSnippets();
Expand Down Expand Up @@ -92,7 +87,7 @@ const SnippetList = () => {
<SnippetModal
snippet={snippet}
handleCloseModal={handleCloseModal}
language={extensions[language.name] || language.name}
language={snippet.extension}
/>
)}
</AnimatePresence>
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type SnippetType = {
code: string;
tags: string[];
author: string;
extension: string;
};

export type AppState = {
Expand Down
2 changes: 2 additions & 0 deletions utils/snippetParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function parseSnippet(path, name, text) {
match = headerEndCodeStartRegex.exec(fromCursor());
if(match === null) return raise('Missing header end \'---\' or code start \'```\'', path);
cursor += match[0].length;
const extension = match[0].replace(/[\r\n`-]/g, '');

match = codeRegex.exec(fromCursor());
if(match === null) return raise('Missing code block end \'```\'', path);
Expand All @@ -67,6 +68,7 @@ function parseSnippet(path, name, text) {
tags: properties.tags.split(',').map((tag) => tag.trim()).filter((tag) => tag),
contributors: 'contributors' in properties ? properties.contributors.split(',').map((contributor) => contributor.trim()).filter((contributor) => contributor) : [],
code: code.replace(/\r\n/g, '\n'),
extension
}
}

Expand Down