From 5cff888050e09220c4ca06fb5663b825302b82ca Mon Sep 17 00:00:00 2001 From: YangFong Date: Sun, 7 Jul 2024 10:26:59 +0800 Subject: [PATCH] style: apply eslint formatting --- README.md | 16 +-- index.html | 20 ++-- package.json | 4 +- src/api/fetch.js | 2 +- src/assets/scripts/renderers/wx-renderer.js | 102 +++++++++--------- .../CodemirrorEditor/AboutDialog.vue | 2 +- .../EditorHeader/PostInfoDialog.vue | 2 +- .../EditorHeader/ResetDialog.vue | 2 +- .../CodemirrorEditor/EditorHeader/index.vue | 10 +- .../CodemirrorEditor/InsertFormDialog.vue | 4 +- .../CodemirrorEditor/RightClickMenu.vue | 2 +- .../CodemirrorEditor/UploadImgDialog.vue | 2 +- src/element/index.js | 2 +- src/main.js | 2 +- src/views/CodemirrorEditor.vue | 10 +- tsconfig.app.json | 24 ++--- tsconfig.json | 4 +- tsconfig.node.json | 6 +- vite.config.ts | 4 +- 19 files changed, 112 insertions(+), 108 deletions(-) diff --git a/README.md b/README.md index 43cc2ea75..c609247ac 100644 --- a/README.md +++ b/README.md @@ -76,19 +76,19 @@ Markdown 文档自动即时渲染为微信图文,让你不再为微信文章 示例代码: ```js -const { file, util, okCb, errCb } = CUSTOM_ARG; -const param = new FormData(); -param.append("file", file); +const { file, util, okCb, errCb } = CUSTOM_ARG +const param = new FormData() +param.append(`file`, file) util.axios - .post("http://127.0.0.1:9000/upload", param, { - headers: { "Content-Type": "multipart/form-data" }, + .post(`http://127.0.0.1:9000/upload`, param, { + headers: { 'Content-Type': `multipart/form-data` }, }) .then((res) => { - okCb(res.url); + okCb(res.url) }) .catch((err) => { - errCb(err); - }); + errCb(err) + }) // 提供的可用参数: // CUSTOM_ARG = { diff --git a/index.html b/index.html index 252dc4268..e479504ea 100644 --- a/index.html +++ b/index.html @@ -1,4 +1,4 @@ - + @@ -29,14 +29,19 @@ href="https://cdn-doocs.oss-cn-shenzhen.aliyuncs.com/gh/wechatsync/article-syncjs@latest/dist/styles.css" /> - - + + @@ -52,9 +57,8 @@ - diff --git a/package.json b/package.json index f7caf80ee..75e9cb02c 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "md", - "private": false, - "version": "1.6.0", "type": "module", + "version": "1.6.0", + "private": false, "scripts": { "dev": "vite --host", "build": "run-p type-check \"build:only {@}\" --", diff --git a/src/api/fetch.js b/src/api/fetch.js index cd33ad0b4..4ea31a6e0 100644 --- a/src/api/fetch.js +++ b/src/api/fetch.js @@ -8,7 +8,7 @@ const service = axios.create({ service.interceptors.request.use( (config) => { - if (/^(post)|(put)|(delete)$/i.test(config.method)) { + if (/^(?:post|put|delete)$/i.test(config.method)) { if (config.data && config.data.upload) { config.headers[`Content-Type`] = `multipart/form-data` } diff --git a/src/assets/scripts/renderers/wx-renderer.js b/src/assets/scripts/renderers/wx-renderer.js index 5b3577180..a1611f3c2 100644 --- a/src/assets/scripts/renderers/wx-renderer.js +++ b/src/assets/scripts/renderers/wx-renderer.js @@ -43,11 +43,11 @@ class WxRenderer { const arr = [] const dict = styleMapping[tokenName] if (!dict) - return '' + return `` for (const key in dict) { arr.push(`${key}:${dict[key]}`) } - return `style="${arr.join(';') + (addition || '')}"` + return `style="${arr.join(`;`) + (addition || ``)}"` } const addFootnote = (title, link) => { @@ -63,11 +63,11 @@ class WxRenderer { return `[${x[0]}] ${x[1]}: ${x[2]}
` }) if (!footnoteArray.length) { - return '' + return `` } - return `

引用链接

${footnoteArray.join('\n')}

` + return `

引用链接

${footnoteArray.join(`\n`)}

` } this.buildAddition = () => { @@ -105,101 +105,101 @@ class WxRenderer { renderer.heading = (text, level) => { switch (level) { case 1: - return `

${text}

` + return `

${text}

` case 2: - return `

${text}

` + return `

${text}

` case 3: - return `

${text}

` + return `

${text}

` default: - return `

${text}

` + return `

${text}

