do11y 0.2.9 → 0.2.11

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.
@@ -21,6 +21,13 @@ export interface SandboxIframeProps {
21
21
  * @do11y Automatically passed.
22
22
  */
23
23
  highlightedSource: string;
24
+ /**
25
+ * HTML string containing the highlighted source code,
26
+ * without any of the style tags.
27
+ *
28
+ * @do11y Automatically passed.
29
+ */
30
+ highlightedStylelessSource: string;
24
31
  /**
25
32
  * HTML string containing the highlighted source code,
26
33
  * with all the style tags compiled to CSS.
@@ -24,6 +24,7 @@ const resolveOptions = async () => {
24
24
  themes: options.highlighter?.themes ?? [],
25
25
  themesInput,
26
26
  transformers: options.highlighter?.transformers || [],
27
+ postprocess: options.highlighter?.postprocess,
27
28
  },
28
29
  };
29
30
  };
@@ -22,10 +22,12 @@ export const highlightCode = (code, lang) => {
22
22
  {
23
23
  name: "do11y",
24
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;
25
+ if (do11yOptions.highlighter.postprocess) {
26
+ const jsdom = new JSDOM(html);
27
+ const preTag = jsdom.window.document.querySelector("pre");
28
+ do11yOptions.highlighter.postprocess(preTag);
29
+ return preTag.parentElement.innerHTML;
30
+ }
29
31
  },
30
32
  },
31
33
  ],
@@ -46,9 +48,21 @@ export default () => {
46
48
  viteDevServer = server;
47
49
  },
48
50
  async transform(_, id) {
49
- if (id.endsWith(".vue?highlight") || id.endsWith(".vue?highlight&lang=css")) {
50
- const path = id.replace("?highlight", "").replace("&lang=css", "");
51
+ if (id.endsWith(".vue?highlight") ||
52
+ id.endsWith(".vue?highlight&lang=css") ||
53
+ id.endsWith(".vue?highlight&styleless")) {
54
+ const path = id
55
+ .replace("?highlight", "")
56
+ .replace("&lang=css", "")
57
+ .replace("&styleless", "");
51
58
  const source = readFileSync(path, "utf-8");
59
+ const sourceWithoutStyles = source.replace(/\n<style\b[^>]*>[\s\S]*?<\/style>/gi, "");
60
+ if (id.endsWith("styleless")) {
61
+ return {
62
+ code: `export default ${JSON.stringify(await highlightAndFormatCode(path, sourceWithoutStyles))};`,
63
+ moduleType: "js",
64
+ };
65
+ }
52
66
  /**
53
67
  * Getting the code from `load` does not work during development,
54
68
  * so we return the original code during development.
@@ -68,7 +82,6 @@ export default () => {
68
82
  });
69
83
  return code?.replace(/^(export default ")/, "").replace(/"$/, "");
70
84
  };
71
- const sourceWithoutStyles = source.replace(/\n<style\b[^>]*>[\s\S]*?<\/style>/gi, "");
72
85
  const stylesheets = parseVue(source).descriptor.styles.map((style, i) => {
73
86
  /* prettier-ignore */
74
87
  return !style.lang || style.lang === "css"
@@ -31,7 +31,7 @@ export interface Options extends MarkdownPluginOptions {
31
31
  /**
32
32
  * The code highlighter.
33
33
  * - Markdown code blocks
34
- * - `.vue?highlight` & `.vue?highlight&lang=css` imports
34
+ * - `.vue?highlight`, `.vue?highlight&lang=css` & `.vue?highlight&styleless` imports
35
35
  * - `highlightedSource` and `highlightedCssSource` props in SandboxIframe
36
36
  *
37
37
  * If using multiple themes - you can set the `data-theme` attribute
@@ -44,12 +44,14 @@ export default () => {
44
44
 
45
45
  import highlightedSource from "${id}?highlight";
46
46
  import highlightedCssSource from "${id}?highlight&lang=css";
47
+ import highlightedStylelessSource from "${id}?highlight&styleless";
47
48
 
48
49
  export default defineComponent((props) => {
49
50
  return () => h(SandboxIframe, {
50
51
  id: "${toParamId(id)}",
51
52
  highlightedSource,
52
53
  highlightedCssSource,
54
+ highlightedStylelessSource,
53
55
  });
54
56
  });
55
57
  `.trim();
@@ -10,6 +10,9 @@ export declare const viteConfig: {
10
10
  plugins: Plugin<any>[];
11
11
  server: {
12
12
  port: number;
13
+ fs: {
14
+ allow: string[];
15
+ };
13
16
  };
14
17
  preview: {
15
18
  port: number;
@@ -1,6 +1,6 @@
1
1
  import { join } from "node:path";
2
2
  import { loadConfigFromFile } from "vite";
3
- import { docs, ui, output } from "./files.js";
3
+ import { docs, ui, output, root } from "./files.js";
4
4
  import { plugins } from "./plugins/plugins.js";
5
5
  export const getUserViteConfig = async (command) => {
6
6
  const userConfigFile = await loadConfigFromFile({
@@ -39,7 +39,12 @@ const getUserPlugins = async (userViteConfig) => {
39
39
  VuePlugin({
40
40
  ...vuePluginApi.options,
41
41
  include: [/\.vue$/, /\.md$/],
42
- exclude: [/\.vue\?meta$/, /\.vue\?highlight$/, /\.vue\?highlight&lang=css$/],
42
+ exclude: [
43
+ /\.vue\?meta$/,
44
+ /\.vue\?highlight$/,
45
+ /\.vue\?highlight&lang=css$/,
46
+ /\.vue\?highlight&styleless$/,
47
+ ],
43
48
  }),
44
49
  ...resolvedUserPlugins.filter((i) => i.name !== "vite:vue"),
45
50
  ];
@@ -49,6 +54,9 @@ export const viteConfig = {
49
54
  plugins: plugins(),
50
55
  server: {
51
56
  port: 1998,
57
+ fs: {
58
+ allow: [ui, root],
59
+ },
52
60
  },
53
61
  preview: {
54
62
  port: 1996,
@@ -1 +1 @@
1
- import{computed as e,createBlock as t,createCommentVNode as n,createElementBlock as r,defineComponent as i,mergeProps as a,onBeforeMount as o,openBlock as s,shallowRef as c,unref as l}from"vue";import u from"do11y:options";var d=[`src`],f=i({__name:`SandboxIframe`,props:{id:{},url:{},highlightedSource:{},highlightedCssSource:{},passedProps:{}},setup(n){let i=n,f=e(()=>`/sandbox?id=${i.id}`),p=c();return o(async()=>{p.value=(await u.SandboxIframe?.())?.default}),(e,i)=>p.value?(s(),t(l(p),a({key:0,id:n.id,url:f.value,"highlighted-source":n.highlightedSource,"highlighted-css-source":n.highlightedCssSource},n.passedProps),null,16,[`id`,`url`,`highlighted-source`,`highlighted-css-source`])):(s(),r(`iframe`,{key:1,src:f.value},null,8,d))}});export{f as default};
1
+ import{computed as e,createBlock as t,createCommentVNode as n,createElementBlock as r,defineComponent as i,mergeProps as a,onBeforeMount as o,openBlock as s,shallowRef as c,unref as l}from"vue";import u from"do11y:options";var d=[`src`],f=i({__name:`SandboxIframe`,props:{id:{},url:{},highlightedSource:{},highlightedStylelessSource:{},highlightedCssSource:{},passedProps:{}},setup(n){let i=n,f=e(()=>`/sandbox?id=${i.id}`),p=c();return o(async()=>{p.value=(await u.SandboxIframe?.())?.default}),(e,i)=>p.value?(s(),t(l(p),a({key:0,id:n.id,url:f.value,"highlighted-source":n.highlightedSource,"highlighted-css-source":n.highlightedCssSource,"highlighted-styleless-source":n.highlightedStylelessSource},n.passedProps),null,16,[`id`,`url`,`highlighted-source`,`highlighted-css-source`,`highlighted-styleless-source`])):(s(),r(`iframe`,{key:1,src:f.value},null,8,d))}});export{f as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "do11y",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
4
4
  "description": "A bare-bones tool to document Vue components.",
5
5
  "keywords": [
6
6
  "docs-generator",
@@ -29,16 +29,12 @@
29
29
  "@mdit-vue/plugin-component": "^3.0.2",
30
30
  "@mdit-vue/plugin-frontmatter": "^3.0.2",
31
31
  "@mdit-vue/plugin-sfc": "^3.0.2",
32
- "@shikijs/engine-oniguruma": "^3.22.0",
33
- "@shikijs/langs": "^3.22.0",
34
- "@shikijs/themes": "^3.22.0",
35
32
  "@shikijs/transformers": "^3.22.0",
36
33
  "@types/markdown-it": "^14.1.2",
37
34
  "front-matter": "^4.0.2",
38
35
  "jsdom": "^28.1.0",
39
36
  "markdown-it": "^14.1.1",
40
37
  "markdown-it-attrs": "^4.3.1",
41
- "sass": "^1.97.3",
42
38
  "shiki": "^3.22.0",
43
39
  "tinyglobby": "^0.2.15",
44
40
  "v-custom-block": "^1.0.67",
package/src/types.d.ts CHANGED
@@ -48,3 +48,11 @@ declare module "*.vue?meta" {
48
48
 
49
49
  export default meta;
50
50
  }
51
+
52
+ declare module "*.vue?highlight" {
53
+ import type { Meta } from "do11y";
54
+
55
+ const html: string;
56
+
57
+ export default html;
58
+ }