[add] Add core implementation.

This commit is contained in:
naive231 2024-11-15 09:00:48 +08:00
parent 487c0f6736
commit 6789f574b8
1 changed files with 14 additions and 8 deletions

22
main.ts
View File

@ -147,15 +147,21 @@ function processLineBlock(source: string): string {
} }
function applyFormatting(text: string): string { function applyFormatting(text: string): string {
// Replace **bold** with *bold* (with spaces) if (text.includes('**')) {
text = text.replace(/\*\*(.*?)\*\*/g, ' *$1* '); // Replace **bold** with *bold* (with spaces)
// Replace *italic* with _italic_ text = text.replace(/\*\*(.*?)\*\*/g, ' *$1* ');
text = text.replace(/(?<!\*)\*(?!\*)(.*?)\*(?!\*)/g, ' _$1_ '); } else if (text.includes('*')) {
// Replace *italic* with _italic_
text = text.replace(/(?<!\*)\*(?!\*)(.*?)\*(?!\*)/g, ' _$1_ ');
}
// Replace ~~strike~~ with ~strike~ // Replace ~~strike~~ with ~strike~
text = text.replace(/~~(.*?)~~/g, ' ~$1~ '); text = text.replace(/~~(.*?)~~/g, ' ~$1~ ');
// Replace ==emphasize== with `emphasize` if (text.includes('==')) {
text = text.replace(/==(.*?)==/g, ' `$1` '); // Replace ==emphasize== with `emphasize`
// Replace `quote` with {quote} text = text.replace(/==(.*?)==/g, ' `$1` ');
text = text.replace(/`(.*?)`/g, ' {$1} '); } else if (text.includes('`')) {
// Replace `quote` with {quote}
text = text.replace(/`(.*?)`/g, ' {$1} ');
}
return text; return text;
} }