mirror of
https://github.com/doocs/md.git
synced 2024-10-30 15:57:50 +08:00
style: fix eslint error (#333)
This commit is contained in:
parent
bdac5c9d78
commit
a0f3bb5a67
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@ -11,12 +11,12 @@ jobs:
|
|||||||
if: github.repository == 'doocs/md'
|
if: github.repository == 'doocs/md'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
- name: Set up node
|
- name: Set up node
|
||||||
uses: actions/setup-node@v3
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 20
|
||||||
|
|
||||||
|
4
.github/workflows/preview-build.yml
vendored
4
.github/workflows/preview-build.yml
vendored
@ -10,12 +10,12 @@ jobs:
|
|||||||
if: github.repository == 'doocs/md'
|
if: github.repository == 'doocs/md'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
|
|
||||||
- name: Set up node
|
- name: Set up node
|
||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 20
|
||||||
|
|
||||||
|
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -12,7 +12,7 @@ jobs:
|
|||||||
if: github.repository == 'doocs/md'
|
if: github.repository == 'doocs/md'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- name: Create Release
|
- name: Create Release
|
||||||
id: create_release
|
id: create_release
|
||||||
uses: actions/create-release@v1
|
uses: actions/create-release@v1
|
||||||
|
@ -8,14 +8,12 @@
|
|||||||
|
|
||||||
<div align="center">
|
<div align="center">
|
||||||
|
|
||||||
[![sync status](https://github.com/doocs/md/workflows/Sync/badge.svg)](https://github.com/doocs/md/actions) [![deploy status](https://github.com/doocs/md/workflows/Build%20and%20Deploy/badge.svg)](https://github.com/doocs/md/actions) [![prettier status](https://github.com/doocs/md/workflows/Prettier/badge.svg)](https://github.com/doocs/md/actions) [![users](https://badgen.net/badge/Who's/using/green)](#谁在使用) [![PRs Welcome](https://badgen.net/badge/PRs/welcome/green)](../../pulls)<br> [![github](https://badgen.net/badge/⭐/GitHub/blue)](https://github.com/doocs/md) [![gitee](https://badgen.net/badge/⭐/Gitee/blue)](https://gitee.com/doocs/md) [![gitee](https://badgen.net/badge/⭐/GitCode/blue)](https://gitcode.com/doocs/md) [![license](https://badgen.net/github/license/doocs/md)](./LICENSE) [![release](https://img.shields.io/github/v/release/doocs/md.svg)](../../releases)
|
[![deploy status](https://github.com/doocs/md/workflows/Build%20and%20Deploy/badge.svg)](https://github.com/doocs/md/actions) [![users](https://badgen.net/badge/Who's/using/green)](#谁在使用) [![PRs Welcome](https://badgen.net/badge/PRs/welcome/green)](../../pulls)<br>[![license](https://badgen.net/github/license/doocs/md)](./LICENSE) [![github](https://badgen.net/badge/⭐/GitHub/blue)](https://github.com/doocs/md) [![gitee](https://badgen.net/badge/⭐/Gitee/blue)](https://gitee.com/doocs/md) [![gitee](https://badgen.net/badge/⭐/GitCode/blue)](https://gitcode.com/doocs/md) [![release](https://img.shields.io/github/v/release/doocs/md.svg)](../../releases)
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
## 项目介绍
|
## 项目介绍
|
||||||
|
|
||||||
> 本项目基于 [wechat-format](https://github.com/lyricat/wechat-format) 进行二次开发,感谢 [lyricat](https://github.com/lyricat) 的创意和贡献!
|
|
||||||
|
|
||||||
Markdown 文档自动即时渲染为微信图文,让你不再为微信文章排版而发愁!只要你会基本的 Markdown 语法,就能做出一篇样式简洁而又美观大方的微信图文。
|
Markdown 文档自动即时渲染为微信图文,让你不再为微信文章排版而发愁!只要你会基本的 Markdown 语法,就能做出一篇样式简洁而又美观大方的微信图文。
|
||||||
|
|
||||||
## 在线编辑器地址
|
## 在线编辑器地址
|
||||||
|
@ -115,82 +115,52 @@ export function customCssWithTemplate(jsonString, color, theme) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将CSS形式的字符串转换为JSON
|
* 将 CSS 字符串转换为 JSON 对象
|
||||||
*
|
*
|
||||||
* @param {string} css - css字符串
|
* @param {string} css - CSS 字符串
|
||||||
|
* @returns {object} - JSON 格式的 CSS
|
||||||
*/
|
*/
|
||||||
export function css2json(css) {
|
export function css2json(css) {
|
||||||
// 移除CSS所有注释
|
// 去除所有 CSS 注释
|
||||||
let open, close
|
css = css.replace(/\/\*[\s\S]*?\*\//g, ``)
|
||||||
while (
|
|
||||||
(open = css.indexOf(`/*`)) !== -1
|
|
||||||
&& (close = css.indexOf(`*/`)) !== -1
|
|
||||||
) {
|
|
||||||
css = css.substring(0, open) + css.substring(close + 2)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 初始化返回值
|
|
||||||
const json = {}
|
const json = {}
|
||||||
|
|
||||||
while (css.length > 0 && css.includes(`{`) && css.includes(`}`)) {
|
// 辅助函数:将声明数组转换为对象
|
||||||
// 存储第一个左/右花括号的下标
|
const toObject = array =>
|
||||||
|
array.reduce((obj, item) => {
|
||||||
|
const [property, value] = item.split(`:`).map(part => part.trim())
|
||||||
|
if (property)
|
||||||
|
obj[property] = value
|
||||||
|
return obj
|
||||||
|
}, {})
|
||||||
|
|
||||||
|
while (css.includes(`{`) && css.includes(`}`)) {
|
||||||
const lbracket = css.indexOf(`{`)
|
const lbracket = css.indexOf(`{`)
|
||||||
const rbracket = css.indexOf(`}`)
|
const rbracket = css.indexOf(`}`)
|
||||||
|
|
||||||
// 第一步:将声明转换为Object,如:
|
// 获取声明块并转换为对象
|
||||||
// `font: 'Times New Roman' 1em; color: #ff0000; margin-top: 1em;`
|
const declarations = css.substring(lbracket + 1, rbracket)
|
||||||
// ==>
|
|
||||||
// `{"font": "'Times New Roman' 1em", "color": "#ff0000", "margin-top": "1em"}`
|
|
||||||
|
|
||||||
// 辅助方法:将array转为object
|
|
||||||
|
|
||||||
function toObject(array) {
|
|
||||||
const ret = {}
|
|
||||||
array.forEach((e) => {
|
|
||||||
const index = e.indexOf(`:`)
|
|
||||||
const property = e.substring(0, index).trim()
|
|
||||||
ret[property] = e.substring(index + 1).trim()
|
|
||||||
})
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
// 切割声明块并移除空白符,然后放入数组中
|
|
||||||
let declarations = css
|
|
||||||
.substring(lbracket + 1, rbracket)
|
|
||||||
.split(`;`)
|
.split(`;`)
|
||||||
.map(e => e.trim())
|
.map(e => e.trim())
|
||||||
.filter(e => e.length > 0) // 移除所有""空值
|
.filter(Boolean)
|
||||||
|
|
||||||
// 转为Object对象
|
// 获取选择器并去除空格
|
||||||
declarations = toObject(declarations)
|
const selectors = css.substring(0, lbracket)
|
||||||
|
|
||||||
// 第二步:选择器处理,每个选择器会与它对应的声明相关联,如:
|
|
||||||
// `h1, p#bar {color: red}`
|
|
||||||
// ==>
|
|
||||||
// {"h1": {color: red}, "p#bar": {color: red}}
|
|
||||||
|
|
||||||
const selectors = css
|
|
||||||
.substring(0, lbracket)
|
|
||||||
// 以,切割,并移除空格:`"h1, p#bar, span.foo"` => ["h1", "p#bar", "span.foo"]
|
|
||||||
.split(`,`)
|
.split(`,`)
|
||||||
.map(selector => selector.trim())
|
.map(selector => selector.trim())
|
||||||
|
|
||||||
// 迭代赋值
|
const declarationObj = toObject(declarations)
|
||||||
|
|
||||||
|
// 将声明对象关联到相应的选择器
|
||||||
selectors.forEach((selector) => {
|
selectors.forEach((selector) => {
|
||||||
// 若不存在,则先初始化
|
json[selector] = { ...(json[selector] || {}), ...declarationObj }
|
||||||
if (!json[selector])
|
|
||||||
json[selector] = {}
|
|
||||||
// 赋值到JSON
|
|
||||||
Object.keys(declarations).forEach((key) => {
|
|
||||||
json[selector][key] = declarations[key]
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// 继续下个声明块
|
// 处理下一个声明块
|
||||||
css = css.slice(rbracket + 1).trim()
|
css = css.slice(rbracket + 1).trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 返回JSON形式的结果串
|
|
||||||
return json
|
return json
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,7 +328,7 @@ export function toBase64(file) {
|
|||||||
|
|
||||||
export function checkImage(file) {
|
export function checkImage(file) {
|
||||||
// 检查文件名后缀
|
// 检查文件名后缀
|
||||||
const isValidSuffix = /\.(gif|jpe?g|png)$/i.test(file.name)
|
const isValidSuffix = /\.(?:gif|jpe?g|png)$/i.test(file.name)
|
||||||
if (!isValidSuffix) {
|
if (!isValidSuffix) {
|
||||||
return {
|
return {
|
||||||
ok: false,
|
ok: false,
|
||||||
|
@ -1,33 +1,36 @@
|
|||||||
export function utf16to8(str) {
|
export function utf16to8(str) {
|
||||||
let out, i, len, c
|
let out = ``
|
||||||
out = ``
|
const len = str.length
|
||||||
len = str.length
|
|
||||||
for (i = 0; i < len; i++) {
|
for (let i = 0; i < len; i++) {
|
||||||
c = str.charCodeAt(i)
|
const c = str.charCodeAt(i)
|
||||||
|
|
||||||
if (c >= 0x0001 && c <= 0x007F) {
|
if (c >= 0x0001 && c <= 0x007F) {
|
||||||
out += str.charAt(i)
|
out += str.charAt(i)
|
||||||
}
|
}
|
||||||
else if (c > 0x07FF) {
|
else if (c > 0x07FF) {
|
||||||
out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F))
|
out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F))
|
||||||
out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F))
|
out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F))
|
||||||
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F))
|
out += String.fromCharCode(0x80 | (c & 0x3F))
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F))
|
out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F))
|
||||||
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F))
|
out += String.fromCharCode(0x80 | (c & 0x3F))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
export function utf8to16(str) {
|
export function utf8to16(str) {
|
||||||
let out, i, len, c
|
let out = ``
|
||||||
let char2, char3
|
let i = 0
|
||||||
out = ``
|
const len = str.length
|
||||||
len = str.length
|
|
||||||
i = 0
|
|
||||||
while (i < len) {
|
while (i < len) {
|
||||||
c = str.charCodeAt(i++)
|
const c = str.charCodeAt(i++)
|
||||||
|
let char2, char3
|
||||||
|
|
||||||
switch (c >> 4) {
|
switch (c >> 4) {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
@ -51,11 +54,12 @@ export function utf8to16(str) {
|
|||||||
char2 = str.charCodeAt(i++)
|
char2 = str.charCodeAt(i++)
|
||||||
char3 = str.charCodeAt(i++)
|
char3 = str.charCodeAt(i++)
|
||||||
out += String.fromCharCode(
|
out += String.fromCharCode(
|
||||||
((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0),
|
((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | (char3 & 0x3F),
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,77 +197,89 @@ const base64DecodeChars = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
export function base64encode(str) {
|
export function base64encode(str) {
|
||||||
let out, i, len
|
let out = ``
|
||||||
let c1, c2, c3
|
let i = 0
|
||||||
len = str.length
|
const len = str.length
|
||||||
i = 0
|
|
||||||
out = ``
|
|
||||||
while (i < len) {
|
while (i < len) {
|
||||||
c1 = str.charCodeAt(i++) & 0xFF
|
const c1 = str.charCodeAt(i++) & 0xFF
|
||||||
if (i == len) {
|
|
||||||
|
if (i === len) {
|
||||||
out += base64EncodeChars.charAt(c1 >> 2)
|
out += base64EncodeChars.charAt(c1 >> 2)
|
||||||
out += base64EncodeChars.charAt((c1 & 0x3) << 4)
|
out += base64EncodeChars.charAt((c1 & 0x3) << 4)
|
||||||
out += `==`
|
out += `==`
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
c2 = str.charCodeAt(i++)
|
|
||||||
if (i == len) {
|
const c2 = str.charCodeAt(i++)
|
||||||
|
|
||||||
|
if (i === len) {
|
||||||
out += base64EncodeChars.charAt(c1 >> 2)
|
out += base64EncodeChars.charAt(c1 >> 2)
|
||||||
out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4))
|
out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4))
|
||||||
out += base64EncodeChars.charAt((c2 & 0xF) << 2)
|
out += base64EncodeChars.charAt((c2 & 0xF) << 2)
|
||||||
out += `=`
|
out += `=`
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
c3 = str.charCodeAt(i++)
|
|
||||||
|
const c3 = str.charCodeAt(i++)
|
||||||
|
|
||||||
out += base64EncodeChars.charAt(c1 >> 2)
|
out += base64EncodeChars.charAt(c1 >> 2)
|
||||||
out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4))
|
out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4))
|
||||||
out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6))
|
out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6))
|
||||||
out += base64EncodeChars.charAt(c3 & 0x3F)
|
out += base64EncodeChars.charAt(c3 & 0x3F)
|
||||||
}
|
}
|
||||||
|
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
export function base64decode(str) {
|
export function base64decode(str) {
|
||||||
let c1, c2, c3, c4
|
let c1, c2, c3, c4
|
||||||
let i, len, out
|
let i = 0
|
||||||
len = str.length
|
const len = str.length
|
||||||
i = 0
|
let out = ``
|
||||||
out = ``
|
|
||||||
while (i < len) {
|
while (i < len) {
|
||||||
/* c1 */
|
/* c1 */
|
||||||
do {
|
do {
|
||||||
c1 = base64DecodeChars[str.charCodeAt(i++) & 0xFF]
|
c1 = base64DecodeChars[str.charCodeAt(i++) & 0xFF]
|
||||||
} while (i < len && c1 == -1)
|
} while (i < len && c1 === -1)
|
||||||
if (c1 == -1)
|
if (c1 === -1)
|
||||||
break
|
break
|
||||||
|
|
||||||
/* c2 */
|
/* c2 */
|
||||||
do {
|
do {
|
||||||
c2 = base64DecodeChars[str.charCodeAt(i++) & 0xFF]
|
c2 = base64DecodeChars[str.charCodeAt(i++) & 0xFF]
|
||||||
} while (i < len && c2 == -1)
|
} while (i < len && c2 === -1)
|
||||||
if (c2 == -1)
|
if (c2 === -1)
|
||||||
break
|
break
|
||||||
|
|
||||||
out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4))
|
out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4))
|
||||||
|
|
||||||
/* c3 */
|
/* c3 */
|
||||||
do {
|
do {
|
||||||
c3 = str.charCodeAt(i++) & 0xFF
|
c3 = str.charCodeAt(i++) & 0xFF
|
||||||
if (c3 == 61)
|
if (c3 === 61)
|
||||||
return out
|
return out
|
||||||
c3 = base64DecodeChars[c3]
|
c3 = base64DecodeChars[c3]
|
||||||
} while (i < len && c3 == -1)
|
} while (i < len && c3 === -1)
|
||||||
if (c3 == -1)
|
if (c3 === -1)
|
||||||
break
|
break
|
||||||
|
|
||||||
out += String.fromCharCode(((c2 & 0xF) << 4) | ((c3 & 0x3C) >> 2))
|
out += String.fromCharCode(((c2 & 0xF) << 4) | ((c3 & 0x3C) >> 2))
|
||||||
|
|
||||||
/* c4 */
|
/* c4 */
|
||||||
do {
|
do {
|
||||||
c4 = str.charCodeAt(i++) & 0xFF
|
c4 = str.charCodeAt(i++) & 0xFF
|
||||||
if (c4 == 61)
|
if (c4 === 61)
|
||||||
return out
|
return out
|
||||||
c4 = base64DecodeChars[c4]
|
c4 = base64DecodeChars[c4]
|
||||||
} while (i < len && c4 == -1)
|
} while (i < len && c4 === -1)
|
||||||
if (c4 == -1)
|
if (c4 === -1)
|
||||||
break
|
break
|
||||||
|
|
||||||
out += String.fromCharCode(((c3 & 0x03) << 6) | c4)
|
out += String.fromCharCode(((c3 & 0x03) << 6) | c4)
|
||||||
}
|
}
|
||||||
|
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user