@alauda/doom 2.9.0 → 2.11.0
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.
- package/lib/remark-lint/eslint-message-control.d.ts +12 -0
- package/lib/remark-lint/eslint-message-control.js +75 -0
- package/lib/remark-lint/index.d.ts +5 -1
- package/lib/remark-lint/index.js +5 -1
- package/lib/remarkrc.d.ts +3 -1
- package/lib/remarkrc.js +3 -1
- package/lib/runtime/components/Mermaid.js +4 -2
- package/lib/runtime/components/_X.js +3 -14
- package/lib/runtime/components/_download-link.d.ts +2 -0
- package/lib/runtime/components/_download-link.js +20 -0
- package/package.json +3 -3
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Root } from 'mdast';
|
|
2
|
+
import type { Plugin } from 'unified';
|
|
3
|
+
/**
|
|
4
|
+
* ESLint's `mdx/remark` selector controls every remark diagnostic. Apply its
|
|
5
|
+
* directives to direct remark consumers using physical source locations;
|
|
6
|
+
* `lint ignore` instead controls a whole node and is not an equivalent for
|
|
7
|
+
* `eslint-disable-next-line` (a blank line or multiline node distinguishes them).
|
|
8
|
+
* Keep these controls independent from `lint` directives so enabling one does
|
|
9
|
+
* not undo an explicit disable in the other.
|
|
10
|
+
*/
|
|
11
|
+
declare const eslintMessageControl: Plugin<[], Root>;
|
|
12
|
+
export default eslintMessageControl;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { visitParents } from 'unist-util-visit-parents';
|
|
2
|
+
/**
|
|
3
|
+
* ESLint's `mdx/remark` selector controls every remark diagnostic. Apply its
|
|
4
|
+
* directives to direct remark consumers using physical source locations;
|
|
5
|
+
* `lint ignore` instead controls a whole node and is not an equivalent for
|
|
6
|
+
* `eslint-disable-next-line` (a blank line or multiline node distinguishes them).
|
|
7
|
+
* Keep these controls independent from `lint` directives so enabling one does
|
|
8
|
+
* not undo an explicit disable in the other.
|
|
9
|
+
*/
|
|
10
|
+
const eslintMessageControl = function () {
|
|
11
|
+
// Attach last, after rules have produced their messages.
|
|
12
|
+
this.use(() => (tree, file) => {
|
|
13
|
+
const controls = [];
|
|
14
|
+
visitParents(tree, (node) => {
|
|
15
|
+
if ((node.type !== 'mdxFlowExpression' &&
|
|
16
|
+
node.type !== 'mdxTextExpression') ||
|
|
17
|
+
!('value' in node) ||
|
|
18
|
+
typeof node.value !== 'string' ||
|
|
19
|
+
!node.position) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const value = node.value.trim();
|
|
23
|
+
if (!value.startsWith('/*') || !value.endsWith('*/')) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const comment = value.slice(2, -2).trim();
|
|
27
|
+
const separator = comment.search(/\s/);
|
|
28
|
+
const name = separator < 0 ? comment : comment.slice(0, separator);
|
|
29
|
+
const action = name.slice('eslint-'.length);
|
|
30
|
+
if (!name.startsWith('eslint-') ||
|
|
31
|
+
(action !== 'disable' &&
|
|
32
|
+
action !== 'enable' &&
|
|
33
|
+
action !== 'disable-next-line')) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const attributes = separator < 0 ? '' : comment.slice(separator);
|
|
37
|
+
const rules = attributes
|
|
38
|
+
.split(/\s--\s/)[0]
|
|
39
|
+
.split(/[\s,]+/)
|
|
40
|
+
.filter(Boolean);
|
|
41
|
+
// A bare directive controls every ESLint rule, including mdx/remark.
|
|
42
|
+
if (rules.length && !rules.includes('mdx/remark')) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
controls.push({
|
|
46
|
+
action,
|
|
47
|
+
line: action === 'disable-next-line'
|
|
48
|
+
? node.position.end.line + 1
|
|
49
|
+
: node.position.start.line,
|
|
50
|
+
column: node.position.start.column,
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
file.messages = file.messages.filter((message) => {
|
|
54
|
+
if (!message.line ||
|
|
55
|
+
(message.source !== 'doom-lint' && message.source !== 'remark-lint')) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
let disabled = false;
|
|
59
|
+
for (const control of controls) {
|
|
60
|
+
if (control.action === 'disable-next-line') {
|
|
61
|
+
if (control.line === message.line) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else if (control.line < message.line ||
|
|
66
|
+
(control.line === message.line &&
|
|
67
|
+
control.column <= (message.column ?? 1))) {
|
|
68
|
+
disabled = control.action === 'disable';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return !disabled;
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
export default eslintMessageControl;
|
|
@@ -26,7 +26,11 @@ export * from './table-size.ts';
|
|
|
26
26
|
export * from './title-required.ts';
|
|
27
27
|
export * from './translation-parity/index.ts';
|
|
28
28
|
export * from './unit-case.ts';
|
|
29
|
-
|
|
29
|
+
export interface MessageControlOptions {
|
|
30
|
+
/** ESLint already applies its own directives after remark finishes. */
|
|
31
|
+
eslint?: boolean;
|
|
32
|
+
}
|
|
33
|
+
declare const doomLint: Plugin<[MessageControlOptions?], Root>;
|
|
30
34
|
/**
|
|
31
35
|
* Drops the Chinese-typography rules' messages on documents that are not
|
|
32
36
|
* Chinese.
|
package/lib/remark-lint/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import remarkMessageControl from 'remark-message-control';
|
|
2
|
+
import eslintMessageControl from "./eslint-message-control.js";
|
|
2
3
|
export * from "./check-dead-links.js";
|
|
3
4
|
export * from "./file-naming.js";
|
|
4
5
|
export * from "./heading-anchor-format.js";
|
|
@@ -24,11 +25,14 @@ export * from "./table-size.js";
|
|
|
24
25
|
export * from "./title-required.js";
|
|
25
26
|
export * from "./translation-parity/index.js";
|
|
26
27
|
export * from "./unit-case.js";
|
|
27
|
-
const doomLint = function () {
|
|
28
|
+
const doomLint = function (options) {
|
|
28
29
|
this.use(() => remarkMessageControl({
|
|
29
30
|
name: 'lint',
|
|
30
31
|
source: ['doom-lint', 'remark-lint'],
|
|
31
32
|
}));
|
|
33
|
+
if (options?.eslint !== false) {
|
|
34
|
+
this.use(eslintMessageControl);
|
|
35
|
+
}
|
|
32
36
|
};
|
|
33
37
|
/**
|
|
34
38
|
* Rules about Chinese typography, which only mean anything on a Chinese
|
package/lib/remarkrc.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
plugins: import("unified").Plugin<[], import("mdast").Root>
|
|
2
|
+
plugins: (import("unified").Plugin<[], never> | (import("unified").Plugin<[(import("./remark-lint/index.ts").MessageControlOptions | undefined)?], import("mdast").Root> | {
|
|
3
|
+
eslint: boolean;
|
|
4
|
+
})[])[];
|
|
3
5
|
};
|
|
4
6
|
export default _default;
|
package/lib/remarkrc.js
CHANGED
|
@@ -6,7 +6,9 @@ export default {
|
|
|
6
6
|
// Message control (`<!-- lint disable -->`). It registers its transformer
|
|
7
7
|
// from inside its own attacher, which lands it at the end of the queue, so
|
|
8
8
|
// it filters the messages of every rule regardless of where it sits here.
|
|
9
|
-
|
|
9
|
+
// ESLint applies its own directives, including unused-disable reporting.
|
|
10
|
+
// Only direct remark consumers (such as translation checks) need adaptation.
|
|
11
|
+
[doomLint, { eslint: false }],
|
|
10
12
|
...LINT_RULES,
|
|
11
13
|
],
|
|
12
14
|
};
|
|
@@ -9,9 +9,11 @@ export const Mermaid = ({ className, children }) => {
|
|
|
9
9
|
const containerRef = useRef(null);
|
|
10
10
|
useEffect(() => {
|
|
11
11
|
const container = containerRef.current;
|
|
12
|
-
|
|
12
|
+
// Dark has to be named; `theme: dark` would keep the old palette.
|
|
13
|
+
mermaid.initialize({ theme: isDark ? 'redux-dark-color' : 'redux-color' });
|
|
13
14
|
const render = async () => {
|
|
14
|
-
|
|
15
|
+
// Measure labels with the same document styles used to display the SVG.
|
|
16
|
+
const { svg, diagramType, bindFunctions } = await mermaid.render(`mermaid-${id.slice(1, -1)}`, children, container);
|
|
15
17
|
container.classList.add(diagramType);
|
|
16
18
|
container.innerHTML = svg;
|
|
17
19
|
bindFunctions?.(container);
|
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { withBase } from '@rspress/core/runtime';
|
|
3
3
|
import { getCustomMDXComponent } from '@rspress/core/theme-original';
|
|
4
|
-
import { isExternalUrl
|
|
4
|
+
import { isExternalUrl } from '@rspress/shared';
|
|
5
5
|
import { clsx } from 'clsx';
|
|
6
|
+
import { shouldDownload } from "./_download-link.js";
|
|
6
7
|
const X_ = getCustomMDXComponent();
|
|
7
|
-
const DOWNLOAD_EXTENSIONS = [
|
|
8
|
-
'.ipynb',
|
|
9
|
-
'.zip',
|
|
10
|
-
'.tgz',
|
|
11
|
-
'.tar.gz',
|
|
12
|
-
'.sh',
|
|
13
|
-
'.py',
|
|
14
|
-
'.sql',
|
|
15
|
-
];
|
|
16
8
|
export const X = {
|
|
17
9
|
...X_,
|
|
18
10
|
a: (props) => {
|
|
@@ -21,10 +13,7 @@ export const X = {
|
|
|
21
13
|
download, // type-coverage:ignore-line
|
|
22
14
|
...rest } = props;
|
|
23
15
|
if (href) {
|
|
24
|
-
|
|
25
|
-
const pathname = url.split('/').at(-1).toLowerCase();
|
|
26
|
-
if (download !== false && // type-coverage:ignore-line
|
|
27
|
-
DOWNLOAD_EXTENSIONS.some((ext) => pathname.endsWith(ext))) {
|
|
16
|
+
if (shouldDownload(href, download)) {
|
|
28
17
|
return (_jsx("a", { className: clsx('rp-link', className), href: isExternalUrl(href) ? href : withBase(href),
|
|
29
18
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
30
19
|
download: download ?? true, ...rest }));
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isExternalUrl, parseUrl } from '@rspress/shared';
|
|
2
|
+
const LEGACY_DOWNLOAD_EXTENSIONS = [
|
|
3
|
+
'.ipynb',
|
|
4
|
+
'.zip',
|
|
5
|
+
'.tgz',
|
|
6
|
+
'.tar.gz',
|
|
7
|
+
'.sh',
|
|
8
|
+
'.py',
|
|
9
|
+
'.sql',
|
|
10
|
+
];
|
|
11
|
+
const ROOT_DOWNLOAD_EXTENSIONS = ['.yaml', '.yml', '.json', '.tar'];
|
|
12
|
+
export const isDownloadablePath = (href) => {
|
|
13
|
+
const { url } = parseUrl(href);
|
|
14
|
+
const pathname = url.split('/').at(-1).toLowerCase();
|
|
15
|
+
return (LEGACY_DOWNLOAD_EXTENSIONS.some((ext) => pathname.endsWith(ext)) ||
|
|
16
|
+
(href.startsWith('/') &&
|
|
17
|
+
!isExternalUrl(href) &&
|
|
18
|
+
ROOT_DOWNLOAD_EXTENSIONS.some((ext) => pathname.endsWith(ext))));
|
|
19
|
+
};
|
|
20
|
+
export const shouldDownload = (href, download) => download !== false && isDownloadablePath(href);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alauda/doom",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Doctor Doom making docs.",
|
|
6
6
|
"repository": {
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"ejs": "^5.0.2",
|
|
71
71
|
"es-toolkit": "^1.46.1",
|
|
72
72
|
"eslint": "^10.4.0",
|
|
73
|
-
"eslint-plugin-mdx": "
|
|
73
|
+
"eslint-plugin-mdx": "3.8.3",
|
|
74
74
|
"globals": "^17.6.0",
|
|
75
75
|
"hastscript": "^9.0.1",
|
|
76
76
|
"html-tag-names": "^2.1.0",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"mdast-util-phrasing": "^4.1.0",
|
|
82
82
|
"mdast-util-to-markdown": "^2.1.2",
|
|
83
83
|
"mdast-util-to-string": "^4.0.0",
|
|
84
|
-
"mermaid": "^
|
|
84
|
+
"mermaid": "^12.2.0",
|
|
85
85
|
"openai": "^6.38.0",
|
|
86
86
|
"openapi-types": "^12.1.3",
|
|
87
87
|
"p-ratelimit": "^1.0.1",
|