Skip to content

Commit 66bffd0

Browse files
Merge pull request #979 from Automattic/doc-coverage
Improve doc coverage
2 parents 9450cbb + 55cb392 commit 66bffd0

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-0
lines changed

harper-core/src/span.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use serde::{Deserialize, Serialize};
55
use crate::CharStringExt;
66

77
/// A window in a [`char`] sequence.
8+
///
9+
/// Although specific to `harper.js`, [this page may clear up any questions you have](https://writewithharper.com/docs/harperjs/spans).
810
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Default, PartialEq, Eq)]
911
pub struct Span {
1012
pub start: usize,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: Configure Rules
3+
---
4+
5+
We add new [rules](/docs/rules) to Harper on a daily basis.
6+
As such, it is not recommended for consumers of `harper.js` to rely on any rule to exist.
7+
Further, consumers should allow space (in their UI, database, etc.) for additional rules to be added whenever a new version of `harper.js` is published.
8+
9+
To make this easier, `harper.js` exposes a [`LintConfig`](/docs/harperjs/ref/harper.js.lintconfig.html) type, which can be obtained via `Linter.getLintConfig` and written using `Linter.setLintConfig`.
10+
11+
Each key refers to a specific rule. Each rule can be disabled (set the value to `false`), enabled (set the value to `true`), or to the default (set the value to `undefined`).
12+
For example, the following code disables `SpellCheck`, enables `ExplanationMarks`, and sets `SameAs` to assume the default value.
13+
14+
```javascript
15+
let linter = new WorkerLinter();
16+
17+
await linter.setLintConfig({
18+
SpellCheck: false,
19+
ExplanationMarks: true,
20+
});
21+
```
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: Spans
3+
---
4+
5+
When you lint a document using `harper.js`, you'll get back a series of `Lint` objects, each with a `span` method available.
6+
There are a number of questions that come up about this method.
7+
8+
## What is a span?
9+
10+
A span is a struct that contains a start index and an end index.
11+
The Rust code looks something like this:
12+
13+
```rust
14+
struct Span {
15+
start: usize,
16+
end: usize
17+
}
18+
```
19+
20+
For the uninitiated, a `usize` is an unsigned integer.
21+
Most commonly (and always in the context of a `Lint`), spans are referring to character windows.
22+
More precisely, spans are windows or slices into an array of [unicode scalar values](https://www.unicode.org/glossary/#unicode_scalar_value).
23+
This is less relevant to JavaScript consumers.
24+
Some get confused and believe these are indices into byte arrays (C-style strings).
25+
26+
## Why do I need to obtain the span through a method call?
27+
28+
The actual span for a `Lint` is stored inside WebAssembly memory.
29+
In order to access that data from JavaScript, a tiny bit of WebAssembly code must be run to serialize it and convert its indices to JavaScript [number types](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number).
30+
31+
## What can I use it for?
32+
33+
In a `Lint`, the span represents two things:
34+
35+
1. The location of the problematic text.
36+
1. The text that would be edited by the relevant suggestions.
37+
38+
In other words, you use the span to underline the problem, then again to solve it.

packages/web/src/routes/docs/integrations/obsidian/+page.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ The Harper plugin is a powerful, privacy-first grammar and spell-checking tool d
66

77
![A screenshot of Obsidian with Harper installed](/images/obsidian_screenshot.webp)
88

9+
Unlike other offerings (like Grammarly) Harper explicitly ignores the contents of code fences and inline code blocks.
10+
911
## Key Features
1012

1113
### Privacy-Focused

packages/web/vite.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ export default defineConfig({
9090
title: 'Linting',
9191
to: '/docs/harperjs/linting',
9292
},
93+
{
94+
title: 'Spans',
95+
to: '/docs/harperjs/spans',
96+
},
97+
{
98+
title: 'Configure Rules',
99+
to: '/docs/harperjs/configurerules',
100+
},
93101
{
94102
title: 'Node.js',
95103
to: '/docs/harperjs/node',

0 commit comments

Comments
 (0)