` } } renderer.paragraph = (text) => { - if (text.includes('${text}

` + return text.replace(/ /g, ``) === `` + ? `` + : `

${text}

` } renderer.blockquote = (text) => { - text = text.replace(//g, `

`) - return `

${text}
` + text = text.replace(//g, `

`) + return `

${text}
` } - renderer.code = (text, lang = '') => { - if (lang.startsWith('mermaid')) { + renderer.code = (text, lang = ``) => { + if (lang.startsWith(`mermaid`)) { setTimeout(() => { window.mermaid?.run() }, 0) return `
${text}
` } - lang = lang.split(' ')[0] - lang = hljs.getLanguage(lang) ? lang : 'plaintext' + lang = lang.split(` `)[0] + lang = hljs.getLanguage(lang) ? lang : `plaintext` text = hljs.highlight(text, { language: lang }).value text = text - .replace(/\r\n/g, '
') - .replace(/\n/g, '
') + .replace(/\r\n/g, `
`) + .replace(/\n/g, `
`) .replace(/(>[^<]+)|(^[^<]+)/g, (str) => { - return str.replace(/\s/g, ' ') + return str.replace(/\s/g, ` `) }) return `
${text}
`; - }; + `code`, + )}>${text}` + } renderer.codespan = (text, lang) => - `${text}` + `${text}` renderer.listitem = text => - `
  • <%s/>${text}
  • ` + `
  • <%s/>${text}
  • ` renderer.list = (text, ordered, start) => { - text = text.replace(/<\/*p .*?>/g, '').replace(/<\/*p>/g, '') + text = text.replace(/<\/*p .*?>/g, ``).replace(/<\/*p>/g, ``) const segments = text.split(`<%s/>`) if (!ordered) { - text = segments.join('• ') - return `
      ${text}
    ` + text = segments.join(`• `) + return `
      ${text}
    ` } text = segments[0] for (let i = 1; i < segments.length; i++) { text = `${text + i}. ${segments[i]}` } - return `
      ${text}
    ` + return `
      ${text}
    ` } renderer.image = (href, title, text) => { const createSubText = (s) => { if (!s) { - return '' + return `` } - return `
    ${s}
    ` + return `
    ${s}
    ` } const transform = (title, alt) => { - const legend = localStorage.getItem('legend') + const legend = localStorage.getItem(`legend`) switch (legend) { - case 'alt': + case `alt`: return alt - case 'title': + case `title`: return title - case 'alt-title': + case `alt-title`: return alt || title - case 'title-alt': + case `title-alt`: return title || alt default: - return '' + return `` } } const subText = createSubText(transform(title, text)) - const figureStyles = getStyles('figure') - const imgStyles = getStyles('image') + const figureStyles = getStyles(`figure`) + const imgStyles = getStyles(`image`) return `
    ${text}${subText}
    ` } renderer.link = (href, title, text) => { - if (href.startsWith('https://mp.weixin.qq.com')) { + if (href.startsWith(`https://mp.weixin.qq.com`)) { return `${text}` } if (href === text) { @@ -207,21 +207,21 @@ class WxRenderer { } if (status) { const ref = addFootnote(title || text, href) - return `${text}[${ref}]` + return `${text}[${ref}]` } - return `${text}` + return `${text}` } renderer.strong = text => - `${text}` + `${text}` renderer.em = text => `${text}` renderer.table = (header, body) => `
    ${header}${body}
    ` renderer.tablecell = (text, flags) => - `${text}` - renderer.hr = () => `
    ` + `${text}` + renderer.hr = () => `
    ` return renderer } } diff --git a/src/components/CodemirrorEditor/AboutDialog.vue b/src/components/CodemirrorEditor/AboutDialog.vue index b12426c50..4bf82c0ac 100644 --- a/src/components/CodemirrorEditor/AboutDialog.vue +++ b/src/components/CodemirrorEditor/AboutDialog.vue @@ -6,7 +6,7 @@ export default { default: false, }, }, - emits: ['close'], + emits: [`close`], methods: { onRedirect(url) { window.open(url) diff --git a/src/components/CodemirrorEditor/EditorHeader/PostInfoDialog.vue b/src/components/CodemirrorEditor/EditorHeader/PostInfoDialog.vue index 9390e3eda..b68bc9fb7 100644 --- a/src/components/CodemirrorEditor/EditorHeader/PostInfoDialog.vue +++ b/src/components/CodemirrorEditor/EditorHeader/PostInfoDialog.vue @@ -6,7 +6,7 @@ export default { type: Object, }, }, - emits: ['close', 'post'], + emits: [`close`, `post`], } diff --git a/src/components/CodemirrorEditor/EditorHeader/ResetDialog.vue b/src/components/CodemirrorEditor/EditorHeader/ResetDialog.vue index 49954eb51..c461c85d4 100644 --- a/src/components/CodemirrorEditor/EditorHeader/ResetDialog.vue +++ b/src/components/CodemirrorEditor/EditorHeader/ResetDialog.vue @@ -9,7 +9,7 @@ export default { default: false, }, }, - emits: ['close', 'confirm'], + emits: [`close`, `confirm`], computed: { btnType() { return this.nightMode ? `default` : `primary` diff --git a/src/components/CodemirrorEditor/EditorHeader/index.vue b/src/components/CodemirrorEditor/EditorHeader/index.vue index 07b290ace..1d428983f 100644 --- a/src/components/CodemirrorEditor/EditorHeader/index.vue +++ b/src/components/CodemirrorEditor/EditorHeader/index.vue @@ -18,7 +18,7 @@ export default { StyleOptionMenu, ResetDialog, }, - emits: ['refresh', 'startCopy', 'endCopy', 'showCssEditor', 'cssChanged', 'import-md', 'download', 'export', 'show-dialog-upload-img', 'show-dialog-form', 'show-about-dialog'], + emits: [`refresh`, `startCopy`, `endCopy`, `showCssEditor`, `cssChanged`, `importMd`, `download`, `export`, `showDialogUploadImg`, `showDialogForm`, `showAboutDialog`], data() { return { config, @@ -105,7 +105,7 @@ export default { const read = new FileReader() read.readAsText(file) read.onload = () => { - this.$emit(`import-md`, read.result) + this.$emit(`importMd`, read.result) } } }, @@ -383,11 +383,11 @@ export default {