adds markdown support, fix code wrapping

This commit is contained in:
Daniel Avila 2023-02-24 11:24:09 -05:00
parent c58a9bbe93
commit fd01fd3334
9 changed files with 1545 additions and 115 deletions

View file

@ -3,4 +3,42 @@ import { twMerge } from 'tailwind-merge';
export function cn(...inputs) {
return twMerge(clsx(inputs));
}
}
export const languages = [
'java',
'c',
'markdown',
'css',
'html',
'xml',
'bash',
'json',
'yaml',
'jsx',
'python',
'c++',
'javascript',
'csharp',
'php',
'typescript',
'swift',
'objectivec',
'sql',
'r',
'kotlin',
'ruby',
'go',
'x86asm',
'matlab',
'perl',
'pascal'
];
export const wrapperRegex = {
codeRegex: /(```[\s\S]*?```)/g,
inLineRegex: /(`[^`]+?`)/g,
matchRegex: /(`[^`]+?`)/g,
languageMatch: /^```(\w+)/,
newLineMatch: /^```(\n+)/
};

View file

@ -1,4 +1,3 @@
// const string = 'Some text before\n```python\nThis is some `Python` code with ```backticks``` inside the enclosure\n```\nSome text after\n```javascript\nThis is some JavaScript code\n```\n';
const regex = /```([^`\n]*?)\n([\s\S]*?)\n```/g;
export default function regexSplit(string) {
@ -8,8 +7,7 @@ export default function regexSplit(string) {
for (let i = 0; i < matches.length; i++) {
const [fullMatch, language, code] = matches[i];
// const formattedCode = code.replace(/`+/g, '\\`');
const formattedCode = code;
output.push(`\`\`\`${language}\n${formattedCode}\n\`\`\``);
output.push(`\`\`\`${language}\n${code}\n\`\`\``);
if (i < matches.length - 1) {
const nextText = string.slice(matches[i].index + fullMatch.length, matches[i + 1].index);
output.push(nextText.trim());