do11y 0.2.2 → 0.2.4
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/README.md +101 -6
- package/dist/docs/files.js +4 -2
- package/dist/docs/options.js +2 -1
- package/dist/docs/plugins/highlight.js +15 -2
- package/dist/docs/plugins/options.d.ts +9 -5
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -2,9 +2,104 @@
|
|
|
2
2
|
|
|
3
3
|
A bare-bones tool to document Vue components.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
> [!WARNING]
|
|
6
|
+
> This is a small personal project! I make a lot of component libraries for personal projects and I absolutely love, love, love writing documentation for components, and I intend for this to be a mix of some of the features I love from [VitePress](https://vitepress.dev) and [Histoire](https://histoire.dev). Issues and thoughts and contributions are very welcome! But it is, again, a _personal_ project 😊
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
### Markdown components with [@mdit-vue](https://github.com/mdit-vue/mdit-vue).
|
|
11
|
+
|
|
12
|
+
Markdown files are treated as single file Vue components with the help of [@mdit-vue](https://github.com/mdit-vue/mdit-vue).
|
|
13
|
+
|
|
14
|
+
You can customize the markdown-it instance through the `markdownSetup` option.
|
|
15
|
+
|
|
16
|
+
### Import markdown route files as routes through `do11y:routes`
|
|
17
|
+
|
|
18
|
+
To include a markdown file as a route it needs to have a `title` and a `slug` (e.g. `/button`) in it's frontmatter.
|
|
19
|
+
|
|
20
|
+
### [Shiki](https://shiki.style) code highlighting
|
|
21
|
+
|
|
22
|
+
Code blocks are automatically highlighted with [Shiki](https://shiki.style).
|
|
23
|
+
|
|
24
|
+
You can customize the Shiki instance through the `highlighter` options.
|
|
25
|
+
|
|
26
|
+
### Highlight imports
|
|
27
|
+
|
|
28
|
+
You can import Vue files as highlighted code blocks through `.vue?highlight`, or `.vue?highlight&lang=css` (if you want the output to compile the style tags).
|
|
29
|
+
|
|
30
|
+
These imports return HTML strings meaning you have to render the code block using `v-html`.
|
|
31
|
+
|
|
32
|
+
> [!WARNING]
|
|
33
|
+
> Imports of type `.vue?highlight&lang=css` only work on built sites. During development it will return the same result as `.vue?highlight`.
|
|
34
|
+
|
|
35
|
+
### Sandboxes
|
|
36
|
+
|
|
37
|
+
Create sandbox components - e.g. `Button.sandbox.vue` will be available under the url `/sandbox?id=button`, and if importing the component it will be wrapped inside an iframe component that has access to the components `?highlight` imports.
|
|
38
|
+
|
|
39
|
+
To customize the sandbox app, use the `Sandbox` option - and to cutomize the iframe component used for import, use the `SandboxIframe` option.
|
|
40
|
+
|
|
41
|
+
> [!NOTE]
|
|
42
|
+
> The id is based on the filename - not the path to the file - this means if you have two sandbox files of the same name in different locations - they won't both work.
|
|
43
|
+
|
|
44
|
+
### Document components with [vue-component-meta](https://www.npmjs.com/package/vue-component-meta)
|
|
45
|
+
|
|
46
|
+
Document components through meta imports (`Button.vue?meta`) which give a simplified version of a result from [vue-component-meta](https://www.npmjs.com/package/vue-component-meta).
|
|
47
|
+
|
|
48
|
+
## Options
|
|
49
|
+
|
|
50
|
+
Expected as the default export in `docs/do11y/do11y.ts`.
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
interface Options {
|
|
54
|
+
/**
|
|
55
|
+
* The home page.
|
|
56
|
+
*/
|
|
57
|
+
Home: () => Promise<Component>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The layout for each route.
|
|
61
|
+
*/
|
|
62
|
+
Layout?: () => Promise<Component>;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Additional setup for the app.
|
|
66
|
+
*/
|
|
67
|
+
setup?(app: App, router: Router): void | Promise<void>;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The wrapper component for sandboxes.
|
|
71
|
+
*/
|
|
72
|
+
Sandbox?: () => Promise<Component>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Additional setup for the sandbox app.
|
|
76
|
+
*/
|
|
77
|
+
setupSandbox?(app: App): void | Promise<void>;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Custom wrapper component for `.vue.sandbox` imports.
|
|
81
|
+
*/
|
|
82
|
+
SandboxIframe?: () => Promise<Component>;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The code highlighter.
|
|
86
|
+
* - Markdown code blocks
|
|
87
|
+
* - `.vue?highlight` & `.vue?highlight&lang=css` imports
|
|
88
|
+
* - `highlightedSource` and `highlightedCssSource` props in SandboxIframe
|
|
89
|
+
*
|
|
90
|
+
* If using multiple themes - you can set the `data-theme` attribute
|
|
91
|
+
* to switch between them, e.g. `data-theme="vitesse-light"`.
|
|
92
|
+
*/
|
|
93
|
+
highlighter?: {
|
|
94
|
+
themes: (ThemeInput | StringLiteralUnion<BundledTheme, string>)[];
|
|
95
|
+
defaultTheme?: string | StringLiteralUnion<BundledTheme, string>;
|
|
96
|
+
transformers?: ShikiTransformer[];
|
|
97
|
+
postprocess?: (pre: HTMLPreElement) => void;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Additional markdown-it setup.
|
|
102
|
+
*/
|
|
103
|
+
markdownSetup?: PluginSimple;
|
|
104
|
+
}
|
|
105
|
+
```
|
package/dist/docs/files.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { searchForWorkspaceRoot } from "vite";
|
|
3
|
+
const [_, __, ___, relativePath] = process.argv;
|
|
3
4
|
export const ui = join(import.meta.dirname, "../ui");
|
|
4
|
-
export const root =
|
|
5
|
-
|
|
5
|
+
export const root = relativePath
|
|
6
|
+
? join(searchForWorkspaceRoot(process.cwd()), relativePath)
|
|
7
|
+
: searchForWorkspaceRoot(process.cwd());
|
|
6
8
|
export const docs = join(root, "docs");
|
|
7
9
|
export const output = join(docs, "dist");
|
|
8
10
|
export const do11y = join(docs, "do11y", "do11y.ts");
|
package/dist/docs/options.js
CHANGED
|
@@ -20,9 +20,10 @@ const resolveOptions = async () => {
|
|
|
20
20
|
return {
|
|
21
21
|
...options,
|
|
22
22
|
highlighter: {
|
|
23
|
+
defaultTheme: options.highlighter?.defaultTheme || resolvedThemes[0],
|
|
23
24
|
themes: options.highlighter?.themes ?? [],
|
|
24
25
|
themesInput,
|
|
25
|
-
|
|
26
|
+
transformers: options.highlighter?.transformers || [],
|
|
26
27
|
},
|
|
27
28
|
};
|
|
28
29
|
};
|
|
@@ -2,6 +2,7 @@ import { readFileSync } from "node:fs";
|
|
|
2
2
|
import { parse as parseVue } from "vue/compiler-sfc";
|
|
3
3
|
import { format } from "oxfmt";
|
|
4
4
|
import { createHighlighter, bundledLanguages, bundledThemes } from "shiki";
|
|
5
|
+
import { JSDOM } from "jsdom";
|
|
5
6
|
import { do11yOptions } from "../options.js";
|
|
6
7
|
import { transformerNotationDiff, transformerNotationErrorLevel, transformerNotationHighlight, } from "@shikijs/transformers";
|
|
7
8
|
const shiki = await createHighlighter({
|
|
@@ -17,6 +18,16 @@ export const highlightCode = (code, lang) => {
|
|
|
17
18
|
transformerNotationHighlight(),
|
|
18
19
|
transformerNotationDiff(),
|
|
19
20
|
transformerNotationErrorLevel(),
|
|
21
|
+
...do11yOptions.highlighter.transformers,
|
|
22
|
+
{
|
|
23
|
+
name: "do11y",
|
|
24
|
+
postprocess(html) {
|
|
25
|
+
const jsdom = new JSDOM(html);
|
|
26
|
+
const preTag = jsdom.window.document.querySelector("pre");
|
|
27
|
+
do11yOptions.highlighter.postprocess?.(preTag);
|
|
28
|
+
return preTag.parentElement.innerHTML;
|
|
29
|
+
},
|
|
30
|
+
},
|
|
20
31
|
],
|
|
21
32
|
});
|
|
22
33
|
};
|
|
@@ -42,9 +53,11 @@ export default () => {
|
|
|
42
53
|
async load(id) {
|
|
43
54
|
if (id === "\0dolly:css.css") {
|
|
44
55
|
const generateThemeCss = (theme) => `
|
|
45
|
-
[data-theme="${theme}"] .shiki
|
|
46
|
-
[data-theme="${theme}"] .shiki span {
|
|
56
|
+
[data-theme="${theme}"] .shiki {
|
|
47
57
|
background-color: var(--shiki-${theme}-bg) !important;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
[data-theme="${theme}"] .shiki span {
|
|
48
61
|
color: var(--shiki-${theme}) !important;
|
|
49
62
|
}
|
|
50
63
|
`;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
2
|
import type { App, Component } from "vue";
|
|
3
3
|
import type { Router } from "vue-router";
|
|
4
|
-
import type { BundledTheme, StringLiteralUnion, ThemeInput } from "shiki";
|
|
4
|
+
import type { BundledTheme, ShikiTransformer, StringLiteralUnion, ThemeInput } from "shiki";
|
|
5
5
|
import type { MarkdownPluginOptions } from "./markdown.js";
|
|
6
6
|
export interface Options extends MarkdownPluginOptions {
|
|
7
7
|
/**
|
|
8
|
-
* The home page
|
|
8
|
+
* The home page.
|
|
9
9
|
*/
|
|
10
10
|
Home: () => Promise<Component>;
|
|
11
11
|
/**
|
|
12
|
-
* The layout
|
|
12
|
+
* The layout for each route.
|
|
13
13
|
*/
|
|
14
14
|
Layout?: () => Promise<Component>;
|
|
15
15
|
/**
|
|
@@ -17,7 +17,7 @@ export interface Options extends MarkdownPluginOptions {
|
|
|
17
17
|
*/
|
|
18
18
|
setup?(app: App, router: Router): void | Promise<void>;
|
|
19
19
|
/**
|
|
20
|
-
* The wrapper component for
|
|
20
|
+
* The wrapper component for sandboxes.
|
|
21
21
|
*/
|
|
22
22
|
Sandbox?: () => Promise<Component>;
|
|
23
23
|
/**
|
|
@@ -25,7 +25,7 @@ export interface Options extends MarkdownPluginOptions {
|
|
|
25
25
|
*/
|
|
26
26
|
setupSandbox?(app: App): void | Promise<void>;
|
|
27
27
|
/**
|
|
28
|
-
* Custom wrapper component for
|
|
28
|
+
* Custom wrapper component for `.vue.sandbox` imports.
|
|
29
29
|
*/
|
|
30
30
|
SandboxIframe?: () => Promise<Component>;
|
|
31
31
|
/**
|
|
@@ -40,6 +40,8 @@ export interface Options extends MarkdownPluginOptions {
|
|
|
40
40
|
highlighter?: {
|
|
41
41
|
themes: (ThemeInput | StringLiteralUnion<BundledTheme, string>)[];
|
|
42
42
|
defaultTheme?: string | StringLiteralUnion<BundledTheme, string>;
|
|
43
|
+
transformers?: ShikiTransformer[];
|
|
44
|
+
postprocess?: (pre: HTMLPreElement) => void;
|
|
43
45
|
};
|
|
44
46
|
}
|
|
45
47
|
export interface ResolvedOptions extends Omit<Options, "highlighter"> {
|
|
@@ -47,6 +49,8 @@ export interface ResolvedOptions extends Omit<Options, "highlighter"> {
|
|
|
47
49
|
themes: (ThemeInput | StringLiteralUnion<BundledTheme, string>)[];
|
|
48
50
|
themesInput: Record<string, string>;
|
|
49
51
|
defaultTheme: string;
|
|
52
|
+
transformers: ShikiTransformer[];
|
|
53
|
+
postprocess?: (pre: HTMLPreElement) => void;
|
|
50
54
|
};
|
|
51
55
|
}
|
|
52
56
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "do11y",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "A bare-bones tool to document Vue components.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"docs-generator",
|
|
7
|
+
"markdown",
|
|
8
|
+
"shiki",
|
|
9
|
+
"story",
|
|
10
|
+
"vite",
|
|
11
|
+
"vue"
|
|
12
|
+
],
|
|
5
13
|
"license": "MIT",
|
|
6
14
|
"repository": "github:sq11y/do11y",
|
|
7
15
|
"bin": "./dist/docs/cli.js",
|
|
@@ -25,6 +33,7 @@
|
|
|
25
33
|
"@shikijs/langs": "^3.22.0",
|
|
26
34
|
"@shikijs/themes": "^3.22.0",
|
|
27
35
|
"@shikijs/transformers": "^3.22.0",
|
|
36
|
+
"@types/markdown-it": "^14.1.2",
|
|
28
37
|
"front-matter": "^4.0.2",
|
|
29
38
|
"jsdom": "^28.1.0",
|
|
30
39
|
"markdown-it": "^14.1.1",
|
|
@@ -38,7 +47,6 @@
|
|
|
38
47
|
"devDependencies": {
|
|
39
48
|
"@tsconfig/node24": "^24.0.4",
|
|
40
49
|
"@types/jsdom": "^27.0.0",
|
|
41
|
-
"@types/markdown-it": "^14.1.2",
|
|
42
50
|
"@types/markdown-it-attrs": "^4.1.3",
|
|
43
51
|
"@types/node": "24.10.3",
|
|
44
52
|
"@vue/tsconfig": "^0.8.1",
|