do11y 0.2.4 → 0.2.5

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,33 @@
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
+ async resolveId(id) {
9
+ if (id === "do11y:css") {
10
+ return "\0dolly:css.css";
11
+ }
12
+ },
13
+ load: {
14
+ order: "post",
15
+ handler(id) {
16
+ if (id === "\0dolly:css.css") {
17
+ const generateThemeCss = (theme) => `
18
+ [data-theme="${theme}"] .shiki {
19
+ background-color: var(--shiki-${theme}-bg) !important;
20
+ }
21
+
22
+ [data-theme="${theme}"] .shiki span {
23
+ color: var(--shiki-${theme}) !important;
24
+ }
25
+ `;
26
+ return Object.keys(do11yOptions.highlighter.themesInput)
27
+ .filter((theme) => do11yOptions.highlighter.defaultTheme !== theme)
28
+ .map((theme) => generateThemeCss(theme))
29
+ .join("\n");
30
+ }
31
+ },
32
+ },
33
+ });
@@ -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
48
  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")) {
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,7 @@ 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 `export default \`${await highlightAndFormatCode(path, source)}\`;`;
81
61
  }
82
62
  const loadCss = async (index, lang) => {
83
63
  const { code } = await this.load({
@@ -96,7 +76,7 @@ export default () => {
96
76
  .filter((stylesheet) => !!stylesheet)
97
77
  .map((stylesheet) => `<style>${stylesheet}</style>`)
98
78
  .join("\n");
99
- return `export default ${JSON.stringify(await highlightAndFormatCode(path, sourceWithoutStyles + css))};`;
79
+ return `export default \`${await highlightAndFormatCode(path, sourceWithoutStyles + css)}\`;`;
100
80
  }
101
81
  },
102
82
  };
@@ -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.5",
4
4
  "description": "A bare-bones tool to document Vue components.",
5
5
  "keywords": [
6
6
  "docs-generator",