Skip to content

feat: 给所有 md 文件生成的文档添加 code copy #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const router = useRouter();
router.afterEach((to, from) => {
highBrightnessControllerStore.obj[to.path] =
!highBrightnessControllerStore.obj[to.path];
console.log(highBrightnessControllerStore.obj[to.path], 2);
});

const themeStore = useThemeStore();
Expand Down
11 changes: 7 additions & 4 deletions src/components/AppMarkdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import { ref } from 'vue';
import CategorySecond from '../../components/CategorySecond.vue';
import { useRoute, useProps } from 'vue-router';
import { setTitle } from '../../utils/utils.js';
import { requestGetJson } from '../utils/utils.js';
import { requestToYaml } from '../utils/utils.js';
import {
setTitle,
requestGetJson,
requestToYaml,
handleCopyCodeSuccess
} from '../../utils/utils.js';

const props = useProps(['mdPath']);

Expand All @@ -32,7 +35,7 @@ const newsDate = ref('');
:title="yamlDoc['title']"
:right-text="newsDate"
class="absolute w-[calc(59.5vw-1px)]" />
<v-md-preview :text="mdRes" class="pt-[50px]"></v-md-preview>
<v-md-preview :text="mdRes" class="pt-[50px]" @copy-code-success="handleCopyCodeSuccess" />
</div>
</template>

Expand Down
5 changes: 5 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { install as VueMonacoEditorPlugin } from '@guolao/vue-monaco-editor';
import VMdPreview from '@kangc/v-md-editor/lib/preview';
import '@kangc/v-md-editor/lib/style/preview.css';
import vuepressTheme from '@kangc/v-md-editor/lib/theme/vuepress.js';
import createCopyCodePlugin from '@kangc/v-md-editor/lib/plugins/copy-code/index';
import '@kangc/v-md-editor/lib/plugins/copy-code/copy-code.css';
import '@kangc/v-md-editor/lib/theme/style/vuepress.css';
import './css/index.scss';
import './css/element-plus.scss';
Expand Down Expand Up @@ -47,6 +49,9 @@ VMdPreview.use(vuepressTheme, {
Prism
});

// copy code
VMdPreview.use(createCopyCodePlugin());

// highlightjs
import 'highlight.js/styles/stackoverflow-light.css';
// import hljs from 'highlight.js/lib/core';
Expand Down
10 changes: 7 additions & 3 deletions src/pages/mdView/MdView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
import { ref } from 'vue';
import CategorySecond from '../../components/CategorySecond.vue';
import { useRoute } from 'vue-router';
import { setTitle } from '../../utils/utils.js';
import { requestToYaml, requestGetJson } from '../../utils/utils.js';
import {
setTitle,
requestToYaml,
requestGetJson,
handleCopyCodeSuccess
} from '../../utils/utils.js';

const mdRes = ref();
const route = useRoute();
Expand All @@ -28,7 +32,7 @@ const newsDate = ref('');
:title="yamlDoc['title']"
:right-text="newsDate"
class="absolute w-[calc(59.5vw-1px)]" />
<v-md-preview :text="mdRes"></v-md-preview>
<v-md-preview :text="mdRes" @copy-code-success="handleCopyCodeSuccess" />
</div>
</template>

Expand Down
10 changes: 7 additions & 3 deletions src/pages/news/NewsDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
import { ref } from 'vue';
import CategorySecond from '../../components/CategorySecond.vue';
import { useRoute } from 'vue-router';
import { setTitle } from '../../utils/utils.js';
import { requestGetJson, requestToYaml } from '../../utils/utils.js';
import {
setTitle,
requestGetJson,
requestToYaml,
handleCopyCodeSuccess
} from '../../utils/utils.js';

const mdRes = ref();
const route = useRoute();
Expand All @@ -29,7 +33,7 @@ const newsDate = ref('');
:title="yamlDoc['title']"
:right-text="newsDate"
class="sticky top-0 z-1" />
<v-md-preview :text="mdRes"></v-md-preview>
<v-md-preview :text="mdRes" @copy-code-success="handleCopyCodeSuccess" />
</div>
</template>

Expand Down
4 changes: 4 additions & 0 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,7 @@ export const useHighlightWatch = (switchHash) => {
switchHash();
});
};

export const handleCopyCodeSuccess = () => {
ElMessage.success('复制成功');
};