Skip to content

Commit 5148c55

Browse files
committed
修复知乎数学公式
1 parent 87429c4 commit 5148c55

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "markdown-downloader",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "markdown文章下载",
55
"main": "dist/index.js",
66
"scripts": {

src/markdown.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export const formatMarkdownBody = (container, selectors, options, exec) => {
117117
return markdownBody
118118
}
119119

120-
const extract = async (markdownBody, selectors, options, exec) => {
120+
const extract = async ({ markdownBody, selectors, options, exec, hook }) => {
121121
const { origin, context, localOptions = {} } = options
122122
const fileName = getText(selectors.title) || document.title
123123
const realName = fileName.replace(/[\\\/\?<>:'\*\|]/g, '_')
@@ -151,7 +151,7 @@ const extract = async (markdownBody, selectors, options, exec) => {
151151
}, localOptions.tpl)
152152
const markdownDoc = html2markdown(info + getMarkdown(markdownBody), {})
153153
const copyright = formatCopyRight({ title: fileName, url: location.href }, localOptions)
154-
const content = await exec('formatContent', { markdownBody, markdownDoc })
154+
const content = await exec(hook['formatContent'], context, { markdownBody, markdownDoc })
155155
files.push({
156156
name: realName + '.md',
157157
content: `${content && typeof content === 'string' ? content : markdownDoc}${copyright}`
@@ -178,7 +178,7 @@ export const downloadMarkdown = async (...rest) => {
178178
const markdownBody = formatMarkdownBody(container, selectors, options, exec)
179179
if (await verify('extract', { markdownBody })) return exec()
180180

181-
const { fileName, files } = await extract(markdownBody, selectors, options, exec)
181+
const { fileName, files } = await extract({ markdownBody, selectors, options, exec, hook })
182182
if (await verify('afterExtract', { fileName, files })) return exec()
183183

184184
return {

src/mathjax.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
require('mathjax/es5/tex-svg')
2-
const tex2svg = (markdownDoc) => {
1+
import 'mathjax/es5/tex-svg'
2+
export const tex2svg = (markdownDoc) => {
33
return markdownDoc.replace(/<ztext>(.*?)<\/ztext>/g, (s, s1) => {
44
const tex = decodeURIComponent(s1)
55
const svg = MathJax.tex2svg(tex)
@@ -8,6 +8,6 @@ const tex2svg = (markdownDoc) => {
88
return svg.outerHTML
99
})
1010
}
11-
Object.assign(module.exports, Object.assign(exports, {
11+
export default {
1212
tex2svg
13-
}))
13+
}

src/utils.js

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export const exec = async (...rest) => {
113113
} catch (err) {
114114
console.warn(err)
115115
}
116+
return exec.returnValue
116117
}
117118

118119
export default {

0 commit comments

Comments
 (0)