do11y 0.2.4 → 0.2.6

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.
@@ -0,0 +1,7 @@
1
+ import type { Plugin } from "vite";
2
+ /**
3
+ * Adds the necessary styles for using
4
+ * dual themes with the `highlighter`.
5
+ */
6
+ declare const _default: () => Plugin;
7
+ export default _default;
@@ -0,0 +1,31 @@
1
+ import { do11yOptions } from "../../options.js";
2
+ /**
3
+ * Adds the necessary styles for using
4
+ * dual themes with the `highlighter`.
5
+ */
6
+ export default () => ({
7
+ name: "do11y:highlight-css",
8
+ resolveId(id) {
9
+ if (id === "do11y:css") {
10
+ return "\0dolly:css";
11
+ }
12
+ },
13
+ load(id) {
14
+ if (id === "\0dolly:css") {
15
+ const generateThemeCss = (theme) => `
16
+ [data-theme="${theme}"] .shiki {
17
+ background-color: var(--shiki-${theme}-bg) !important;
18
+ }
19
+
20
+ [data-theme="${theme}"] .shiki span {
21
+ color: var(--shiki-${theme}) !important;
22
+ }
23
+ `;
24
+ const css = Object.keys(do11yOptions.highlighter.themesInput)
25
+ .filter((theme) => do11yOptions.highlighter.defaultTheme !== theme)
26
+ .map((theme) => generateThemeCss(theme))
27
+ .join("\n");
28
+ return `export default \`${css}\``;
29
+ }
30
+ },
31
+ });
@@ -3,7 +3,7 @@ import { parse as parseVue } from "vue/compiler-sfc";
3
3
  import { format } from "oxfmt";
4
4
  import { createHighlighter, bundledLanguages, bundledThemes } from "shiki";
5
5
  import { JSDOM } from "jsdom";
6
- import { do11yOptions } from "../options.js";
6
+ import { do11yOptions } from "../../options.js";
7
7
  import { transformerNotationDiff, transformerNotationErrorLevel, transformerNotationHighlight, } from "@shikijs/transformers";
8
8
  const shiki = await createHighlighter({
9
9
  langs: Object.keys(bundledLanguages),
@@ -41,32 +41,12 @@ export const highlightAndFormatCode = async (path, code) => {
41
41
  export default () => {
42
42
  let viteDevServer;
43
43
  return {
44
- name: "do11y:shiki",
44
+ name: "do11y:highlight",
45
45
  configureServer(server) {
46
46
  viteDevServer = server;
47
47
  },
48
- async resolveId(id) {
49
- if (id === "do11y:css") {
50
- return "\0dolly:css.css";
51
- }
52
- },
53
- async load(id) {
54
- if (id === "\0dolly:css.css") {
55
- const generateThemeCss = (theme) => `
56
- [data-theme="${theme}"] .shiki {
57
- background-color: var(--shiki-${theme}-bg) !important;
58
- }
59
-
60
- [data-theme="${theme}"] .shiki span {
61
- color: var(--shiki-${theme}) !important;
62
- }
63
- `;
64
- return Object.keys(do11yOptions.highlighter.themesInput)
65
- .filter((theme) => do11yOptions.highlighter.defaultTheme !== theme)
66
- .map((theme) => generateThemeCss(theme))
67
- .join("\n");
68
- }
69
- else if (id.endsWith(".vue?highlight") || id.endsWith(".vue?highlight&lang=css")) {
48
+ async transform(id) {
49
+ if (id.endsWith(".vue?highlight") || id.endsWith(".vue?highlight&lang=css")) {
70
50
  const path = id.replace("?highlight", "").replace("&lang=css", "");
71
51
  const source = readFileSync(path, "utf-8");
72
52
  /**
@@ -77,7 +57,10 @@ export default () => {
77
57
  * to compile the style tags to CSS.
78
58
  */
79
59
  if (viteDevServer?.config.command === "serve" || !id.endsWith("lang=css")) {
80
- return `export default ${JSON.stringify(await highlightAndFormatCode(path, source))};`;
60
+ return {
61
+ code: `export default \`${await highlightAndFormatCode(path, source)}\`;`,
62
+ moduleType: "js",
63
+ };
81
64
  }
82
65
  const loadCss = async (index, lang) => {
83
66
  const { code } = await this.load({
@@ -96,7 +79,10 @@ export default () => {
96
79
  .filter((stylesheet) => !!stylesheet)
97
80
  .map((stylesheet) => `<style>${stylesheet}</style>`)
98
81
  .join("\n");
99
- return `export default ${JSON.stringify(await highlightAndFormatCode(path, sourceWithoutStyles + css))};`;
82
+ return {
83
+ code: `export default \`${await highlightAndFormatCode(path, sourceWithoutStyles + css)}\`;`,
84
+ moduleType: "js",
85
+ };
100
86
  }
101
87
  },
102
88
  };
@@ -3,7 +3,7 @@ import { sfcPlugin } from "@mdit-vue/plugin-sfc";
3
3
  import { frontmatterPlugin } from "@mdit-vue/plugin-frontmatter";
4
4
  import attrsPlugin from "markdown-it-attrs";
5
5
  import markdown from "markdown-it";
6
- import { highlightCode } from "./highlight.js";
6
+ import { highlightCode } from "./highlight/highlight.js";
7
7
  /**
8
8
  * Processes blocks with the lang set to `md` into HTML,
9
9
  * and turns `.md` files into single file vue components
@@ -1,6 +1,7 @@
1
1
  import ui from "./ui.js";
2
2
  import sandbox from "./sandbox.js";
3
- import highlight from "./highlight.js";
3
+ import highlightCss from "./highlight/highlight-css.js";
4
+ import highlight from "./highlight/highlight.js";
4
5
  import meta from "./meta/meta.js";
5
6
  import markdown from "./markdown.js";
6
7
  import block from "v-custom-block";
@@ -10,6 +11,7 @@ import { do11yOptions } from "../options.js";
10
11
  export const plugins = () => [
11
12
  ui(),
12
13
  sandbox(),
14
+ highlightCss(),
13
15
  highlight(),
14
16
  meta(),
15
17
  markdown(do11yOptions),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "do11y",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "A bare-bones tool to document Vue components.",
5
5
  "keywords": [
6
6
  "docs-generator",