Skip to content

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

feat: add web lint styling optoin (#3104)

Stanley74bdbd3df585
diff --git a/packages/obsidian-plugin/src/HarperSettingTab.ts b/packages/obsidian-plugin/src/HarperSettingTab.ts
index c0dd3ef9d..63037658f 100644
--- a/packages/obsidian-plugin/src/HarperSettingTab.ts
+++ b/packages/obsidian-plugin/src/HarperSettingTab.ts
@@ -100,6 +100,18 @@ export class HarperSettingTab extends PluginSettingTab {
}),
);
+ new Setting(containerEl)
+ .setName('Use Web-Style Lints')
+ .setDesc(
+ 'Use a straight underline with a background color instead of the default squiggly underline.',
+ )
+ .addToggle((toggle) =>
+ toggle.setValue(this.settings.useWebStyleLints ?? false).onChange(async (value) => {
+ this.settings.useWebStyleLints = value;
+ await this.state.initializeFromSettings(this.settings);
+ }),
+ );
+
new Setting(containerEl)
.setName('Mask')
.setDesc(
diff --git a/packages/obsidian-plugin/src/State.ts b/packages/obsidian-plugin/src/State.ts
index 0432d2d99..b5ed2affd 100644
--- a/packages/obsidian-plugin/src/State.ts
+++ b/packages/obsidian-plugin/src/State.ts
@@ -23,6 +23,7 @@ export type Settings = {
ignoredGlobs?: string[];
lintEnabled?: boolean;
regexMask?: string;
+ useWebStyleLints?: boolean;
};
const DEFAULT_DELAY = -1;
@@ -39,6 +40,7 @@ export default class State {
private editorInfoField?: StateField<MarkdownFileInfo>;
private lintEnabled?: boolean;
private regexMask?: string;
+ private useWebStyleLints = false;
/** The CodeMirror extension objects that should be inserted by the host. */
private editorExtensions: Extension[];
@@ -111,6 +113,7 @@ export default class State {
this.ignoredGlobs = settings.ignoredGlobs;
this.lintEnabled = settings.lintEnabled;
this.regexMask = settings.regexMask;
+ this.useWebStyleLints = settings.useWebStyleLints ?? false;
// Reinitialize it.
if (this.hasEditorLinter()) {
@@ -221,7 +224,7 @@ export default class State {
to: span.end,
source: linterName,
severity: 'error',
- markClass: lintKindClass(lint.lint_kind()),
+ markClass: `${lintKindClass(lint.lint_kind())} ${this.useWebStyleLints ? 'harper-web-style' : 'harper-squiggly-style'}`,
title: lint.lint_kind_pretty(),
renderMessage: (_view) => {
const node = document.createElement('template');
@@ -280,6 +283,7 @@ export default class State {
ignoredGlobs: this.ignoredGlobs,
lintEnabled: this.lintEnabled,
regexMask: this.regexMask,
+ useWebStyleLints: this.useWebStyleLints,
};
}
diff --git a/packages/obsidian-plugin/src/lint.ts b/packages/obsidian-plugin/src/lint.ts
index aaf3e02a5..21b9a3e9e 100644
--- a/packages/obsidian-plugin/src/lint.ts
+++ b/packages/obsidian-plugin/src/lint.ts
@@ -526,10 +526,25 @@ function underline(color: string) {
);
}
-const lintKindRangeTheme = Object.fromEntries(
+const lintKindRangeThemeStraight = Object.fromEntries(
Object.entries(LINT_KIND_COLORS).map(([lintKind, color]) => [
- `.cm-lintRange.harper-lintRange-${lintKind}`,
- { backgroundImage: underline(color) },
+ `.cm-lintRange.harper-lintRange-${lintKind}.harper-web-style`,
+ {
+ borderBottom: `2px solid ${color}`,
+ backgroundColor: `${color}22`,
+ },
+ ]),
+);
+
+const lintKindRangeThemeSquiggly = Object.fromEntries(
+ Object.entries(LINT_KIND_COLORS).map(([lintKind, color]) => [
+ `.cm-lintRange.harper-lintRange-${lintKind}.harper-squiggly-style`,
+ {
+ backgroundImage: underline(color),
+ backgroundPosition: 'left bottom',
+ backgroundRepeat: 'repeat-x',
+ paddingBottom: '0.7px',
+ },
]),
);
@@ -646,16 +661,49 @@ const baseTheme = EditorView.baseTheme({
},
'.cm-lintRange': {
+ paddingBottom: '0.7px',
+ },
+
+ '.cm-lintRange-error.harper-web-style': {
+ borderBottom: '2px solid #dd1111',
+ backgroundColor: '#dd111122',
+ },
+ '.cm-lintRange-warning.harper-web-style': {
+ borderBottom: '2px solid #ffa500',
+ backgroundColor: '#ffa50022',
+ },
+ '.cm-lintRange-info.harper-web-style': {
+ borderBottom: '2px solid #999999',
+ backgroundColor: '#99999922',
+ },
+ '.cm-lintRange-hint.harper-web-style': {
+ borderBottom: '2px solid #6666dd',
+ backgroundColor: '#6666dd22',
+ },
+
+ '.cm-lintRange-error.harper-squiggly-style': {
+ backgroundImage: underline('#d11'),
+ backgroundPosition: 'left bottom',
+ backgroundRepeat: 'repeat-x',
+ },
+ '.cm-lintRange-warning.harper-squiggly-style': {
+ backgroundImage: underline('orange'),
+ backgroundPosition: 'left bottom',
+ backgroundRepeat: 'repeat-x',
+ },
+ '.cm-lintRange-info.harper-squiggly-style': {
+ backgroundImage: underline('#999'),
+ backgroundPosition: 'left bottom',
+ backgroundRepeat: 'repeat-x',
+ },
+ '.cm-lintRange-hint.harper-squiggly-style': {
+ backgroundImage: underline('#66d'),
backgroundPosition: 'left bottom',
backgroundRepeat: 'repeat-x',
- paddingBottom: '0.7px',
},
- '.cm-lintRange-error': { backgroundImage: underline('#d11') },
- '.cm-lintRange-warning': { backgroundImage: underline('orange') },
- '.cm-lintRange-info': { backgroundImage: underline('#999') },
- '.cm-lintRange-hint': { backgroundImage: underline('#66d') },
- ...lintKindRangeTheme,
+ ...lintKindRangeThemeStraight,
+ ...lintKindRangeThemeSquiggly,
'.cm-lintRange-active': { backgroundColor: '#ffdd9980' },
'.cm-tooltip-lint': {