@alauda/doom 1.15.2 → 1.16.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.
@@ -15,7 +15,6 @@ import { transformerMetaHighlight, transformerMetaWordHighlight, transformerNota
15
15
  import { difference } from 'es-toolkit';
16
16
  import { glob } from 'tinyglobby';
17
17
  import { cyan } from 'yoctocolors';
18
- import { attributesPlugin } from "../plugins/attributes/index.js";
19
18
  import { apiPlugin, autoSidebarPlugin, autoTocPlugin, createTransformerCallouts, directivesPlugin, globalPlugin, mermaidPlugin, permissionPlugin, replacePlugin, } from "../plugins/index.js";
20
19
  import { isExplicitlyUnversioned, normalizeSlash, UNVERSIONED, } from "../shared/index.js";
21
20
  import { pathExists, pkgResolve, resolveStaticConfig } from "../utils/index.js";
@@ -212,7 +211,6 @@ const getCommonConfig = async ({ config, root, configFilePath, base, version, do
212
211
  apiPlugin({
213
212
  localBasePath,
214
213
  }),
215
- attributesPlugin(),
216
214
  autoSidebarPlugin({ export: export_, ignore }),
217
215
  autoTocPlugin(),
218
216
  directivesPlugin(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "1.15.2",
3
+ "version": "1.16.0",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": {
@@ -67,7 +67,6 @@
67
67
  "globals": "^16.4.0",
68
68
  "html-tag-names": "^2.1.0",
69
69
  "jsencrypt": "^3.5.4",
70
- "md-attr-parser": "^1.3.0",
71
70
  "mdast-util-mdx": "^3.0.0",
72
71
  "mdast-util-mdx-jsx": "^3.2.0",
73
72
  "mdast-util-phrasing": "^4.1.0",
@@ -1,2 +0,0 @@
1
- import type { RspressPlugin } from '@rspress/core';
2
- export declare const attributesPlugin: () => RspressPlugin;
@@ -1,9 +0,0 @@
1
- import { remarkAttributes } from "./remark-attributes/index.js";
2
- export const attributesPlugin = () => {
3
- return {
4
- name: 'doom-attributes',
5
- markdown: {
6
- remarkPlugins: [remarkAttributes],
7
- },
8
- };
9
- };
@@ -1,14 +0,0 @@
1
- import type { Node, Root } from 'mdast';
2
- export interface Attrs extends Node {
3
- type: 'attrs';
4
- value?: string | null;
5
- }
6
- declare module 'mdast' {
7
- interface PhrasingContentMap {
8
- attrs: Attrs;
9
- }
10
- interface RootContentMap {
11
- attrs: Attrs;
12
- }
13
- }
14
- export declare function attributesTransformer(root: Root): void;
@@ -1,63 +0,0 @@
1
- import parseAttrs from 'md-attr-parser';
2
- import { visit } from 'unist-util-visit';
3
- export function attributesTransformer(root) {
4
- visit(root, 'paragraph', (node, _, parent) => {
5
- if ('children' in node &&
6
- node.children.length === 1 &&
7
- node.children[0].type === 'attrs') {
8
- const children = parent.children;
9
- const index = children.indexOf(node);
10
- children[index] = node.children[0];
11
- }
12
- });
13
- visit(root, (node, _, parent) => node.type === 'paragraph' && parent?.type === 'listItem', (node, _, parent) => {
14
- const { children } = node;
15
- const ids = Object.entries(children)
16
- .filter(([, child]) => child.type === 'attrs')
17
- .map(([id, node]) => [Number.parseInt(id, 10), node]);
18
- if (ids.length === 0) {
19
- return;
20
- }
21
- for (const [index, attrNode] of ids) {
22
- const sibling = children[index - 1];
23
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
24
- if (sibling?.type === 'text' && parent) {
25
- const data = parent.data;
26
- parent.data = {
27
- ...data,
28
- hProperties: {
29
- ...data?.hProperties,
30
- ...parseAttrs(attrNode.value).prop,
31
- },
32
- };
33
- children.splice(index, 1);
34
- }
35
- }
36
- });
37
- visit(root, 'attrs', (node, index, parent) => {
38
- if (index == null || parent == null || parent.children.length <= 1) {
39
- return;
40
- }
41
- const { children } = parent;
42
- const sibling = children.at(index - 1);
43
- if (!sibling || sibling.type === 'text') {
44
- parent.data = {
45
- ...parent.data,
46
- hProperties: {
47
- ...parent.data?.hProperties,
48
- ...parseAttrs(node.value).prop,
49
- },
50
- };
51
- }
52
- else {
53
- sibling.data = {
54
- ...sibling.data,
55
- hProperties: {
56
- ...sibling.data?.hProperties,
57
- ...parseAttrs(node.value).prop,
58
- },
59
- };
60
- }
61
- children.splice(index, 1);
62
- });
63
- }
@@ -1,9 +0,0 @@
1
- import type { Root } from 'mdast';
2
- import type { Extension as FromMarkdownExtension } from 'mdast-util-from-markdown';
3
- import type { Plugin } from 'unified';
4
- import type { AttributesExtension } from './types.ts';
5
- export interface AttributesData {
6
- micromarkExtensions?: AttributesExtension[];
7
- fromMarkdownExtensions?: FromMarkdownExtension[];
8
- }
9
- export declare const remarkAttributes: Plugin<[], Root>;
@@ -1,13 +0,0 @@
1
- import { attributesTransformer } from "./attributes-transformer.js";
2
- import { mdastAttributes } from "./mdast-attributes.js";
3
- import { micromarkAttributes } from "./micromark-attributes.js";
4
- export const remarkAttributes = function () {
5
- const data = this.data();
6
- function add(key, value) {
7
- data[key] ||= [];
8
- data[key].unshift(value);
9
- }
10
- add('micromarkExtensions', micromarkAttributes());
11
- add('fromMarkdownExtensions', mdastAttributes());
12
- return attributesTransformer;
13
- };
@@ -1,5 +0,0 @@
1
- import type { Extension as FromMarkdownExtension } from 'mdast-util-from-markdown';
2
- /**
3
- * Fully-configured extension to add Heading ID nodes to Markdown.
4
- **/
5
- export declare function mdastAttributes(): FromMarkdownExtension;
@@ -1,21 +0,0 @@
1
- /**
2
- * Fully-configured extension to add Heading ID nodes to Markdown.
3
- **/
4
- export function mdastAttributes() {
5
- return {
6
- enter: {
7
- attrs(token) {
8
- this.enter({ type: 'attrs', value: null }, token);
9
- this.buffer();
10
- },
11
- },
12
- exit: {
13
- attrs(token) {
14
- const attrs = this.resume();
15
- const node = this.stack[this.stack.length - 1];
16
- this.exit(token);
17
- node.value = attrs;
18
- },
19
- },
20
- };
21
- }
@@ -1,4 +0,0 @@
1
- import type { AttributesExtension } from './types.js';
2
- export declare function micromarkAttributes(options?: {
3
- escaped: boolean;
4
- }): AttributesExtension;
@@ -1,169 +0,0 @@
1
- import { codes } from 'micromark-util-symbol';
2
- export function micromarkAttributes(options = { escaped: false }) {
3
- const syntaxExtensionEscaped = {
4
- text: {
5
- [codes.backslash]: {
6
- name: 'attributesEscapedMaybeStart',
7
- tokenize(effects, ok, stop) {
8
- return start;
9
- function start(code) {
10
- return effects.attempt({
11
- tokenize(effects, startOk, startNok) {
12
- return attemptStart;
13
- function attemptStart(code) {
14
- if (code !== null) {
15
- effects.consume(code);
16
- return dive;
17
- }
18
- }
19
- function dive(code) {
20
- if (code === codes.backslash) {
21
- effects.consume(code);
22
- effects.enter('chunkString', { contentType: 'string' });
23
- return effects.attempt({
24
- tokenize(effects, diveOk, diveNok) {
25
- return escapedBraces;
26
- function escapedBraces(code) {
27
- if (code === codes.backslash) {
28
- effects.consume(code);
29
- return braces;
30
- }
31
- return diveNok(code);
32
- }
33
- function braces(code) {
34
- if (code === codes.leftCurlyBrace ||
35
- code === codes.rightCurlyBrace) {
36
- effects.consume(code);
37
- effects.exit('chunkString');
38
- return diveOk(code);
39
- }
40
- return diveNok(code);
41
- }
42
- },
43
- }, startOk, dive);
44
- }
45
- if (code === codes.leftCurlyBrace) {
46
- effects.enter('attributes');
47
- effects.consume(code);
48
- effects.enter('attrs');
49
- effects.enter('chunkString', { contentType: 'string' });
50
- return inside;
51
- }
52
- if (code !== null) {
53
- return startNok;
54
- }
55
- }
56
- function continueFurtherInside(code) {
57
- effects.consume(code);
58
- return inside;
59
- }
60
- function inside(code) {
61
- // skip `#` which is used heading id in rspress
62
- if (code === codes.numberSign) {
63
- return startNok(code);
64
- }
65
- if ([
66
- codes.carriageReturn,
67
- codes.lineFeed,
68
- codes.carriageReturnLineFeed,
69
- ].includes(code)) {
70
- effects.consume(code);
71
- return startNok(code);
72
- }
73
- if (code === codes.backslash) {
74
- return effects.attempt({
75
- tokenize(effects, insideOk, insideNok) {
76
- return attemptBackslash;
77
- function attemptBackslash(code) {
78
- if (code === codes.backslash) {
79
- effects.exit('chunkString');
80
- effects.exit('attrs');
81
- effects.consume(code);
82
- return endBrace;
83
- }
84
- }
85
- function endBrace(code) {
86
- if (code === codes.rightCurlyBrace) {
87
- effects.consume(code);
88
- effects.exit('attributes');
89
- return insideOk(code);
90
- }
91
- if (code === codes.backslash) {
92
- effects.consume(code);
93
- return insideNok(code);
94
- }
95
- if (code !== null) {
96
- effects.consume(code);
97
- return insideNok(code);
98
- }
99
- throw new Error(`No closing attribute brace found`);
100
- }
101
- },
102
- }, startOk, continueFurtherInside)(code);
103
- }
104
- if (code !== null) {
105
- effects.consume(code);
106
- return inside;
107
- }
108
- }
109
- },
110
- }, ok, stop)(code);
111
- }
112
- },
113
- },
114
- },
115
- };
116
- const syntaxExtension = {
117
- text: {
118
- [codes.leftCurlyBrace]: {
119
- name: 'attributesMaybeStart',
120
- tokenize(effects, ok, nok) {
121
- return start;
122
- function start(code) {
123
- return effects.attempt({
124
- tokenize(effects, ok, nok) {
125
- return attemptStart;
126
- function attemptStart(code) {
127
- if (code !== null) {
128
- effects.enter('attributes');
129
- effects.consume(code);
130
- effects.enter('attrs');
131
- effects.enter('chunkString', { contentType: 'string' });
132
- return inside;
133
- }
134
- }
135
- function inside(code) {
136
- if (code !== null) {
137
- if ([
138
- codes.carriageReturn,
139
- codes.lineFeed,
140
- codes.carriageReturnLineFeed,
141
- null,
142
- codes.backslash,
143
- codes.leftCurlyBrace,
144
- ].includes(code)) {
145
- effects.consume(code);
146
- return nok(code);
147
- }
148
- if (code === codes.rightCurlyBrace) {
149
- effects.exit('chunkString');
150
- effects.exit('attrs');
151
- effects.consume(code);
152
- effects.exit('attributes');
153
- return ok(code);
154
- }
155
- effects.consume(code);
156
- return inside;
157
- }
158
- return nok(code);
159
- }
160
- },
161
- }, ok, nok)(code);
162
- }
163
- },
164
- previous: (code) => code !== codes.backslash,
165
- },
166
- },
167
- };
168
- return options.escaped ? syntaxExtensionEscaped : syntaxExtension;
169
- }
@@ -1,80 +0,0 @@
1
- import type { Construct, Effects, Extension, State, Token, TokenizeContext, TokenType } from 'micromark-util-types';
2
- export type AttributesTokenType = TokenType | 'attributes' | 'attrs';
3
- /**
4
- * Open a token.
5
- *
6
- * @param type
7
- * Token type.
8
- * @param fields
9
- * Extra fields.
10
- * @returns
11
- * Token.
12
- */
13
- export type AttributesEnter = (type: AttributesTokenType, fields?: Omit<Partial<Token>, 'type'>) => Token;
14
- /**
15
- * Close a token.
16
- *
17
- * @param type
18
- * Token type.
19
- * @returns
20
- * Token.
21
- */
22
- export type AttributesExit = (type: AttributesTokenType) => Token;
23
- /**
24
- * Attempt deals with several values, and tries to parse according to those
25
- * values.
26
- *
27
- * If a value resulted in `ok`, it worked, the tokens that were made are used,
28
- * and `ok` is switched to.
29
- * If the result is `nok`, the attempt failed, so we revert to the original
30
- * state, and `nok` is used.
31
- *
32
- * @param construct
33
- * Construct(s) to try.
34
- * @param ok
35
- * State to move to when successful.
36
- * @param nok
37
- * State to move to when unsuccessful.
38
- * @returns
39
- * Next state.
40
- */
41
- export type AttributesAttempt = (construct: AttributesConstruct[] | AttributesConstruct | AttributesConstructRecord, ok: State, nok?: State) => State;
42
- export type AttributeEffects = {
43
- /**
44
- * Start a new token.
45
- */
46
- enter: AttributesEnter;
47
- /**
48
- * End a started token.
49
- */
50
- exit: AttributesExit;
51
- /**
52
- * Try to tokenize a construct.
53
- */
54
- attempt: AttributesAttempt;
55
- } & Effects;
56
- /**
57
- * A tokenize function sets up a state machine to handle character codes streaming in.
58
- *
59
- * @param this
60
- * Tokenize context.
61
- * @param effects
62
- * Effects.
63
- * @param ok
64
- * State to go to when successful.
65
- * @param nok
66
- * State to go to when unsuccessful.
67
- * @returns
68
- * First state.
69
- */
70
- export type AttributesTokenizer = (this: TokenizeContext, effects: AttributeEffects, ok: State, nok: State) => State;
71
- export interface AttributesExtension extends Omit<Extension, 'text'> {
72
- text?: AttributesConstructRecord;
73
- }
74
- /**
75
- * Several constructs, mapped from their initial codes.
76
- */
77
- export type AttributesConstructRecord = Record<string, AttributesConstruct[] | AttributesConstruct | undefined>;
78
- export interface AttributesConstruct extends Omit<Construct, 'tokenize'> {
79
- tokenize?: AttributesTokenizer;
80
- }
@@ -1 +0,0 @@
1
- export {};