mirror of
https://github.com/marktext/marktext.git
synced 2025-05-02 11:50:52 +08:00

* Experimental spellchecker for testing purpose * Fix 'apache' license validation * Use local electron-spellchecker for development * Add settings and bug fixes * Fix Hunspell switchLanguage bug and improvements * Fix attach to editor when enabling spell check again * Add Hunspell license * Copy default Huspell dictionary on first start * Fix full language name * Some code improvements * Allow to add words to user dict and bug fixes * Allow to change Muya's spellcheck container attribute * feat: Don't underline misspelled words * Allow to set Hunspell on macOS * Fix spellchecker changed value * Refactor switchLanguage, init and enableSpellchecker * Refactor and some fixes * Code improvements * electron-spellchecker cleanup and optimization * Disable automatic language detection for Hunspell * Fix init on macOS and update JSDoc * Fix macOS issues and some improvements * Load single settings value only * Fix rebase * Remove debug code * Move electron-spellchecker to scoped npm repo * Fix dictionary of ignored words on macOS * Move replaceWordInline to core API * Remove comment block * Fix upstream lint error
36 lines
1001 B
JavaScript
36 lines
1001 B
JavaScript
import fs from 'fs-extra'
|
|
import path from 'path'
|
|
import axios from 'axios'
|
|
import { SpellChecker } from '@hfelix/electron-spellchecker'
|
|
import { dictionaryPath } from '../spellchecker'
|
|
|
|
/**
|
|
* Try to download the given Hunspell dictionary.
|
|
*
|
|
* @param {string} lang The language to download.
|
|
*/
|
|
export const downloadHunspellDictionary = async lang => {
|
|
const url = SpellChecker.getURLForHunspellDictionary(lang)
|
|
const response = await axios({
|
|
method: 'get',
|
|
url,
|
|
responseType: 'stream'
|
|
})
|
|
|
|
return new Promise((resolve, reject) => {
|
|
const outStream = fs.createWriteStream(path.join(dictionaryPath, `${lang}.bdic`))
|
|
response.data.pipe(outStream)
|
|
outStream.once('error', reject)
|
|
outStream.once('finish', () => resolve())
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Delete the given Hunspell dictionary from disk.
|
|
*
|
|
* @param {string} lang The language to remove.
|
|
*/
|
|
export const deleteHunspellDictionary = async lang => {
|
|
return await fs.remove(path.join(dictionaryPath, `${lang}.bdic`))
|
|
}
|