vuepress-plugin-md-power 1.0.0-rc.54 → 1.0.0-rc.55

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,143 @@
1
+ <script setup lang="ts">
2
+ import { getHighlighterCore } from 'shiki/core'
3
+ import type { HighlighterCore } from 'shiki/core'
4
+ import editorData from '@internal/md-power/replEditorData'
5
+ import { onMounted, onUnmounted, ref, shallowRef, watch } from 'vue'
6
+ import { resolveCodeInfo } from '../composables/codeRepl.js'
7
+
8
+ let highlighter: HighlighterCore | null = null
9
+ let container: HTMLPreElement | null = null
10
+ let lineNumbers: HTMLDivElement | null = null
11
+ const { grammars, theme } = editorData
12
+
13
+ const lang = ref<'go' | 'rust' | 'kotlin'>()
14
+
15
+ const editorEl = shallowRef<HTMLDivElement>()
16
+ const textAreaEl = shallowRef<HTMLTextAreaElement>()
17
+ const input = ref('')
18
+
19
+ async function init() {
20
+ highlighter = await getHighlighterCore({
21
+ themes: 'light' in theme && 'dark' in theme ? [theme.light, theme.dark] : [theme],
22
+ langs: Object.keys(grammars).map(key => grammars[key]),
23
+ loadWasm: () => import('shiki/wasm'),
24
+ })
25
+ }
26
+
27
+ function highlight() {
28
+ if (highlighter && lang.value && input.value) {
29
+ const output = highlighter.codeToHtml(input.value, {
30
+ lang: lang.value,
31
+ ...('light' in theme && 'dark' in theme
32
+ ? { themes: theme, defaultColor: false }
33
+ : { theme }),
34
+ })
35
+ if (container) {
36
+ container.innerHTML = output
37
+ .replace(/^<pre[^]+?>/, '')
38
+ .replace(/<\/pre>$/, '')
39
+ .replace(/(<span class="line">)(<\/span>)/g, '$1<wbr>$2')
40
+ }
41
+ if (lineNumbers) {
42
+ lineNumbers.innerHTML = output
43
+ .split('\n')
44
+ .map(() => '<div class="line-number"></div>')
45
+ .join('')
46
+ }
47
+ }
48
+ }
49
+
50
+ function updateScroll() {
51
+ container && (container.scrollLeft = textAreaEl.value?.scrollLeft || 0)
52
+ }
53
+
54
+ watch([input], highlight, { flush: 'post' })
55
+
56
+ onMounted(async () => {
57
+ if (!editorEl.value || !textAreaEl.value)
58
+ return
59
+ await init()
60
+ container = editorEl.value.querySelector('pre')
61
+ lineNumbers = editorEl.value.querySelector('.line-numbers')
62
+ const info = resolveCodeInfo(editorEl.value)
63
+ lang.value = info.lang
64
+ input.value = info.code
65
+ textAreaEl.value.addEventListener('scroll', updateScroll, { passive: false })
66
+ window.addEventListener('resize', updateScroll)
67
+ })
68
+
69
+ onUnmounted(() => {
70
+ textAreaEl.value?.removeEventListener('scroll', updateScroll)
71
+ window.removeEventListener('resize', updateScroll)
72
+ highlighter = null
73
+ container = null
74
+ lineNumbers = null
75
+ })
76
+ </script>
77
+
78
+ <template>
79
+ <div ref="editorEl" class="code-repl-editor">
80
+ <slot />
81
+ <textarea ref="textAreaEl" v-model="input" class="code-repl-input" />
82
+ </div>
83
+ </template>
84
+
85
+ <style scoped>
86
+ .code-repl-editor {
87
+ position: relative;
88
+ }
89
+
90
+ .code-repl-editor :deep(div[class*="language-"] pre) {
91
+ scrollbar-width: none;
92
+ }
93
+
94
+ .code-repl-editor:hover :deep(.copy-code-button) {
95
+ opacity: 1;
96
+ }
97
+
98
+ .code-repl-input {
99
+ position: absolute;
100
+ top: 0;
101
+ right: -1.5rem;
102
+ bottom: 0;
103
+ left: -1.5rem;
104
+ z-index: 1;
105
+ box-sizing: border-box;
106
+ display: block;
107
+ padding: 1.3rem 1.5rem;
108
+ overflow-x: auto;
109
+ font-family: var(--vp-font-family-mono);
110
+ font-size: var(--vp-code-font-size);
111
+ -webkit-hyphens: none;
112
+ hyphens: none;
113
+ color: transparent;
114
+ text-align: left;
115
+ word-break: normal;
116
+ word-wrap: normal;
117
+ -moz-tab-size: 4;
118
+ -o-tab-size: 4;
119
+ tab-size: 4;
120
+ white-space: pre;
121
+ caret-color: gray;
122
+ resize: none;
123
+ background-color: transparent;
124
+ word-spacing: normal;
125
+
126
+ direction: ltr;
127
+ -webkit-font-smoothing: auto;
128
+ -moz-osx-font-smoothing: auto;
129
+ scrollbar-width: thin;
130
+ }
131
+
132
+ @media (min-width: 640px) {
133
+ .code-repl-input {
134
+ right: 0;
135
+ left: 0;
136
+ }
137
+ }
138
+
139
+ :deep(div[class*="language-"].line-numbers-mode) + .code-repl-input {
140
+ padding-left: 1rem;
141
+ margin-left: 2rem;
142
+ }
143
+ </style>
@@ -1,11 +1,18 @@
1
1
  <script setup lang="ts">
