Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

feat(web): added a splash of color to the demo

Elijah Potterb96da4b7a7c9
diff --git a/demo.md b/demo.md
index 084c7b0f4..ef48b7209 100644
--- a/demo.md
+++ b/demo.md
@@ -8,9 +8,10 @@ Like if you break up words you shoul dn't.
Harper can be a lifesaver when writing technical documents,
emails or other formal forms of communication.
-Harper works everywhere, even offline. Since you r data
-never leaves your device, you don't ned to worry aout us
-selling it or using it to train large language models.
+Harper works everywhere, even offline. Since your data
+never leaves your device, you don't need to worry aout us
+selling it or using it to train large language models,
+despite of the consequences.
The best part: Harper can give you feedback instantly.
For most documents, Harper can serve up suggestions in
diff --git a/harper-core/src/linting/lint_kind.rs b/harper-core/src/linting/lint_kind.rs
index 0f1a70f01..513f9461e 100644
--- a/harper-core/src/linting/lint_kind.rs
+++ b/harper-core/src/linting/lint_kind.rs
@@ -20,6 +20,24 @@ pub enum LintKind {
Miscellaneous,
}
+impl LintKind {
+ /// Produce a string representation, which can be used as keys in a map or CSS variables.
+ pub fn to_string_key(&self) -> String {
+ match self {
+ LintKind::Spelling => "Spelling",
+ LintKind::Capitalization => "Capitalization",
+ LintKind::Formatting => "Formatting",
+ LintKind::Repetition => "Repetition",
+ LintKind::Readability => "Readability",
+ LintKind::Miscellaneous => "Miscellaneous",
+ LintKind::Enhancement => "Enhancement",
+ LintKind::WordChoice => "WordChoice",
+ LintKind::Style => "Style",
+ }
+ .to_owned()
+ }
+}
+
impl Display for LintKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match self {
diff --git a/harper-wasm/src/lib.rs b/harper-wasm/src/lib.rs
index 6befc85b2..f90100472 100644
--- a/harper-wasm/src/lib.rs
+++ b/harper-wasm/src/lib.rs
@@ -282,6 +282,11 @@ impl Lint {
/// Get a string representing the general category of the lint.
pub fn lint_kind(&self) -> String {
+ self.inner.lint_kind.to_string_key()
+ }
+
+ /// Get a string representing the general category of the lint.
+ pub fn lint_kind_pretty(&self) -> String {
self.inner.lint_kind.to_string()
}
diff --git a/packages/web/src/lib/Editor.svelte b/packages/web/src/lib/Editor.svelte
index 633852710..0af62b849 100644
--- a/packages/web/src/lib/Editor.svelte
+++ b/packages/web/src/lib/Editor.svelte
@@ -7,6 +7,7 @@
import type { Lint } from 'harper.js';
import CheckMark from '$lib/CheckMark.svelte';
import { fly } from 'svelte/transition';
+ import lintKindColor from './lintKindColor';
export let content = demo;
@@ -79,10 +80,10 @@
on:click={() => (focused = i)}
bind:this={lintCards[i]}
>
- <div class="pl-2 border-l-[3px] border-l-primary-500">
+ <div class={`pl-2`} style={`border-left: 4px solid ${lintKindColor(lint.lint_kind())}`}>
<div class="flex flex-row">
<h3 class="font-bold text-base p-0">
- {lint.lint_kind()} - “<span class="italic">
+ {lint.lint_kind_pretty()} - “<span class="italic">
{lint.get_problem_text()}
</span>”
</h3>
diff --git a/packages/web/src/lib/Underlines.svelte b/packages/web/src/lib/Underlines.svelte
index c77360d48..6a6f38749 100644
--- a/packages/web/src/lib/Underlines.svelte
+++ b/packages/web/src/lib/Underlines.svelte
@@ -6,6 +6,7 @@
import type { Lint } from 'harper.js';
import { WorkerLinter } from 'harper.js';
+ import lintKindColor from '$lib/lintKindColor';
export let content: string;
export let focusLintIndex: number | undefined;
@@ -47,6 +48,7 @@
focused: boolean;
content: string;
index: number;
+ color: string;
};
type UnderlineToken = string | null | undefined | UnderlineDetails;
@@ -72,7 +74,8 @@
let lintContent: UnderlineDetails = {
focused: lintIndex === focusLintIndex,
index: lintIndex,
- content: lint.get_problem_text().replaceAll(' ', '\u00A0')
+ content: lint.get_problem_text().replaceAll(' ', '\u00A0'),
+ color: lintKindColor(lint.lint_kind())
};
return [...prevContent, lintContent];
@@ -112,7 +115,7 @@
bind:this={lintHighlights[chunk.index]}
on:click={() =>
chunk != null && typeof chunk == 'object' && (focusLintIndex = chunk.index)}
- style={`--line-color: #DB2B39; --line-width: ${chunk.focused ? '4px' : '2px'}; --bg-color: ${chunk.focused ? '#dbafb3' : 'transparent'};`}
+ style={`--line-color: ${chunk.color}; --line-width: ${chunk.focused ? '4px' : '2px'}; --bg-color: ${chunk.focused ? '#dbafb3' : 'transparent'};`}
>
{chunk.content}
</button>
diff --git a/packages/web/src/lib/lintKindColor.ts b/packages/web/src/lib/lintKindColor.ts
new file mode 100644
index 000000000..308948c65
--- /dev/null
+++ b/packages/web/src/lib/lintKindColor.ts
@@ -0,0 +1,24 @@
+export default function lintKindColor(lintKindKey: string): string {
+ switch (lintKindKey) {
+ case 'Spelling':
+ return '#EE4266';
+ case 'Capitalization':
+ return '#540D6E';
+ case 'Style':
+ return '#FFD23F';
+ case 'Formatting':
+ return '#540D6E';
+ case 'Repetition':
+ return '#3BCEAC';
+ case 'Enhancement':
+ return '#0EAD69';
+ case 'Readability':
+ return '#0EAD69';
+ case 'WordChoice':
+ return '#0EAD69';
+ case 'Miscellaneous':
+ return '#3BCEAC';
+ default:
+ throw new Error(`Unexpected lint kind: ${lintKindKey}`);
+ }
+}