Skip to content

Commit

Permalink
style: apply eslint formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
YangFong committed Jul 7, 2024
1 parent 02b86da commit 5cff888
Show file tree
Hide file tree
Showing 19 changed files with 112 additions and 108 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
20 changes: 12 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
Expand Down Expand Up @@ -29,14 +29,19 @@
href="https://cdn-doocs.oss-cn-shenzhen.aliyuncs.com/gh/wechatsync/article-syncjs@latest/dist/styles.css"
/>
<!-- KaTeX CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css" integrity="sha384-n8MVd4RsNIU0tAv4ct0nTaAbDJwPJzDEaqSD1odI+WdtXRGWt2kTvGFasHpSy3SV" crossorigin="anonymous">

<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css"
integrity="sha384-n8MVd4RsNIU0tAv4ct0nTaAbDJwPJzDEaqSD1odI+WdtXRGWt2kTvGFasHpSy3SV"
crossorigin="anonymous"
/>

<style>
/**
解决公众号复制字体问题
*/
.katex .mathnormal {
font-family: "Times New Roman" !important;
font-family: 'Times New Roman' !important;
}
</style>
</head>
Expand All @@ -52,9 +57,8 @@
<script src="https://cdn-doocs.oss-cn-shenzhen.aliyuncs.com/gh/wechatsync/article-syncjs@latest/dist/main.js"></script>
<!-- 支持一下 mermaid -->
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
window.mermaid = mermaid;
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs'
mermaid.initialize({ startOnLoad: true })
window.mermaid = mermaid
</script>
</html>

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 {@}\" --",
Expand Down
2 changes: 1 addition & 1 deletion src/api/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
}
Expand Down
102 changes: 51 additions & 51 deletions src/assets/scripts/renderers/wx-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -63,11 +63,11 @@ class WxRenderer {
return `<code style="font-size: 90%; opacity: 0.6;">[${x[0]}]</code> ${x[1]}: <i>${x[2]}</i><br/>`
})
if (!footnoteArray.length) {
return ''
return ``
}
return `<h4 ${getStyles('h4')}>引用链接</h4><p ${getStyles(
'footnotes',
)}>${footnoteArray.join('\n')}</p>`
return `<h4 ${getStyles(`h4`)}>引用链接</h4><p ${getStyles(
`footnotes`,
)}>${footnoteArray.join(`\n`)}</p>`
}

