Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions com.glyph.spellcheck-fa/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Persian (Farsi) spell-check dictionary for Glyph.
//
// Registers فارسی in Settings → Editor → Spell Check. The Hunspell dictionary
// is the Lilak project's, published as `dictionary-fa` (Apache-2.0) in the
// wooorm/dictionaries collection, fetched from jsDelivr the first time the
// language is selected; Glyph caches the parsed checker for the session.
// Pinned to an exact version so the fetched content never changes under us.
const DICTIONARY_BASE = "https://cdn.jsdelivr.net/npm/dictionary-fa@2.0.0";

async function fetchText(url) {
const res = await fetch(url);
if (!res.ok) throw new Error(`Failed to load ${url}: ${res.status}`);
return res.text();
}

export default {
activate(ctx) {
ctx.spellcheck.registerDictionary({
language: "fa",
label: "فارسی (Persian)",
async load() {
const [aff, dic] = await Promise.all([
fetchText(`${DICTIONARY_BASE}/index.aff`),
fetchText(`${DICTIONARY_BASE}/index.dic`),
]);
return { aff, dic };
},
});
},
};
8 changes: 8 additions & 0 deletions com.glyph.spellcheck-fa/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "com.glyph.spellcheck-fa",
"name": "Persian Spell Check",
"version": "1.0.0",
"apiVersion": "^1.3.0",
"description": "Persian (Farsi) spell-check dictionary: adds فارسی to Settings → Editor → Spell Check.",
"permissions": ["network:cdn.jsdelivr.net"]
}
20 changes: 20 additions & 0 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,26 @@ ctx.exporters.register({
});
```

## `ctx.spellcheck` (API 1.3)

Contribute a spell-check dictionary. The language appears (by `label`) in Settings → Editor → Spell Check → Language, and `load` runs only the first time the user selects it, so a fetched dictionary costs nothing until then. Registering a code Glyph already knows (including the built-in `en`) replaces it; unloading the plugin removes the language and drops any cached checker built from it.

```ts
ctx.spellcheck.registerDictionary({
language: "fa",
label: "فارسی (Persian)",
async load() {
// Return Hunspell sources as text, from wherever suits your plugin:
// inlined strings, or a fetch under a `network:` permission.
return { aff, dic };
},
});
```

- `load` must resolve to `{ aff, dic }`: the two Hunspell files as UTF-8 text.
- Main-context only; the sandbox does not expose `ctx.spellcheck` (the loader would have to cross the worker bridge).
- A rejected `load` is not cached: the next time the user selects the language, Glyph calls it again.

## `ctx.markdown`

Extend how documents render.
Expand Down
10 changes: 10 additions & 0 deletions docs/plugin-catalog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ The sample plugin: adds a status bar greeting and a "Hello Status: Say Hello" co
- **Permissions**: none
- **Sandbox**: no
- **Source**: [com.glyph.hello-status/](../com.glyph.hello-status/) in this repo

## Persian Spell Check

`com.glyph.spellcheck-fa`

Adds a Persian (Farsi) dictionary to the editor's spell check: once installed, فارسی appears under Settings → Editor → Spell Check → Language. The Hunspell dictionary comes from the [Lilak](https://github.com/b00f/lilak) project (Apache-2.0), published as [`dictionary-fa`](https://www.npmjs.com/package/dictionary-fa); it is fetched from jsDelivr the first time you select the language (about 1 MB, once per session), so the first activation needs a network connection. Requires Glyph plugin API 1.3 (spell-check dictionaries).

- **Permissions**: `network:cdn.jsdelivr.net`
- **Sandbox**: no (dictionary contributions are main-context only)
- **Source**: [com.glyph.spellcheck-fa/](../com.glyph.spellcheck-fa/) in this repo
9 changes: 9 additions & 0 deletions index.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
"version": "1.0.0",
"apiVersion": "^1.0.0",
"mainUrl": "https://raw.githubusercontent.com/glyph-md/plugins/main/com.glyph.hello-status/main.js"
},
{
"id": "com.glyph.spellcheck-fa",
"name": "Persian Spell Check",
"description": "Persian (Farsi) spell-check dictionary: adds فارسی to Settings → Editor → Spell Check.",
"version": "1.0.0",
"apiVersion": "^1.3.0",
"permissions": ["network:cdn.jsdelivr.net"],
"mainUrl": "https://raw.githubusercontent.com/glyph-md/plugins/main/com.glyph.spellcheck-fa/main.js"
}
]
}