mirror of
https://github.com/heyman/heynote.git
synced 2025-06-24 11:31:25 +02:00
Add relevance threshold to language auto detection, and some debug logging
This commit is contained in:
parent
185dc25078
commit
8649222fa8
@ -22,14 +22,17 @@ export function languageDetection(getView) {
|
|||||||
const block = getActiveNoteBlock(state)
|
const block = getActiveNoteBlock(state)
|
||||||
const newLang = HIGHLIGHTJS_TO_TOKEN[event.data.highlightjs.language]
|
const newLang = HIGHLIGHTJS_TO_TOKEN[event.data.highlightjs.language]
|
||||||
if (block.language.auto === true && block.language.name !== newLang) {
|
if (block.language.auto === true && block.language.name !== newLang) {
|
||||||
let content = state.doc.sliceString(block.content.from, block.content.to)
|
console.log("New auto detected language:", newLang, "Relevance:", event.data.highlightjs.relevance)
|
||||||
const threshold = content.length * 0.1
|
if (event.data.highlightjs.relevance >= 5) {
|
||||||
if (levenshtein_distance(content, event.data.content) <= threshold) {
|
let content = state.doc.sliceString(block.content.from, block.content.to)
|
||||||
console.log("Setting new auto detected language:", newLang)
|
const threshold = content.length * 0.1
|
||||||
// the content has not changed significantly
|
if (levenshtein_distance(content, event.data.content) <= threshold) {
|
||||||
changeLanguageTo(state, view.dispatch, block, newLang, true)
|
// the content has not changed significantly so it's safe to change the language
|
||||||
} else {
|
console.log("Changing language to", newLang)
|
||||||
console.log("Content has changed significantly, not setting new language")
|
changeLanguageTo(state, view.dispatch, block, newLang, true)
|
||||||
|
} else {
|
||||||
|
console.log("Content has changed significantly, not setting new language")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user