Skip to content

Instantly share code, notes, and snippets.

@agoose77
Created September 29, 2025 10:09
Show Gist options
  • Save agoose77/f2aa22b8f59c300ec66fe4efdf4c957e to your computer and use it in GitHub Desktop.
Save agoose77/f2aa22b8f59c300ec66fe4efdf4c957e to your computer and use it in GitHub Desktop.
import retextSpell from "retext-spell";
async function loadDictionary(dictionary) {
const baseUrl = new URL(`https://unpkg.com/dictionary-${dictionary}@latest/`);
const [aff, dic] = await Promise.all([
fetch(new URL("index.aff", baseUrl)),
fetch(new URL("index.dic", baseUrl)),
]);
if (!(aff.ok && dic.ok)) {
throw new Error(`Couldn't load dictionary files from ${baseUrl}`);
}
return {
aff: Buffer.from(await aff.arrayBuffer()),
dic: Buffer.from(await dic.arrayBuffer()),
};
}
function plugin(options) {
return async (tree, file, next) => {
// The nascent beginnings of a configurable dictionary
const locale = "en-gb";
let dictionary;
try {
dictionary = await loadDictionary(locale);
} catch (error) {
file.fail(String(error));
}
const impl = retextSpell({ dictionary });
return impl(tree, file, next);
};
}
export default {
plugins: [[plugin, {}]],
};
  1. Install the NodeJS packages
  2. Install the Python dependencies
import shutil
key = "retext-language-server"
c.LanguageServerManager.language_servers = {
key: dict(
version=2,
display_name=key,
mime_types=["text/x-gfm", "text/x-ipythongfm", "text/x-markdown"],
argv=[
shutil.which("node"),
"/tmp/tmp.O8NDAzyhVI/server.mjs",
"--stdio",
],
languages=["markdown", "ipythongfm", "gfm"],
install=dict(
npm="npm install --save-dev {}".format(key),
yarn="yarn add --dev {}".format(key),
jlpm="jlpm add --dev {}".format(key),
),
)
}
{
"dependencies": {
"remark": "^15.0.1",
"retext": "^9.0.0",
"retext-spell": "^6.1.0",
"unified-language-server": "^4.0.1"
}
}
jupyterlab-lsp
python-lsp-server[all]
jupyterlab
import { retext } from "retext";
import { createUnifiedLanguageServer } from "unified-language-server";
process.title = "retext-language-server";
createUnifiedLanguageServer({
ignoreName: ".retextignore",
pluginPrefix: "retext",
rcName: ".retextrc",
processorName: "retext",
processorSpecifier: "retext",
defaultProcessor: retext,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment