@bhsd/codemirror-mediawiki 3.4.0 → 3.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,7 +12,7 @@ import type statusBar from './statusBar';
12
12
  export type AddonMain<T> = (config?: T, cm?: CodeMirror6) => Extension;
13
13
  export type Addon<T> = [AddonMain<T>, Record<string, T>?];
14
14
  export type Dialect = 'sanitized-css' | undefined;
15
- export interface MenuItem {
15
+ declare interface MenuItem {
16
16
  name: string;
17
17
  isActionable(this: void, cm: CodeMirror6): boolean;
18
18
  getItems(this: void, cm: CodeMirror6): HTMLDivElement[];
@@ -413,7 +413,7 @@ export class CodeMirror6 {
413
413
  * @param position position
414
414
  */
415
415
  getNodeAt(position) {
416
- return this.#view && ensureSyntaxTree(this.#view.state, position)?.resolve(position, 1);
416
+ return this.#view && ensureSyntaxTree(this.#view.state, position)?.resolveInner(position, 1);
417
417
  }
418
418
  /**
419
419
  * Scroll to the specified position
package/dist/linter.js CHANGED
@@ -72,7 +72,7 @@ export const getWikiLinter = async (opt, obj) => {
72
72
  message,
73
73
  };
74
74
  if (fix) {
75
- const before = lines.slice(0, i - 1).join('\n').length + 1 + length;
75
+ const before = lines.slice(0, i - 1).join('\n').length + length;
76
76
  diagnostic.data = [
77
77
  {
78
78
  range: {
@@ -1,5 +1,7 @@
1
+ import { ensureSyntaxTree } from '@codemirror/language';
1
2
  import { cssLanguage } from '@codemirror/lang-css';
2
3
  import { javascriptLanguage } from '@codemirror/lang-javascript';
4
+ import { sanitizeInlineStyle } from '@bhsd/common';
3
5
  import { getWikiLinter, getJsLinter, getCssLinter, getJsonLinter, getLuaLinter } from './linter';
4
6
  import { posToIndex } from './hover';
5
7
  /**
@@ -127,8 +129,18 @@ export const getVueLintSource = async (opt) => {
127
129
  return async (state) => {
128
130
  const { doc } = state, option = await getOpt(opt, true) ?? {}, js = option['js'], css = option['css'];
129
131
  return [
130
- ...(await Promise.all(cssLanguage.findRegions(state)
131
- .map(({ from, to }) => cssLintSource(styleLint, state.sliceDoc(from, to), css, doc, from, to)))).flat(),
132
+ ...(await Promise.all(cssLanguage.findRegions(state).map(async ({ from, to }) => {
133
+ const node = ensureSyntaxTree(state, from)?.resolve(from, 1);
134
+ if (node?.name === 'AttributeValue') {
135
+ return (await cssLintSource(styleLint, `a {${sanitizeInlineStyle(state.sliceDoc(from, to))}}`, css, doc, from - 3, to + 1)).filter(({ from: f, to: t }) => f <= to && t >= from)
136
+ .map((diagnostic) => {
137
+ diagnostic.from = Math.max(diagnostic.from, from);
138
+ diagnostic.to = Math.min(diagnostic.to, to);
139
+ return diagnostic;
140
+ });
141
+ }
142
+ return node ? cssLintSource(styleLint, state.sliceDoc(from, to), css, doc, from, to) : [];
143
+ }))).flat(),
132
144
  ...javascriptLanguage.findRegions(state)
133
145
  .flatMap(({ from, to }) => jsLintSource(esLint, state.sliceDoc(from, to), js, doc, from, to)),
134
146
  ];