mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
better FIM codeblock matching
This commit is contained in:
parent
b3ebe85c04
commit
a0569b1ead
1 changed files with 6 additions and 5 deletions
|
|
@ -76,16 +76,20 @@ class SurroundingsRemover {
|
|||
|
||||
|
||||
removeCodeBlock = () => {
|
||||
// Match either:
|
||||
// 1. ```language\n<code>\n```\n?
|
||||
// 2. ```<code>\n```\n?
|
||||
|
||||
const pm = this
|
||||
const foundCodeBlock = pm.removePrefix('```')
|
||||
if (!foundCodeBlock) return false
|
||||
|
||||
pm.removeFromStartUntil('\n', true) // language
|
||||
|
||||
const foundCodeBlockEnd = pm.removeSuffix('```')
|
||||
const foundCodeBlockEnd = pm.removeSuffix('```') || pm.removeSuffix('```\n')
|
||||
if (!foundCodeBlockEnd) return false
|
||||
|
||||
pm.removeSuffix('\n')
|
||||
pm.removeSuffix('\n') // remove the newline before ```
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
@ -105,9 +109,6 @@ class SurroundingsRemover {
|
|||
|
||||
|
||||
export const extractCodeFromRegular = ({ text, recentlyAddedTextLen }: { text: string, recentlyAddedTextLen: number }): [string, string] => {
|
||||
// Match either:
|
||||
// 1. ```language\n<code>```
|
||||
// 2. ```<code>```
|
||||
|
||||
const pm = new SurroundingsRemover(text)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue