Commit 73dc492b2a49793d945ccdae7f5c429c874f298c
1 parent
0bb9c035
feat(markdown-viewer): add new component
新增MarkdownViewer组件用于显示Markdown格式的富文本 close: #1181
Showing
6 changed files
with
82 additions
and
10 deletions
CHANGELOG.zh_CN.md
@@ -5,6 +5,7 @@ | @@ -5,6 +5,7 @@ | ||
5 | - 单元格编辑新增提交回调,将根据回调函数返回的结果来决定是否将数据提交到表格 | 5 | - 单元格编辑新增提交回调,将根据回调函数返回的结果来决定是否将数据提交到表格 |
6 | - 行编辑添加校验方法,允许只校验而不提交值,以便异步保存数据成功后才提交倒表格 | 6 | - 行编辑添加校验方法,允许只校验而不提交值,以便异步保存数据成功后才提交倒表格 |
7 | - 修复`rowClassName`属性无法和`striped`同时使用的问题 | 7 | - 修复`rowClassName`属性无法和`striped`同时使用的问题 |
8 | +- 新增组件 **MarkdownViewer** 用于显示 Markdown 格式的富文本 | ||
8 | 9 | ||
9 | ### 🐛 Bug Fixes | 10 | ### 🐛 Bug Fixes |
10 | 11 |
package.json
@@ -54,6 +54,7 @@ | @@ -54,6 +54,7 @@ | ||
54 | "print-js": "^1.6.0", | 54 | "print-js": "^1.6.0", |
55 | "qrcode": "^1.4.4", | 55 | "qrcode": "^1.4.4", |
56 | "resize-observer-polyfill": "^1.5.1", | 56 | "resize-observer-polyfill": "^1.5.1", |
57 | + "showdown": "^1.9.1", | ||
57 | "sortablejs": "^1.14.0", | 58 | "sortablejs": "^1.14.0", |
58 | "tinymce": "^5.9.2", | 59 | "tinymce": "^5.9.2", |
59 | "vditor": "^3.8.6", | 60 | "vditor": "^3.8.6", |
@@ -81,6 +82,7 @@ | @@ -81,6 +82,7 @@ | ||
81 | "@types/nprogress": "^0.2.0", | 82 | "@types/nprogress": "^0.2.0", |
82 | "@types/qrcode": "^1.4.1", | 83 | "@types/qrcode": "^1.4.1", |
83 | "@types/qs": "^6.9.7", | 84 | "@types/qs": "^6.9.7", |
85 | + "@types/showdown": "^1.9.4", | ||
84 | "@types/sortablejs": "^1.10.7", | 86 | "@types/sortablejs": "^1.10.7", |
85 | "@typescript-eslint/eslint-plugin": "^4.31.0", | 87 | "@typescript-eslint/eslint-plugin": "^4.31.0", |
86 | "@typescript-eslint/parser": "^4.31.0", | 88 | "@typescript-eslint/parser": "^4.31.0", |
src/components/Markdown/index.ts
1 | import { withInstall } from '/@/utils'; | 1 | import { withInstall } from '/@/utils'; |
2 | import markDown from './src/Markdown.vue'; | 2 | import markDown from './src/Markdown.vue'; |
3 | +import markDownViewer from './src/MarkdownViewer.vue'; | ||
3 | 4 | ||
4 | export const MarkDown = withInstall(markDown); | 5 | export const MarkDown = withInstall(markDown); |
6 | +export const MarkdownViewer = withInstall(markDownViewer); | ||
5 | export * from './src/typing'; | 7 | export * from './src/typing'; |
src/components/Markdown/src/MarkdownViewer.vue
0 → 100644
1 | +<template> | ||
2 | + <div v-html="getHtmlData" :class="$props.class" class="markdown-viewer"></div> | ||
3 | +</template> | ||
4 | + | ||
5 | +<script lang="ts" setup> | ||
6 | + import { computed } from 'vue'; | ||
7 | + import showdown from 'showdown'; | ||
8 | + | ||
9 | + const converter = new showdown.Converter(); | ||
10 | + converter.setOption('tables', true); | ||
11 | + const props = defineProps({ | ||
12 | + value: { type: String }, | ||
13 | + class: { type: String }, | ||
14 | + }); | ||
15 | + const getHtmlData = computed(() => converter.makeHtml(props.value || '')); | ||
16 | +</script> | ||
17 | + | ||
18 | +<style scoped> | ||
19 | + .markdown-viewer { | ||
20 | + width: 100%; | ||
21 | + } | ||
22 | +</style> |
src/views/demo/editor/markdown/index.vue
1 | <template> | 1 | <template> |
2 | <PageWrapper title="MarkDown组件示例"> | 2 | <PageWrapper title="MarkDown组件示例"> |
3 | - <a-button @click="toggleTheme" class="mb-2" type="primary"> 黑暗主题 </a-button> | ||
4 | - <a-button @click="clearValue" class="mb-2" type="default"> 清空内容 </a-button> | ||
5 | - <MarkDown | ||
6 | - v-model:value="value" | ||
7 | - @change="handleChange" | ||
8 | - ref="markDownRef" | ||
9 | - placeholder="这是占位文本" | ||
10 | - /> | 3 | + <div> |
4 | + <a-button @click="toggleTheme" class="mb-2" type="primary"> 黑暗主题 </a-button> | ||
5 | + <a-button @click="clearValue" class="mb-2" type="default"> 清空内容 </a-button> | ||
6 | + <MarkDown | ||
7 | + v-model:value="value" | ||
8 | + @change="handleChange" | ||
9 | + ref="markDownRef" | ||
10 | + placeholder="这是占位文本" | ||
11 | + /> | ||
12 | + </div> | ||
13 | + <div class="mt-2"> | ||
14 | + <a-card title="Markdown Viewer 组件演示"> | ||
15 | + <MarkdownViewer :value="value" /> | ||
16 | + </a-card> | ||
17 | + </div> | ||
11 | </PageWrapper> | 18 | </PageWrapper> |
12 | </template> | 19 | </template> |
13 | <script lang="ts"> | 20 | <script lang="ts"> |
14 | import { defineComponent, ref, unref } from 'vue'; | 21 | import { defineComponent, ref, unref } from 'vue'; |
15 | - import { MarkDown, MarkDownActionType } from '/@/components/Markdown'; | 22 | + import { MarkDown, MarkDownActionType, MarkdownViewer } from '/@/components/Markdown'; |
16 | import { PageWrapper } from '/@/components/Page'; | 23 | import { PageWrapper } from '/@/components/Page'; |
24 | + import { Card } from 'ant-design-vue'; | ||
17 | 25 | ||
18 | export default defineComponent({ | 26 | export default defineComponent({ |
19 | - components: { MarkDown, PageWrapper }, | 27 | + components: { MarkDown, PageWrapper, MarkdownViewer, ACard: Card }, |
20 | setup() { | 28 | setup() { |
21 | const markDownRef = ref<Nullable<MarkDownActionType>>(null); | 29 | const markDownRef = ref<Nullable<MarkDownActionType>>(null); |
22 | const valueRef = ref(` | 30 | const valueRef = ref(` |
yarn.lock
@@ -2064,6 +2064,11 @@ | @@ -2064,6 +2064,11 @@ | ||
2064 | dependencies: | 2064 | dependencies: |
2065 | "@types/node" "*" | 2065 | "@types/node" "*" |
2066 | 2066 | ||
2067 | +"@types/showdown@^1.9.4": | ||
2068 | + version "1.9.4" | ||
2069 | + resolved "https://registry.nlark.com/@types/showdown/download/@types/showdown-1.9.4.tgz?cache=0&sync_timestamp=1629709796532&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40types%2Fshowdown%2Fdownload%2F%40types%2Fshowdown-1.9.4.tgz#5385adf34143abad9309561661fa6c781d2ab962" | ||
2070 | + integrity sha1-U4Wt80FDq62TCVYWYfpseB0quWI= | ||
2071 | + | ||
2067 | "@types/sortablejs@^1.10.7": | 2072 | "@types/sortablejs@^1.10.7": |
2068 | version "1.10.7" | 2073 | version "1.10.7" |
2069 | resolved "https://registry.npmjs.org/@types/sortablejs/-/sortablejs-1.10.7.tgz#ab9039c85429f0516955ec6dbc0bb20139417b15" | 2074 | resolved "https://registry.npmjs.org/@types/sortablejs/-/sortablejs-1.10.7.tgz#ab9039c85429f0516955ec6dbc0bb20139417b15" |
@@ -10127,6 +10132,13 @@ shelljs@^0.8.3: | @@ -10127,6 +10132,13 @@ shelljs@^0.8.3: | ||
10127 | interpret "^1.0.0" | 10132 | interpret "^1.0.0" |
10128 | rechoir "^0.6.2" | 10133 | rechoir "^0.6.2" |
10129 | 10134 | ||
10135 | +showdown@^1.9.1: | ||
10136 | + version "1.9.1" | ||
10137 | + resolved "https://registry.nlark.com/showdown/download/showdown-1.9.1.tgz#134e148e75cd4623e09c21b0511977d79b5ad0ef" | ||
10138 | + integrity sha1-E04UjnXNRiPgnCGwURl315ta0O8= | ||
10139 | + dependencies: | ||
10140 | + yargs "^14.2" | ||
10141 | + | ||
10130 | side-channel@^1.0.4: | 10142 | side-channel@^1.0.4: |
10131 | version "1.0.4" | 10143 | version "1.0.4" |
10132 | resolved "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz#efce5c8fdc104ee751b25c58d4290011fa5ea2cf" | 10144 | resolved "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz#efce5c8fdc104ee751b25c58d4290011fa5ea2cf" |
@@ -12260,6 +12272,14 @@ yargs-parser@^13.1.2: | @@ -12260,6 +12272,14 @@ yargs-parser@^13.1.2: | ||
12260 | camelcase "^5.0.0" | 12272 | camelcase "^5.0.0" |
12261 | decamelize "^1.2.0" | 12273 | decamelize "^1.2.0" |
12262 | 12274 | ||
12275 | +yargs-parser@^15.0.1: | ||
12276 | + version "15.0.3" | ||
12277 | + resolved "https://registry.nlark.com/yargs-parser/download/yargs-parser-15.0.3.tgz#316e263d5febe8b38eef61ac092b33dfcc9b1115" | ||
12278 | + integrity sha1-MW4mPV/r6LOO72GsCSsz38ybERU= | ||
12279 | + dependencies: | ||
12280 | + camelcase "^5.0.0" | ||
12281 | + decamelize "^1.2.0" | ||
12282 | + | ||
12263 | yargs@^13.2.4: | 12283 | yargs@^13.2.4: |
12264 | version "13.3.2" | 12284 | version "13.3.2" |
12265 | resolved "https://registry.npmjs.org/yargs/-/yargs-13.3.2.tgz#ad7ffefec1aa59565ac915f82dccb38a9c31a2dd" | 12285 | resolved "https://registry.npmjs.org/yargs/-/yargs-13.3.2.tgz#ad7ffefec1aa59565ac915f82dccb38a9c31a2dd" |
@@ -12276,6 +12296,23 @@ yargs@^13.2.4: | @@ -12276,6 +12296,23 @@ yargs@^13.2.4: | ||
12276 | y18n "^4.0.0" | 12296 | y18n "^4.0.0" |
12277 | yargs-parser "^13.1.2" | 12297 | yargs-parser "^13.1.2" |
12278 | 12298 | ||
12299 | +yargs@^14.2: | ||
12300 | + version "14.2.3" | ||
12301 | + resolved "https://registry.nlark.com/yargs/download/yargs-14.2.3.tgz?cache=0&sync_timestamp=1628889096518&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fyargs%2Fdownload%2Fyargs-14.2.3.tgz#1a1c3edced1afb2a2fea33604bc6d1d8d688a414" | ||
12302 | + integrity sha1-Ghw+3O0a+yov6jNgS8bR2NaIpBQ= | ||
12303 | + dependencies: | ||
12304 | + cliui "^5.0.0" | ||
12305 | + decamelize "^1.2.0" | ||
12306 | + find-up "^3.0.0" | ||
12307 | + get-caller-file "^2.0.1" | ||
12308 | + require-directory "^2.1.1" | ||
12309 | + require-main-filename "^2.0.0" | ||
12310 | + set-blocking "^2.0.0" | ||
12311 | + string-width "^3.0.0" | ||
12312 | + which-module "^2.0.0" | ||
12313 | + y18n "^4.0.0" | ||
12314 | + yargs-parser "^15.0.1" | ||
12315 | + | ||
12279 | yargs@^16.0.3, yargs@^16.2.0: | 12316 | yargs@^16.0.3, yargs@^16.2.0: |
12280 | version "16.2.0" | 12317 | version "16.2.0" |
12281 | resolved "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz#1c82bf0f6b6a66eafce7ef30e376f49a12477f66" | 12318 | resolved "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz#1c82bf0f6b6a66eafce7ef30e376f49a12477f66" |