diff --git a/.vscode/settings.json b/.vscode/settings.json index d75cd8df..7fa3c0bf 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -26,6 +26,7 @@ "non-moe", "persistedstate", "Pinia", + "prismjs", "rdquo", "shinnku", "signin", diff --git a/package.json b/package.json index d1cb45a7..6014dbfe 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "dompurify": "^3.0.5", "pinia": "^2.1.6", "pinia-plugin-persistedstate": "^3.2.0", + "prismjs": "^1.29.0", "vue": "^3.3.4", "vue-i18n": "^9.2.2", "vue-router": "^4.2.4" @@ -33,6 +34,7 @@ "@iconify/vue": "^4.1.1", "@types/dompurify": "^3.0.2", "@types/node": "^20.4.8", + "@types/prismjs": "^1.26.0", "@vitejs/plugin-vue": "^4.2.3", "@vitejs/plugin-vue-jsx": "^3.0.2", "cross-env": "^7.0.3", @@ -41,6 +43,7 @@ "typescript": "^5.1.6", "vite": "^4.4.8", "vite-plugin-mock": "^3.0.0", + "vite-plugin-prismjs": "^0.0.8", "vue-tsc": "^1.8.8" }, "keywords": [ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d6ba3f51..17a013d1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,6 +26,9 @@ dependencies: pinia-plugin-persistedstate: specifier: ^3.2.0 version: 3.2.0(pinia@2.1.6) + prismjs: + specifier: ^1.29.0 + version: 1.29.0 vue: specifier: ^3.3.4 version: 3.3.4 @@ -46,6 +49,9 @@ devDependencies: '@types/node': specifier: ^20.4.8 version: 20.4.8 + '@types/prismjs': + specifier: ^1.26.0 + version: 1.26.0 '@vitejs/plugin-vue': specifier: ^4.2.3 version: 4.2.3(vite@4.4.8)(vue@3.3.4) @@ -70,6 +76,9 @@ devDependencies: vite-plugin-mock: specifier: ^3.0.0 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: specifier: ^1.8.8 version: 1.8.8(typescript@5.1.6) @@ -712,6 +721,10 @@ packages: resolution: {integrity: sha512-0mHckf6D2DiIAzh8fM8f3HQCvMKDpK94YQ0DSVkfWTG9BZleYIWudw9cJxX8oCk9bM+vAkDyujDV6dmKHbvQpg==} dev: true + /@types/prismjs@1.26.0: + resolution: {integrity: sha512-ZTaqn/qSqUuAq1YwvOFQfVW1AR/oQJlLSZVustdjwI+GZ8kr0MSHBj0tsXPW1EqHubx50gtBEjbPGsdZwQwCjQ==} + dev: true + /@types/trusted-types@2.0.3: resolution: {integrity: sha512-NfQ4gyz38SL8sDNrSixxU2Os1a5xcdFxipAFxYEuLUlvU2uDwS4NUpsImcf1//SlWItCVMMLiylsxbmNMToV/g==} dev: true @@ -1147,6 +1160,14 @@ packages: picomatch: 2.3.1 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: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} dev: true @@ -1828,7 +1849,6 @@ packages: /prismjs@1.29.0: resolution: {integrity: sha512-Kx/1w86q/epKcmte75LNrEoT+lX8pBpavuAbvJWRXar7Hz8jrtF+e3vY751p0R8H9HdArwaCTNDDzHg/ScJK1Q==} engines: {node: '>=6'} - dev: false /queue-microtask@1.2.3: resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} @@ -2069,6 +2089,17 @@ packages: - supports-color 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.10 + 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): resolution: {integrity: sha512-LONawOUUjxQridNWGQlNizfKH89qPigK36XhMI7COMGztz8KNY0JHim7/xDd71CZwGT4HtSRgI7Hy+RlhG0Gvg==} engines: {node: ^14.18.0 || >=16.0.0} diff --git a/src/components/wang-editor/EditorSettingsMenu.vue b/src/components/wang-editor/EditorSettingsMenu.vue index 73d1857b..309a7938 100644 --- a/src/components/wang-editor/EditorSettingsMenu.vue +++ b/src/components/wang-editor/EditorSettingsMenu.vue @@ -84,7 +84,7 @@ const handleRefreshPage = () => location.reload() padding: 10px; z-index: 1009; position: absolute; - bottom: 50px; + top: 470px; background-color: var(--kungalgame-white); border: 1px solid var(--kungalgame-blue-1); box-shadow: var(--shadow); diff --git a/src/components/wang-editor/WangEditor.vue b/src/components/wang-editor/WangEditor.vue index 14a725d0..2e48cc43 100644 --- a/src/components/wang-editor/WangEditor.vue +++ b/src/components/wang-editor/WangEditor.vue @@ -177,7 +177,6 @@ const handleChange = (editor: IDomEditor) => { width: 100%; margin: 0 auto; z-index: 1008; - background-color: var(--kungalgame-trans-white-2); } .toolbar { diff --git a/src/styles/editor/editor.scss b/src/styles/editor/editor.scss index 7b7973e4..8add50e2 100644 --- a/src/styles/editor/editor.scss +++ b/src/styles/editor/editor.scss @@ -22,24 +22,11 @@ u { text-decoration: underline; } -/* 设置为 none,不然黑夜模式代码块会花屏 */ -* { - text-shadow: none; -} - /* 不显示分割线 */ .w-e-bar-divider { display: none; } -a { - color: var(--kungalgame-blue-5); - border-bottom: 1.5px solid var(--kungalgame-trans-white-9); - &:hover { - border-bottom: 1.5px solid var(--kungalgame-blue-5); - } -} - :root { /* textarea - css vars */ --w-e-textarea-bg-color: var(--kungalgame-white-9); diff --git a/src/styles/html/richText.scss b/src/styles/html/richText.scss new file mode 100644 index 00000000..6a5c050c --- /dev/null +++ b/src/styles/html/richText.scss @@ -0,0 +1,71 @@ +/** + * 这是渲染 wangEditor 输出的富文本的样式 + * 需要注意的是,.kungalgame-topic-content 这个类名被全局注册了 + */ +.kungalgame-topic-content { + border-radius: 5px; + padding: 0 10px; + margin-top: 20px; + overflow-x: auto; + * { + max-width: 100%; + overflow-y: scroll; + } + + a { + color: var(--kungalgame-blue-5); + border-bottom: 1.5px solid var(--kungalgame-trans-white-9); + &:hover { + border-bottom: 1.5px solid var(--kungalgame-blue-5); + } + } + + span { + text-shadow: none; + } +} + +.kungalgame-topic-content p, +.kungalgame-topic-content li { + white-space: pre-wrap; /* 保留空格 */ +} + +.kungalgame-topic-content blockquote { + border-left: 8px solid var(--kungalgame-blue-1); + padding: 10px 10px; + margin: 10px 0; + background-color: var(--kungalgame-trans-blue-0); +} + +.kungalgame-topic-content code { + font-family: monospace; + background-color: var(--kungalgame-trans-blue-0); + padding: 3px; + border-radius: 3px; +} +.kungalgame-topic-content pre > code { + display: block; + padding: 10px; +} + +.kungalgame-topic-content table { + border-collapse: collapse; +} +.kungalgame-topic-content td, +.kungalgame-topic-content th { + border: 1px solid var(--kungalgame-blue-4); + min-width: 50px; + height: 20px; +} +.kungalgame-topic-content th { + background-color: var(--kungalgame-trans-blue-0); +} + +.kungalgame-topic-content ul, +.kungalgame-topic-content ol { + padding-left: 20px; +} + +.kungalgame-topic-content input[type='checkbox'] { + margin-right: 5px; +} diff --git a/src/views/edit/Edit.vue b/src/views/edit/Edit.vue index 866b5429..b067296c 100644 --- a/src/views/edit/Edit.vue +++ b/src/views/edit/Edit.vue @@ -50,7 +50,7 @@ import KUNGalgameFooter from '@/components/KUNGalgameFooter.vue' margin: 0 auto; /* 容器的阴影 */ box-shadow: var(--shadow); - background-color: var(--kungalgame-trans-white-5); + background-color: var(--kungalgame-trans-white-2); color: var(--kungalgame-font-color-3); border: 1px solid var(--kungalgame-blue-1); } @@ -62,8 +62,6 @@ import KUNGalgameFooter from '@/components/KUNGalgameFooter.vue' display: flex; flex-direction: column; align-items: center; - background-color: var(--kungalgame-trans-white-5); - backdrop-filter: blur(5px); } @media (max-width: 1000px) { diff --git a/src/views/edit/components/Button.vue b/src/views/edit/components/Button.vue index a2ab6ff5..ea2216d2 100644 --- a/src/views/edit/components/Button.vue +++ b/src/views/edit/components/Button.vue @@ -32,6 +32,7 @@ const checkPublish = (topicData: EditCreateTopicRequestData) => { message('Title cannot be empty!', '标题不可为空!', 'warn') return false } else if (topicData.content.trim()) { + // TODO: console.log(getPlainText(topicData.content.trim()).length) return true } else { diff --git a/src/views/topic/content/components/Content.vue b/src/views/topic/content/components/Content.vue index f7d17085..88b5d358 100644 --- a/src/views/topic/content/components/Content.vue +++ b/src/views/topic/content/components/Content.vue @@ -1,47 +1,159 @@