[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 {
// Replace **bold** with *bold* (with spaces)
text = text.replace(/\*\*(.*?)\*\*/g, ' *$1* ');
// Replace *italic* with _italic_
text = text.replace(/(?<!\*)\*(?!\*)(.*?)\*(?!\*)/g, ' _$1_ ');
if (text.includes('**')) {
// Replace **bold** with *bold* (with spaces)
text = text.replace(/\*\*(.*?)\*\*/g, ' *$1* ');
} else if (text.includes('*')) {
// Replace *italic* with _italic_
text = text.replace(/(?<!\*)\*(?!\*)(.*?)\*(?!\*)/g, ' _$1_ ');
}
// Replace ~~strike~~ with ~strike~
text = text.replace(/~~(.*?)~~/g, ' ~$1~ ');
// Replace ==emphasize== with `emphasize`
text = text.replace(/==(.*?)==/g, ' `$1` ');
// Replace `quote` with {quote}
text = text.replace(/`(.*?)`/g, ' {$1} ');
if (text.includes('==')) {
// Replace ==emphasize== with `emphasize`
text = text.replace(/==(.*?)==/g, ' `$1` ');
} else if (text.includes('`')) {
// Replace `quote` with {quote}
text = text.replace(/`(.*?)`/g, ' {$1} ');
}
return text;
}