diff --git a/demo.md b/demo.md index 084c7b0f..ef48b720 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 0f1a70f0..513f9461 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 6befc85b..f9010047 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 63385271..0af62b84 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]} > -
+

- {lint.lint_kind()} - “ + {lint.lint_kind_pretty()} - “ {lint.get_problem_text()}

diff --git a/packages/web/src/lib/Underlines.svelte b/packages/web/src/lib/Underlines.svelte index c77360d4..6a6f3874 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} diff --git a/packages/web/src/lib/lintKindColor.ts b/packages/web/src/lib/lintKindColor.ts new file mode 100644 index 00000000..308948c6 --- /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}`); + } +}