mod: remove prismjs, remove feat: code highlight

This commit is contained in:
KUN1007 2023-09-07 02:15:02 +08:00
parent 83dc826440
commit fde65b088e
9 changed files with 92 additions and 194 deletions

View file

@ -6,6 +6,7 @@
"azkhx", "azkhx",
"bangumi", "bangumi",
"Bilibili", "Bilibili",
"cout",
"dompurify", "dompurify",
"fontawesome", "fontawesome",
"galgame", "galgame",

View file

@ -24,7 +24,6 @@
"dompurify": "^3.0.5", "dompurify": "^3.0.5",
"pinia": "^2.1.6", "pinia": "^2.1.6",
"pinia-plugin-persistedstate": "^3.2.0", "pinia-plugin-persistedstate": "^3.2.0",
"prismjs": "^1.29.0",
"vue": "^3.3.4", "vue": "^3.3.4",
"vue-i18n": "^9.2.2", "vue-i18n": "^9.2.2",
"vue-router": "^4.2.4" "vue-router": "^4.2.4"
@ -33,7 +32,6 @@
"@iconify/vue": "^4.1.1", "@iconify/vue": "^4.1.1",
"@types/dompurify": "^3.0.2", "@types/dompurify": "^3.0.2",
"@types/node": "^20.4.8", "@types/node": "^20.4.8",
"@types/prismjs": "^1.26.0",
"@vitejs/plugin-vue": "^4.2.3", "@vitejs/plugin-vue": "^4.2.3",
"@vitejs/plugin-vue-jsx": "^3.0.2", "@vitejs/plugin-vue-jsx": "^3.0.2",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
@ -42,7 +40,6 @@
"typescript": "^5.1.6", "typescript": "^5.1.6",
"vite": "^4.4.8", "vite": "^4.4.8",
"vite-plugin-mock": "^3.0.0", "vite-plugin-mock": "^3.0.0",
"vite-plugin-prismjs": "^0.0.8",
"vue-tsc": "^1.8.8" "vue-tsc": "^1.8.8"
}, },
"keywords": [ "keywords": [

View file

@ -23,9 +23,6 @@ dependencies:
pinia-plugin-persistedstate: pinia-plugin-persistedstate:
specifier: ^3.2.0 specifier: ^3.2.0
version: 3.2.0(pinia@2.1.6) version: 3.2.0(pinia@2.1.6)
prismjs:
specifier: ^1.29.0
version: 1.29.0
vue: vue:
specifier: ^3.3.4 specifier: ^3.3.4
version: 3.3.4 version: 3.3.4
@ -46,9 +43,6 @@ devDependencies:
'@types/node': '@types/node':
specifier: ^20.4.8 specifier: ^20.4.8
version: 20.4.8 version: 20.4.8
'@types/prismjs':
specifier: ^1.26.0
version: 1.26.0
'@vitejs/plugin-vue': '@vitejs/plugin-vue':
specifier: ^4.2.3 specifier: ^4.2.3
version: 4.2.3(vite@4.4.8)(vue@3.3.4) version: 4.2.3(vite@4.4.8)(vue@3.3.4)
@ -73,9 +67,6 @@ devDependencies:
vite-plugin-mock: vite-plugin-mock:
specifier: ^3.0.0 specifier: ^3.0.0
version: 3.0.0(esbuild@0.18.19)(mockjs@1.1.0)(vite@4.4.8) version: 3.0.0(esbuild@0.18.19)(mockjs@1.1.0)(vite@4.4.8)
vite-plugin-prismjs:
specifier: ^0.0.8
version: 0.0.8(prismjs@1.29.0)
vue-tsc: vue-tsc:
specifier: ^1.8.8 specifier: ^1.8.8
version: 1.8.8(typescript@5.1.6) version: 1.8.8(typescript@5.1.6)
@ -708,10 +699,6 @@ packages:
resolution: {integrity: sha512-0mHckf6D2DiIAzh8fM8f3HQCvMKDpK94YQ0DSVkfWTG9BZleYIWudw9cJxX8oCk9bM+vAkDyujDV6dmKHbvQpg==} resolution: {integrity: sha512-0mHckf6D2DiIAzh8fM8f3HQCvMKDpK94YQ0DSVkfWTG9BZleYIWudw9cJxX8oCk9bM+vAkDyujDV6dmKHbvQpg==}
dev: true dev: true
/@types/prismjs@1.26.0:
resolution: {integrity: sha512-ZTaqn/qSqUuAq1YwvOFQfVW1AR/oQJlLSZVustdjwI+GZ8kr0MSHBj0tsXPW1EqHubx50gtBEjbPGsdZwQwCjQ==}
dev: true
/@types/trusted-types@2.0.3: /@types/trusted-types@2.0.3:
resolution: {integrity: sha512-NfQ4gyz38SL8sDNrSixxU2Os1a5xcdFxipAFxYEuLUlvU2uDwS4NUpsImcf1//SlWItCVMMLiylsxbmNMToV/g==} resolution: {integrity: sha512-NfQ4gyz38SL8sDNrSixxU2Os1a5xcdFxipAFxYEuLUlvU2uDwS4NUpsImcf1//SlWItCVMMLiylsxbmNMToV/g==}
dev: true dev: true
@ -930,14 +917,6 @@ packages:
picomatch: 2.3.1 picomatch: 2.3.1
dev: true dev: true
/babel-plugin-prismjs@2.1.0(prismjs@1.29.0):
resolution: {integrity: sha512-ehzSKYfeAz4U78zi/sfwsjDPlq0LvDKxNefcZTJ/iKBu+plsHsLqZhUeGf1+82LAcA35UZGbU6ksEx2Utphc/g==}
peerDependencies:
prismjs: ^1.18.0
dependencies:
prismjs: 1.29.0
dev: true
/balanced-match@1.0.2: /balanced-match@1.0.2:
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
dev: true dev: true
@ -1630,10 +1609,6 @@ packages:
picocolors: 1.0.0 picocolors: 1.0.0
source-map-js: 1.0.2 source-map-js: 1.0.2
/prismjs@1.29.0:
resolution: {integrity: sha512-Kx/1w86q/epKcmte75LNrEoT+lX8pBpavuAbvJWRXar7Hz8jrtF+e3vY751p0R8H9HdArwaCTNDDzHg/ScJK1Q==}
engines: {node: '>=6'}
/queue-microtask@1.2.3: /queue-microtask@1.2.3:
resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==}
dev: true dev: true
@ -1862,17 +1837,6 @@ packages:
- supports-color - supports-color
dev: true dev: true
/vite-plugin-prismjs@0.0.8(prismjs@1.29.0):
resolution: {integrity: sha512-mBPPMS/hwVUArdqCtp/oajZT7iq1qwJDDCciNZ3R5+Q5tQUuUHXtDKuZHYnklPLElNbENf2FyuOtC4FrgxQRAA==}
engines: {node: '>=12.0.0'}
dependencies:
'@babel/core': 7.22.15
babel-plugin-prismjs: 2.1.0(prismjs@1.29.0)
transitivePeerDependencies:
- prismjs
- supports-color
dev: true
/vite@4.4.8(@types/node@20.4.8)(sass@1.64.2): /vite@4.4.8(@types/node@20.4.8)(sass@1.64.2):
resolution: {integrity: sha512-LONawOUUjxQridNWGQlNizfKH89qPigK36XhMI7COMGztz8KNY0JHim7/xDd71CZwGT4HtSRgI7Hy+RlhG0Gvg==} resolution: {integrity: sha512-LONawOUUjxQridNWGQlNizfKH89qPigK36XhMI7COMGztz8KNY0JHim7/xDd71CZwGT4HtSRgI7Hy+RlhG0Gvg==}
engines: {node: ^14.18.0 || >=16.0.0} engines: {node: ^14.18.0 || >=16.0.0}

View file

@ -26,6 +26,9 @@ defineProps<{
const isRefreshPage = ref(false) const isRefreshPage = ref(false)
// //
watch(mode, () => {
isRefreshPage.value = !isRefreshPage.value
})
const handleRefreshPage = () => location.reload() const handleRefreshPage = () => location.reload()
</script> </script>
@ -69,8 +72,14 @@ const handleRefreshPage = () => location.reload()
</span> </span>
</Transition> </Transition>
</div> </div>
<!-- 切换按钮 --> <!-- 切换按钮 -->
<SwitchButton /> <select class="select" v-model="mode">
<option value="minimal">最小配置</option>
<option value="">默认配置</option>
<option value="essential">基本配置</option>
<option value="full">最高配置</option>
</select>
</div> </div>
</div> </div>
</Transition> </Transition>
@ -78,10 +87,11 @@ const handleRefreshPage = () => location.reload()
<style lang="scss" scoped> <style lang="scss" scoped>
.settings-menu { .settings-menu {
width: 277px;
padding: 10px; padding: 10px;
z-index: 1009; z-index: 1009;
position: absolute; position: absolute;
top: 470px; margin-bottom: 190px;
background-color: var(--kungalgame-white); background-color: var(--kungalgame-white);
border: 1px solid var(--kungalgame-blue-1); border: 1px solid var(--kungalgame-blue-1);
box-shadow: var(--shadow); box-shadow: var(--shadow);
@ -106,6 +116,8 @@ const handleRefreshPage = () => location.reload()
.editor-height { .editor-height {
margin-bottom: 20px; margin-bottom: 20px;
display: flex;
justify-content: space-between;
} }
.editor-advance { .editor-advance {
@ -126,6 +138,19 @@ const handleRefreshPage = () => location.reload()
} }
} }
//
.select {
width: 100px;
font-size: 16px;
margin-left: 20px;
color: var(--kungalgame-font-color-3);
border: 1px solid var(--kungalgame-blue-4);
background-color: var(--kungalgame-trans-white-9);
option {
background-color: var(--kungalgame-white);
}
}
.slide-up-enter-active, .slide-up-enter-active,
.slide-up-leave-active { .slide-up-leave-active {
transition: all 0.25s ease-out; transition: all 0.25s ease-out;

View file

@ -5,10 +5,11 @@ import {
ref, ref,
onBeforeMount, onBeforeMount,
onBeforeUnmount, onBeforeUnmount,
onMounted,
} from 'vue' } from 'vue'
import { QuillEditor } from '@vueup/vue-quill' import { QuillEditor } from '@vueup/vue-quill'
// quill // quill
import '@/styles/editor/editor.snow.scss' import '@/styles/editor/editor.snow.scss'
// import '@vueup/vue-quill/dist/vue-quill.bubble.css' // import '@vueup/vue-quill/dist/vue-quill.bubble.css'
@ -42,6 +43,7 @@ const { editorHeight, mode, theme, isSave, content } = storeToRefs(
* @param {boolean} isShowSettings - 是否显示编辑器设置 * @param {boolean} isShowSettings - 是否显示编辑器设置
*/ */
const props = defineProps<{ const props = defineProps<{
height?: number
isShowToolbar: boolean isShowToolbar: boolean
isShowAdvance: boolean isShowAdvance: boolean
isShowTitle: boolean isShowTitle: boolean
@ -52,7 +54,14 @@ const props = defineProps<{
const editorRef = ref() const editorRef = ref()
// //
const editorHeightStyle = computed(() => `height: ${editorHeight.value}px`) const editorHeightStyle = computed(
() => `height: ${props.height ? props.height : editorHeight.value}px`
)
//
const isShowEditorToolbar = computed(() =>
props.isShowToolbar ? 'block' : 'none'
)
// //
const valueHtml = ref('') const valueHtml = ref('')
// //
@ -67,16 +76,25 @@ const editorOptions = {
const onEditorReady = () => {} const onEditorReady = () => {}
// //
const toolbarOptions = {
container: [
['bold', 'italic', 'underline', 'strike'],
['markdown'], // Add this.
],
handlers: {
// Add this.
markdown: function () {},
},
}
// //
onBeforeMount(() => { onBeforeMount(() => {
if (isSave.value) { if (isSave.value) {
valueHtml.value = content.value valueHtml.value = content.value
} }
})
// //
onBeforeUnmount(() => {}) })
// //
const handleTextChange = () => { const handleTextChange = () => {
@ -107,7 +125,7 @@ const handleTextChange = () => {
:content="valueHtml" :content="valueHtml"
:style="editorHeightStyle" :style="editorHeightStyle"
:theme="theme" :theme="theme"
toolbar="full" :toolbar="mode"
:options="editorOptions" :options="editorOptions"
@textChange="handleTextChange" @textChange="handleTextChange"
@ready="onEditorReady" @ready="onEditorReady"
@ -136,6 +154,7 @@ const handleTextChange = () => {
background-color: var(--kungalgame-trans-blue-0); background-color: var(--kungalgame-trans-blue-0);
/* 头部下方阴影 */ /* 头部下方阴影 */
box-shadow: 0 2px 4px 0 var(--kungalgame-trans-blue-1); box-shadow: 0 2px 4px 0 var(--kungalgame-trans-blue-1);
display: v-bind(isShowEditorToolbar);
} }
/* 编辑器体的样式 */ /* 编辑器体的样式 */
@ -165,6 +184,16 @@ const handleTextChange = () => {
} }
.ql-editor { .ql-editor {
padding: 0; padding: 0;
&::-webkit-scrollbar {
display: inline;
width: 4px;
height: 0;
}
&::-webkit-scrollbar-thumb {
cursor: default;
background: var(--kungalgame-blue-4);
border-radius: 2px;
}
&::before { &::before {
left: 0; left: 0;
} }
@ -175,7 +204,7 @@ const handleTextChange = () => {
bottom: 0; bottom: 0;
transform: translateX(-20px) translateY(27px); transform: translateX(-20px) translateY(27px);
color: var(--kungalgame-trans-white-5); color: var(--kungalgame-trans-white-5);
text-shadow: 1px 1px 1px var(--kungalgame-blue-2); text-shadow: 1px 1px 1px var(--kungalgame-pink-3);
font-style: oblique; font-style: oblique;
} }
} }

View file

@ -833,7 +833,6 @@
background-color: var(--kungalgame-trans-white-2); background-color: var(--kungalgame-trans-white-2);
} }
.ql-toolbar.ql-snow { .ql-toolbar.ql-snow {
border: 1px solid var(--kungalgame-blue-1);
box-sizing: border-box; box-sizing: border-box;
font-family: 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif; font-family: 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
padding: 8px; padding: 8px;
@ -934,3 +933,12 @@
.ql-container.ql-snow { .ql-container.ql-snow {
border: 1px solid var(--kungalgame-blue-1); border: 1px solid var(--kungalgame-blue-1);
} }
/* 被 reset css 覆盖的样式 */
u {
text-decoration: underline;
}
s {
text-decoration: line-through;
}

View file

@ -1,23 +1,18 @@
<script setup lang="ts"> <script setup lang="ts">
import { onMounted } from 'vue' //
import prismjs from 'prismjs' // quill
import 'prismjs/themes/prism.css' import '@/styles/editor/editor.snow.scss'
defineProps<{ defineProps<{
content: string content: string
}>() }>()
onMounted(() => {
//
prismjs.highlightAll()
})
</script> </script>
<template> <template>
<!-- 内容区右侧的话题展示区这里富文本必须用 v-html已经确定文本经过三次处理 --> <!-- 内容区右侧的话题展示区这里富文本必须用 v-html已经确定文本经过三次处理 -->
<!-- 这里用的 v-html样式是页面刷新后才会有的所以必须动态绑定样式 --> <!-- 这里用的 v-html样式是页面刷新后才会有的所以必须动态绑定样式 -->
<div class="kungalgame-topic-content"> <div class="kungalgame-topic-content ql-container ql-snow">
<div v-html="content"></div> <div class="ql-editor ql-blank" v-html="content"></div>
</div> </div>
</template> </template>
@ -28,8 +23,8 @@ onMounted(() => {
width: calc(100% - 141px); width: calc(100% - 141px);
font-size: 15px; font-size: 15px;
padding: 17px; padding: 17px;
border-left: 1px solid var(--kungalgame-blue-1);
color: var(--kungalgame-font-color-3); color: var(--kungalgame-font-color-3);
border: none !important;
} }
.kungalgame-topic-content { .kungalgame-topic-content {
@ -56,108 +51,18 @@ onMounted(() => {
text-shadow: none; text-shadow: none;
} }
/* 下面全部是 wangEditor 原生样式 */
:deep(p, li) {
white-space: pre-wrap; /* 保留空格 */
}
:deep(blockquote) {
border-left: 8px solid var(--kungalgame-blue-1);
padding: 10px 10px;
margin: 10px 0;
background-color: var(--kungalgame-trans-blue-0);
}
:deep(pre > code) {
display: block;
padding: 10px;
}
:deep(code) {
font-family: monospace;
background-color: var(--kungalgame-trans-blue-0);
padding: 3px;
border-radius: 3px;
text-shadow: none;
box-shadow: var(--shadow);
}
:deep(table) {
border-collapse: collapse;
}
:deep(td, th) {
border: 1px solid var(--kungalgame-blue-4);
min-width: 50px;
height: 20px;
}
:deep(th) {
background-color: var(--kungalgame-trans-blue-0);
}
:deep(ul, ol) {
padding-left: 20px;
}
:deep(input[type='checkbox']) {
margin-right: 5px;
}
/**
* 过滤 prism 相关样式的代码
*/
/* 这一步把 prism 的背景过滤掉 */
:deep(pre) { :deep(pre) {
padding: 0; &::before {
border: 1px solid var(--kungalgame-blue-4); content: '< code >';
background-color: var(--kungalgame-trans-white-9); color: var(--kungalgame-font-color-0);
} background-color: var(--kungalgame-trans-white-5);
border: 1px solid var(--kungalgame-blue-1);
:deep(.token) { padding: 0 5px;
background-color: var(--kungalgame-trans-white-9); border-radius: 3px;
} position: absolute;
font-size: 17px;
:deep(.toolbar) { top: 20px;
top: 17px; right: 28px;
right: 10px;
display: flex;
& > .toolbar-item {
/* 这里直接根据 DOM 结构写的,写的不是很明了,要怪就怪写 prism 插件的人吧 hhh */
button,
& > span {
transition: all 0.2s;
box-shadow: unset;
margin-left: 10px;
border-radius: 0;
padding: 2px 5px;
}
& > span {
color: var(--kungalgame-pink-4);
border: 1px solid var(--kungalgame-pink-4);
background-color: var(--kungalgame-trans-white-5);
&:hover {
background-color: var(--kungalgame-pink-4);
color: var(--kungalgame-white);
}
}
button {
cursor: pointer;
background-color: var(--kungalgame-trans-white-9);
border: 1px solid var(--kungalgame-blue-4);
color: var(--kungalgame-blue-4);
&:hover {
background-color: var(--kungalgame-blue-4);
color: var(--kungalgame-white);
}
&:focus {
color: var(--kungalgame-pink-4);
border: 1px solid var(--kungalgame-pink-4);
background-color: var(--kungalgame-trans-white-5);
}
}
} }
} }
} }

View file

@ -55,6 +55,7 @@ const handelClosePanel = () => {
<!-- 回复的编辑器 --> <!-- 回复的编辑器 -->
<div class="content"> <div class="content">
<QuillEditor <QuillEditor
:height="200"
:is-show-toolbar="isShowAdvance" :is-show-toolbar="isShowAdvance"
:is-show-advance="false" :is-show-advance="false"
:is-show-title="false" :is-show-title="false"

View file

@ -5,42 +5,10 @@ import vue from '@vitejs/plugin-vue'
import { visualizer } from 'rollup-plugin-visualizer' import { visualizer } from 'rollup-plugin-visualizer'
// 导入 vite tsx 支持 // 导入 vite tsx 支持
import vueJsx from '@vitejs/plugin-vue-jsx' import vueJsx from '@vitejs/plugin-vue-jsx'
// 导入 prismjs 高亮
import { prismjsPlugin } from 'vite-plugin-prismjs'
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [ plugins: [vue(), visualizer() as PluginOption, vueJsx()],
vue(),
visualizer() as PluginOption,
vueJsx(),
prismjsPlugin({
// 这里和 wangEditor 适配
languages: [
'jsx',
'typescript',
'markup',
'go',
'php',
'c',
'python',
'java',
'cpp',
'csharp',
'visual-basic',
'sql',
'ruby',
'swift',
'bash',
'markdown',
'lua',
'groovy',
],
plugins: ['show-language', 'toolbar', 'copy-to-clipboard'],
theme: 'okaidia',
css: true,
}),
],
/* src 别名为 @ */ /* src 别名为 @ */
resolve: { resolve: {
alias: { alias: {