2
- import { shallowRef } from 'vue'
2
+ import { defineAsyncComponent, shallowRef } from 'vue'
3
3
  import { useCodeRepl } from '../composables/codeRepl.js'
4
4
  import IconRun from './IconRun.vue'
5
5
  import Loading from './Loading.vue'
6
6
  import IconConsole from './IconConsole.vue'
7
7
  import IconClose from './IconClose.vue'
8
8
 
9
+ defineProps<{
10
+ editable?: boolean
11
+ title?: string
12
+ }>()
13
+
14
+ const Editor = defineAsyncComponent(() => import('./CodeEditor.vue'))
15
+
9
16
  const replEl = shallowRef<HTMLDivElement | null>(null)
10
17
  const outputEl = shallowRef<HTMLDivElement | null>(null)
11
18
  const {
@@ -31,10 +38,16 @@ function runCode() {
31
38
 
32
39
  <template>
33
40
  <div ref="replEl" class="code-repl">
34
- <span v-show="loaded && finished" class="icon-run" title="Run Code" @click="runCode">
35
- <IconRun />
36
- </span>
37
- <slot />
41
+ <div class="code-repl-title">
42
+ <h4>{{ title }}</h4>
43
+ <span v-show="loaded && finished" class="icon-run" title="Run Code" @click="runCode">
44
+ <IconRun />
45
+ </span>
46
+ </div>
47
+ <Editor v-if="editable">
48
+ <slot />
49
+ </Editor>
50
+ <slot v-else />
38
51
  <div ref="outputEl" class="code-repl-pin" />
39
52
  <div v-if="!firstRun" class="code-repl-output">
40
53
  <div class="output-head">
@@ -80,16 +93,43 @@ function runCode() {
80
93
  margin-bottom: 16px;
81
94
  }
82
95
 
96
+ .code-repl :deep(div[class*="language-"]) {
97
+ margin: 0 -1.5rem;
98
+ border-top-left-radius: 0;
99
+ border-top-right-radius: 0;
100
+ }
101
+
83
102
  .code-repl-output {
84
103
  position: relative;
85
104
  top: -20px;
86
105
  padding-top: 6px;
87
106
  margin: 0 -1.5rem;
88
107
  background-color: var(--vp-code-block-bg);
89
- transition: background-color, var(--t-color);
108
+ transition: background-color var(--t-color);
90
109
  }
91
110
 
92
- @media (min-width: 768px) {
111
+ .code-repl-title {
112
+ display: flex;
113
+ align-items: center;
114
+ padding: 0 20px;
115
+ margin: 0 -1.5rem;
116
+ background-color: var(--vp-code-block-bg);
117
+ border-bottom: solid 1px var(--vp-c-divider);
118
+ transition: var(--t-color);
119
+ transition-property: background, border;
120
+ }
121
+
122
+ @media (min-width: 640px) {
123
+ .code-repl-title {
124
+ margin: 0;
125
+ border-top-left-radius: 6px;
126
+ border-top-right-radius: 6px;
127
+ }
128
+
129
+ .code-repl :deep(div[class*="language-"]) {
130
+ margin: 0;
131
+ }
132
+
93
133
  .code-repl-output {
94
134
  margin: 0;
95
135
  border-bottom-right-radius: 6px;
@@ -97,34 +137,36 @@ function runCode() {
97
137
  }
98
138
  }
99
139
 
140
+ .code-repl-title h4 {
141
+ flex: 1;
142
+ padding: 0 12px;
143
+ margin: 0;
144
+ font-size: 14px;
145
+ font-weight: 500;
146
+ line-height: 48px;
147
+ color: var(--vp-code-tab-active-text-color);
148
+ white-space: nowrap;
149
+ transition: color var(--t-color);
150
+ }
151
+
100
152
  .icon-run {
101
- position: absolute;
102
- top: -10px;
103
- right: 10px;
104
- z-index: 2;
105
153
  display: flex;
106
154
  align-items: center;
107
155
  justify-content: center;
108
- width: 30px;
109
- height: 30px;
110
- font-size: 16px;
111
- color: var(--vp-c-bg);
156
+ width: 24px;
157
+ height: 24px;
158
+ font-size: 12px;
159
+ color: var(--vp-c-text-3);
112
160
  cursor: pointer;
113
- background-color: var(--vp-c-brand-1);
161
+ border: solid 1px var(--vp-c-text-3);
114
162
  border-radius: 100%;
115
163
  transition: var(--t-color);
116
- transition-property: color, background-color;
117
- }
118
-
119
- @media (min-width: 768px) {
120
- .icon-run {
121
- top: 60px;
122
- right: 16px;
123
- }
164
+ transition-property: color, border;
124
165
  }
125
166
 
126
167
  .icon-run:hover {
127
- background-color: var(--vp-c-brand-2);
168
+ color: var(--vp-c-text-2);
169
+ border-color: var(--vp-c-text-2);
128
170
  }
129
171
 
130
172
  .code-repl-output .output-head {
@@ -132,7 +174,7 @@ function runCode() {
132
174
  align-items: center;
133
175
  justify-content: space-between;
134
176
  padding: 4px 10px 4px 20px;
135
- border-top: solid 2px var(--vp-c-border);
177
+ border-top: solid 2px var(--vp-c-divider);
136
178
  transition: border-color var(--t-color);
137
179
  }
138
180
 
@@ -1,5 +1,6 @@
1
1
  import { type Ref } from 'vue';
2
2
  type Lang = 'kotlin' | 'go' | 'rust';
3
+ export declare function resolveCode(el: HTMLElement): string;
3
4
  export declare function resolveCodeInfo(el: HTMLDivElement): {
4
5
  lang: Lang;
5
6
  code: string;
@@ -1,4 +1,4 @@
1
- import { ref } from 'vue';
1
+ import { onMounted, ref } from 'vue';
2
2
  import { http } from '../utils/http.js';
3
3
  import { sleep } from '../utils/sleep.js';
4
4
  import { rustExecute } from './rustRepl.js';
@@ -19,18 +19,20 @@ const supportLang = ['kotlin', 'go', 'rust'];
19
19
  function resolveLang(lang) {
20
20
  return lang ? langAlias[lang] || lang : '';
21
21
  }
22
+ export function resolveCode(el) {
23
+ const clone = el.cloneNode(true);
24
+ clone
25
+ .querySelectorAll(ignoredNodes.join(','))
26
+ .forEach(node => node.remove());
27
+ return clone.textContent || '';
28
+ }
22
29
  export function resolveCodeInfo(el) {
23
- const wrapper = el.querySelector('[class*=language-]');
30
+ const wrapper = el.querySelector('div[class*=language-]');
24
31
  const lang = wrapper?.className.match(RE_LANGUAGE)?.[1];
25
- const codeEl = wrapper?.querySelector('pre code');
32
+ const codeEl = wrapper?.querySelector('pre');
26
33
  let code = '';
27
- if (codeEl) {
28
- const clone = codeEl.cloneNode(true);
29
- clone
30
- .querySelectorAll(ignoredNodes.join(','))
31
- .forEach(node => node.remove());
32
- code = clone.textContent || '';
33
- }
34
+ if (codeEl)
35
+ code = resolveCode(codeEl);
34
36
  return { lang: resolveLang(lang), code };
35
37
  }
36
38
  export function useCodeRepl(el) {
@@ -42,6 +44,12 @@ export function useCodeRepl(el) {
42
44
  const stderr = ref([]); // like print error
43
45
  const error = ref(''); // execute error
44
46
  const backendVersion = ref('');
47
+ onMounted(() => {
48
+ if (el.value) {
49
+ const info = resolveCodeInfo(el.value);
50
+ lang.value = info.lang;
51
+ }
52
+ });
45
53
  const executeMap = {
46
54
  kotlin: executeKotlin,
47
55
  go: executeGolang,
@@ -1,3 +1,15 @@
1
+ /**
2
+ * Fork for https://github.com/vuepress-theme-hope/vuepress-theme-hope/blob/main/packages/components/src/client/utils/viewPDF.ts
3
+ *
4
+ * The MIT License (MIT)
5
+ * Copyright (C) 2021 - PRESENT by Mr.Hope<mister-hope@outlook.com>
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ *
9
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
+ */
1
13
  import type { PDFEmbedType, PDFTokenMeta } from '../../shared/pdf.js';
2
14
  export declare function renderPDF(el: HTMLElement, url: string, embedType: PDFEmbedType, options: PDFTokenMeta): void;
3
15
  export declare function usePDF(el: HTMLElement, url: string, options: PDFTokenMeta): void;
@@ -1,3 +1,15 @@
1
+ /**
2
+ * Fork for https://github.com/vuepress-theme-hope/vuepress-theme-hope/blob/main/packages/components/src/client/utils/viewPDF.ts
3
+ *
4
+ * The MIT License (MIT)
5
+ * Copyright (C) 2021 - PRESENT by Mr.Hope<mister-hope@outlook.com>
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ *
9
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
+ */
1
13
  import { ensureEndingSlash, isLinkHttp } from 'vuepress/shared';
2
14
  import { withBase } from 'vuepress/client';
3
15
  import { pluginOptions } from '../options.js';
@@ -1,3 +1,15 @@
1
+ /**
2
+ * Fork for https://github.com/vuepress-theme-hope/vuepress-theme-hope/blob/main/packages/components/src/client/composables/useSize.ts
3
+ *
4
+ * The MIT License (MIT)
5
+ * Copyright (C) 2021 - PRESENT by Mr.Hope<mister-hope@outlook.com>
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ *
9
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
+ */
1
13
  import type { MaybeRef } from '@vueuse/core';
2
14
  import type { Ref, ShallowRef, ToRefs } from 'vue';
3
15
  import type { SizeOptions } from '../../shared/size.js';
@@ -1,3 +1,15 @@
1
+ /**
2
+ * Fork for https://github.com/vuepress-theme-hope/vuepress-theme-hope/blob/main/packages/components/src/client/composables/useSize.ts
3
+ *
4
+ * The MIT License (MIT)
5
+ * Copyright (C) 2021 - PRESENT by Mr.Hope<mister-hope@outlook.com>
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ *
9
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
+ */
1
13
  import { useEventListener } from '@vueuse/core';
2
14
  import { computed, isRef, onMounted, ref, shallowRef, toValue, watch } from 'vue';
3
15
  export function useSize(options, extraHeight = 0) {
@@ -1,6 +1,7 @@
1
- declare module '*.vue' {
2
- import type { ComponentOptions } from 'vue'
1
+ import type { ReplEditorData } from '../shared/repl.js'
3
2
 
4
- const comp: ComponentOptions
5
- export default comp
3
+ declare module '@internal/md-power/replEditorData' {
4
+
5
+ const res: ReplEditorData
6
+ export default res
6
7
  }
@@ -3,7 +3,7 @@
3
3
  * @[caniuse image](feature_name)
4
4
  */
5
5
  import type { PluginWithOptions } from 'markdown-it';
6
- import type { Markdown } from 'vuepress/markdown';
6
+ import type MarkdownIt from 'markdown-it';
7
7
  import type { CanIUseOptions } from '../../shared/index.js';
8
8
  /**
9
9
  * @example
@@ -22,4 +22,4 @@ export declare const caniusePlugin: PluginWithOptions<CanIUseOptions>;
22
22
  * :::
23
23
  * ```
24
24
  */
25
- export declare function legacyCaniuse(md: Markdown, { mode }?: CanIUseOptions): void;
25
+ export declare function legacyCaniuse(md: MarkdownIt, { mode }?: CanIUseOptions): void;
@@ -1,2 +1,4 @@
1
1
  import type markdownIt from 'markdown-it';
2
- export declare function langReplPlugin(md: markdownIt): void;
2
+ import type { App } from 'vuepress/core';
3
+ import type { ReplOptions } from '../../shared/repl.js';
4
+ export declare function langReplPlugin(app: App, md: markdownIt, { theme, go, kotlin, rust, }: ReplOptions): Promise<void>;
@@ -1,17 +1,53 @@
1
1
  import container from 'markdown-it-container';
2
- function createReplContainer(md, type) {
2
+ import { fs, getDirname, path } from 'vuepress/utils';
3
+ const RE_INFO = /^(#editable)?\s*?(.*)$/;
4
+ function createReplContainer(md, lang) {
5
+ const type = `${lang}-repl`;
3
6
  const validate = (info) => info.trim().startsWith(type);
4
7
  const render = (tokens, index) => {
5
8
  const token = tokens[index];
9
+ const info = token.info.trim().slice(type.length).trim() || '';
10
+ // :::lang-repl#editable title
11
+ const [, editable, title] = info.match(RE_INFO) ?? [];
6
12
  if (token.nesting === 1)
7
- return '<LanguageRepl>';
13
+ return `<CodeRepl ${editable ? 'editable' : ''} title="${title || `${lang} playground`}">`;
8
14
  else
9
- return '</LanguageRepl>';
15
+ return '</CodeRepl>';
10
16
  };
11
17
  md.use(container, type, { validate, render });
12
18
  }
13
- export function langReplPlugin(md) {
14
- createReplContainer(md, 'kotlin-repl');
15
- createReplContainer(md, 'go-repl');
16
- createReplContainer(md, 'rust-repl');
19
+ export async function langReplPlugin(app, md, { theme, go = false, kotlin = false, rust = false, }) {
20
+ kotlin && createReplContainer(md, 'kotlin');
21
+ go && createReplContainer(md, 'go');
22
+ rust && createReplContainer(md, 'rust');
23
+ theme ??= { light: 'github-light', dark: 'github-dark' };
24
+ const data = { grammars: {} };
25
+ const themesPath = getDirname(import.meta.resolve('tm-themes'));
26
+ const grammarsPath = getDirname(import.meta.resolve('tm-grammars'));
27
+ const readTheme = (theme) => read(path.join(themesPath, 'themes', `${theme}.json`));
28
+ const readGrammar = (grammar) => read(path.join(grammarsPath, 'grammars', `${grammar}.json`));
29
+ if (typeof theme === 'string') {
30
+ data.theme = await readTheme(theme);
31
+ }
32
+ else {
33
+ data.theme = await Promise.all([
34
+ readTheme(theme.light),
35
+ readTheme(theme.dark),
36
+ ]).then(([light, dark]) => ({ light, dark }));
37
+ }
38
+ if (kotlin)
39
+ data.grammars.kotlin = await readGrammar('kotlin');
40
+ if (go)
41
+ data.grammars.go = await readGrammar('go');
42
+ if (rust)
43
+ data.grammars.rust = await readGrammar('rust');
44
+ await app.writeTemp('internal/md-power/replEditorData.js', `export default ${JSON.stringify(data, null, 2)}`);
45
+ }
46
+ async function read(file) {
47
+ try {
48
+ const content = await fs.readFile(file, 'utf-8');
49
+ return JSON.parse(content);
50
+ }
51
+ catch { }
52
+ return undefined;
17
53
  }
@@ -1,3 +1,4 @@
1
+ import { addViteOptimizeDepsInclude } from '@vuepress/helper';
1
2
  import { caniusePlugin, legacyCaniuse } from './features/caniuse.js';
2
3
  import { pdfPlugin } from './features/pdf.js';
3
4
  import { createIconCSSWriter, iconsPlugin } from './features/icons/index.js';
@@ -14,14 +15,17 @@ export function markdownPowerPlugin(options = {}) {
14
15
  return (app) => {
15
16
  const { initIcon, addIcon } = createIconCSSWriter(app, options.icons);
16
17
  return {
17
- name: '@vuepress-plume/plugin-md-power',
18
+ name: 'vuepress-plugin-md-power',
18
19
  // clientConfigFile: path.resolve(__dirname, '../client/config.js'),
19
20
  clientConfigFile: app => prepareConfigFile(app, options),
20
21
  define: {
21
22
  __MD_POWER_INJECT_OPTIONS__: options,
22
23
  },
23
24
  onInitialized: async () => await initIcon(),
24
- extendsMarkdown(md) {
25
+ extendsBundlerOptions(bundlerOptions) {
26
+ options.repl && addViteOptimizeDepsInclude(bundlerOptions, app, ['shiki/core', 'shiki/wasm']);
27
+ },
28
+ extendsMarkdown: async (md, app) => {
25
29
  if (options.caniuse) {
26
30
  const caniuse = options.caniuse === true ? {} : options.caniuse;
27
31
  // @[caniuse](feature_name)
@@ -67,7 +71,7 @@ export function markdownPowerPlugin(options = {}) {
67
71
  md.use(plotPlugin);
68
72
  }
69
73
  if (options.repl)
70
- langReplPlugin(md);
74
+ await langReplPlugin(app, md, options.repl);
71
75
  },
72
76
  };
73
77
  };
@@ -32,8 +32,8 @@ export async function prepareConfigFile(app, options) {
32
32
  enhances.add(`app.component('Plot', Plot)`);
33
33
  }
34
34
  if (options.repl) {
35
- imports.add(`import LanguageRepl from '${CLIENT_FOLDER}components/LanguageRepl.vue'`);
36
- enhances.add(`app.component('LanguageRepl', LanguageRepl)`);
35
+ imports.add(`import CodeRepl from '${CLIENT_FOLDER}components/CodeRepl.vue'`);
36
+ enhances.add(`app.component('CodeRepl', CodeRepl)`);
37
37
  }
38
38
  // enhances.add(`if (__VUEPRESS_SSR__) return`)
39
39
  if (options.caniuse) {
@@ -2,6 +2,7 @@ import type { CanIUseOptions } from './caniuse.js';
2
2
  import type { PDFOptions } from './pdf.js';
3
3
  import type { IconsOptions } from './icons.js';
4
4
  import type { PlotOptions } from './plot.js';
5
+ import type { ReplOptions } from './repl.js';
5
6
  export interface MarkdownPowerPluginOptions {
6
7
  pdf?: boolean | PDFOptions;
7
8
  icons?: boolean | IconsOptions;
@@ -9,9 +10,12 @@ export interface MarkdownPowerPluginOptions {
9
10
  bilibili?: boolean;
10
11
  youtube?: boolean;
11
12
  codepen?: boolean;
13
+ /**
14
+ * @deprecated
15
+ */
12
16
  replit?: boolean;
13
17
  codeSandbox?: boolean;
14
18
  jsfiddle?: boolean;
15
- repl?: boolean;
19
+ repl?: false | ReplOptions;
16
20
  caniuse?: boolean | CanIUseOptions;
17
21
  }
@@ -0,0 +1,22 @@
1
+ import type { BuiltinTheme, ThemeRegistration } from 'shiki';
2
+ export type ThemeOptions = BuiltinTheme | {
3
+ light: BuiltinTheme;
4
+ dark: BuiltinTheme;
5
+ };
6
+ export interface ReplOptions {
7
+ theme?: ThemeOptions;
8
+ go?: boolean;
9
+ kotlin?: boolean;
10
+ rust?: boolean;
11
+ }
12
+ export interface ReplEditorData {
13
+ grammars: {
14
+ go?: any;
15
+ kotlin?: any;
16
+ rust?: any;
17
+ };
18
+ theme: ThemeRegistration | {
19
+ light: ThemeRegistration;
20
+ dark: ThemeRegistration;
21
+ };
22
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vuepress-plugin-md-power",
3
3
  "type": "module",
4
- "version": "1.0.0-rc.54",
4
+ "version": "1.0.0-rc.55",
5
5
  "description": "The Plugin for VuePres 2 - markdown power",
6
6
  "author": "pengzhanbo <volodymyr@foxmail.com>",
7
7
  "license": "MIT",
@@ -41,15 +41,19 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@iconify/utils": "^2.1.23",
44
+ "@vuepress/helper": "2.0.0-rc.24",
44
45
  "@vueuse/core": "^10.9.0",
45
46
  "local-pkg": "^0.5.0",
46
47
  "markdown-it-container": "^4.0.0",
47
48
  "nanoid": "^5.0.7",
48
- "vue": "^3.4.25"
49
+ "shiki": "^1.4.0",
50
+ "tm-grammars": "^1.8.1",
51
+ "tm-themes": "^1.4.1",
52
+ "vue": "^3.4.26"
49
53
  },
50
54
  "devDependencies": {
51
- "@iconify/json": "^2.2.204",
52
- "@types/markdown-it": "^14.0.1"
55
+ "@iconify/json": "^2.2.206",
56
+ "@types/markdown-it": "^14.1.1"
53
57
  },
54
58
  "publishConfig": {
55
59
  "access": "public"