diff --git a/index.html b/index.html
index d0105fc..2876afd 100644
--- a/index.html
+++ b/index.html
@@ -3,23 +3,14 @@
-
-
+
+
微信 Markdown 编辑器 | Doocs 开源社区
-
+
{
// 更新编辑器
const editorRefresh = () => {
codeThemeChange()
-
- const renderer = wxRenderer.getRenderer(isCiteStatus.value)
+ const renderer = wxRenderer
+ renderer.reset()
+ renderer.setOptions({ status: isCiteStatus.value, legend: legend.value })
marked.setOptions({ renderer })
let outputTemp = marked.parse(editor.value.getValue(0))
diff --git a/src/utils/wx-renderer.js b/src/utils/wx-renderer.js
index 9a4b39d..16108e1 100644
--- a/src/utils/wx-renderer.js
+++ b/src/utils/wx-renderer.js
@@ -2,230 +2,211 @@ import { Renderer, marked } from 'marked'
import hljs from 'highlight.js'
import markedKatex from 'marked-katex-extension'
-marked.use(markedKatex({
- throwOnError: false,
- output: `html`,
- nonStandard: true,
-}))
+marked.use(
+ markedKatex({
+ throwOnError: false,
+ output: `html`,
+ nonStandard: true,
+ }),
+)
-class WxRenderer {
+class WxRenderer extends Renderer {
constructor(opts) {
+ super()
this.opts = opts
- let footnotes = []
- let footnoteIndex = 0
- let styleMapping = new Map()
-
- const merge = (base, extend) => Object.assign({}, base, extend)
-
- this.buildTheme = (themeTpl) => {
- const mapping = {}
- const base = merge(themeTpl.BASE, {
- 'font-family': this.opts.fonts,
- 'font-size': this.opts.size,
- })
- for (const ele in themeTpl.inline) {
- if (Object.prototype.hasOwnProperty.call(themeTpl.inline, ele)) {
- const style = themeTpl.inline[ele]
- mapping[ele] = merge(themeTpl.BASE, style)
- }
- }
-
- const base_block = merge(base, {})
- for (const ele in themeTpl.block) {
- if (Object.prototype.hasOwnProperty.call(themeTpl.block, ele)) {
- const style = themeTpl.block[ele]
- mapping[ele] = merge(base_block, style)
- }
- }
- return mapping
- }
-
- const getStyles = (tokenName, addition) => {
- const arr = []
- const dict = styleMapping[tokenName]
- if (!dict)
- return ``
- for (const key in dict) {
- arr.push(`${key}:${dict[key]}`)
- }
- return `style="${arr.join(`;`) + (addition || ``)}"`
- }
-
- const addFootnote = (title, link) => {
- footnotes.push([++footnoteIndex, title, link])
- return footnoteIndex
- }
-
- this.buildFootnotes = () => {
- const footnoteArray = footnotes.map((x) => {
- if (x[1] === x[2]) {
- return `[${x[0]}]
: ${x[1]}
`
- }
- return `[${x[0]}]
${x[1]}: ${x[2]}
`
- })
- if (!footnoteArray.length) {
- return ``
- }
- return `引用链接
${footnoteArray.join(`\n`)}
`
- }
-
- this.buildAddition = () => {
- return `
-
- `
- }
-
- this.setOptions = (newOpts) => {
- this.opts = merge(this.opts, newOpts)
- }
-
- this.hasFootnotes = () => footnotes.length !== 0
-
- this.getRenderer = (status) => {
- footnotes = []
- footnoteIndex = 0
-
- styleMapping = this.buildTheme(this.opts.theme)
- const renderer = new Renderer()
-
- renderer.heading = (text, level) => {
- switch (level) {
- case 1:
- return `${text}
`
- case 2:
- return `${text}
`
- case 3:
- return `${text}
`
- default:
- return `${text}
`
- }
- }
- renderer.paragraph = (text) => {
- if (text.includes(`