this.buildAddition = () => {
Expand Down Expand Up @@ -105,123 +105,123 @@ class WxRenderer {
renderer.heading = (text, level) => {
switch (level) {
case 1:
return `<h1 ${getStyles('h1')}>${text}</h1>`
return `<h1 ${getStyles(`h1`)}>${text}</h1>`
case 2:
return `<h2 ${getStyles('h2')}>${text}</h2>`
return `<h2 ${getStyles(`h2`)}>${text}</h2>`
case 3:
return `<h3 ${getStyles('h3')}>${text}</h3>`
return `<h3 ${getStyles(`h3`)}>${text}</h3>`
default:
return `<h4 ${getStyles('h4')}>${text}</h4>`
return `<h4 ${getStyles(`h4`)}>${text}</h4>`
}
}
renderer.paragraph = (text) => {
if (text.includes('<figure') && text.includes('<img')) {
if (text.includes(`<figure`) && text.includes(`<img`)) {
return text
}
return text.replace(/ /g, '') === ''
? ''
: `<p ${getStyles('p')}>${text}</p>`
return text.replace(/ /g, ``) === ``
? ``
: `<p ${getStyles(`p`)}>${text}</p>`
}

renderer.blockquote = (text) => {
text = text.replace(/<p.*?>/g, `<p ${getStyles('blockquote_p')}>`)
return `<blockquote ${getStyles('blockquote')}>${text}</blockquote>`
text = text.replace(/<p.*?>/g, `<p ${getStyles(`blockquote_p`)}>`)
return `<blockquote ${getStyles(`blockquote`)}>${text}</blockquote>`
}
renderer.code = (text, lang = '') => {
if (lang.startsWith('mermaid')) {
renderer.code = (text, lang = ``) => {
if (lang.startsWith(`mermaid`)) {
setTimeout(() => {
window.mermaid?.run()
}, 0)
return `<center><pre class="mermaid">${text}</pre></center>`
}
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, '<br/>')
.replace(/\n/g, '<br/>')
.replace(/\r\n/g, `<br/>`)
.replace(/\n/g, `<br/>`)
.replace(/(>[^<]+)|(^[^<]+)/g, (str) => {
return str.replace(/\s/g, '&nbsp;')
return str.replace(/\s/g, `&nbsp;`)
})

return `<pre class="hljs code__pre" ${getStyles(
"code_pre"
`code_pre`,
)}><code class="language-${lang}" ${getStyles(
"code"
)}>${text}</code></pre>`;
};
`code`,
)}>${text}</code></pre>`
}
renderer.codespan = (text, lang) =>
`<code ${getStyles('codespan')}>${text}</code>`
`<code ${getStyles(`codespan`)}>${text}</code>`
renderer.listitem = text =>
`<li ${getStyles('listitem')}><span><%s/></span>${text}</li>`
`<li ${getStyles(`listitem`)}><span><%s/></span>${text}</li>`

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 `<ul ${getStyles('ul')}>${text}</ul>`
text = segments.join(`• `)
return `<ul ${getStyles(`ul`)}>${text}</ul>`
}
text = segments[0]
for (let i = 1; i < segments.length; i++) {
text = `${text + i}. ${segments[i]}`
}
return `<ol ${getStyles('ol')}>${text}</ol>`
return `<ol ${getStyles(`ol`)}>${text}</ol>`
}
renderer.image = (href, title, text) => {
const createSubText = (s) => {
if (!s) {
return ''
return ``
}

return `<figcaption ${getStyles('figcaption')}>${s}</figcaption>`
return `<figcaption ${getStyles(`figcaption`)}>${s}</figcaption>`
}
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 `<figure ${figureStyles}><img ${imgStyles} src="${href}" title="${title}" alt="${text}"/>${subText}</figure>`
}
renderer.link = (href, title, text) => {
if (href.startsWith('https://mp.weixin.qq.com')) {
if (href.startsWith(`https://mp.weixin.qq.com`)) {
return `<a href="${href}" title="${title || text}" ${getStyles(
'wx_link',
`wx_link`,
)}>${text}</a>`
}
if (href === text) {
return text
}
if (status) {
const ref = addFootnote(title || text, href)
return `<span ${getStyles('link')}>${text}<sup>[${ref}]</sup></span>`
return `<span ${getStyles(`link`)}>${text}<sup>[${ref}]</sup></span>`
}
return `<span ${getStyles('link')}>${text}</span>`
return `<span ${getStyles(`link`)}>${text}</span>`
}
renderer.strong = text =>
`<strong ${getStyles('strong')}>${text}</strong>`
`<strong ${getStyles(`strong`)}>${text}</strong>`
renderer.em = text =>
`<span style="font-style: italic;">${text}</span>`
renderer.table = (header, body) =>
`<section style="padding:0 8px;"><table class="preview-table"><thead ${getStyles(
'thead',
`thead`,
)}>${header}</thead><tbody>${body}</tbody></table></section>`
renderer.tablecell = (text, flags) =>
`<td ${getStyles('td')}>${text}</td>`
renderer.hr = () => `<hr ${getStyles('hr')}>`
`<td ${getStyles(`td`)}>${text}</td>`
renderer.hr = () => `<hr ${getStyles(`hr`)}>`
return renderer
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/CodemirrorEditor/AboutDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
default: false,
},
},
emits: ['close'],
emits: [`close`],
methods: {
onRedirect(url) {
window.open(url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
type: Object,
},
},
emits: ['close', 'post'],
emits: [`close`, `post`],
}
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default {
default: false,
},
},
emits: ['close', 'confirm'],
emits: [`close`, `confirm`],
computed: {
btnType() {
return this.nightMode ? `default` : `primary`
Expand Down
10 changes: 5 additions & 5 deletions src/components/CodemirrorEditor/EditorHeader/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
}
},
Expand Down Expand Up @@ -383,11 +383,11 @@ export default {
</span>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item @click="$emit('show-dialog-upload-img')">
<el-dropdown-item @click="$emit('showDialogUploadImg')">
<el-icon><ElIconUpload /></el-icon>
上传图片
</el-dropdown-item>
<el-dropdown-item @click="$emit('show-dialog-form')">
<el-dropdown-item @click="$emit('showDialogForm')">
<el-icon><ElIconGrid /></el-icon>
插入表格
</el-dropdown-item>
Expand Down Expand Up @@ -479,7 +479,7 @@ export default {
</span>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item @click="$emit('show-about-dialog')">
<el-dropdown-item @click="$emit('showAboutDialog')">
关于
</el-dropdown-item>
</el-dropdown-menu>
Expand Down
4 changes: 2 additions & 2 deletions src/components/CodemirrorEditor/InsertFormDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {
default: false,
},
},
emits: ['close'],
emits: [`close`],
data() {
return {
config,
Expand All @@ -33,7 +33,7 @@ export default {
methods: {
// 插入表格
insertTable() {
const cursor = this.editor.getCursor()
// const cursor = this.editor.getCursor()
const table = createTable({
data: this.tableData,
rows: this.rowNum,
Expand Down
2 changes: 1 addition & 1 deletion src/components/CodemirrorEditor/RightClickMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default {
default: 0,
},
},
emits: ['menuTick', 'closeMenu'],
emits: [`menuTick`, `closeMenu`],
data() {
return {
menu: [
Expand Down
2 changes: 1 addition & 1 deletion src/components/CodemirrorEditor/UploadImgDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default {
default: false,
},
},
emits: ['uploadImage', 'close'],
emits: [`uploadImage`, `close`],
data() {
return {
activeName: `upload`,
Expand Down
Loading

0 comments on commit 5cff888

Please sign in to comment.