Skip to content

Commit

Permalink
修复知乎数学公式
Browse files Browse the repository at this point in the history
  • Loading branch information
kscript committed Sep 19, 2024
1 parent 87429c4 commit 5148c55
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "markdown-downloader",
"version": "2.0.0",
"version": "2.0.1",
"description": "markdown文章下载",
"main": "dist/index.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions src/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const formatMarkdownBody = (container, selectors, options, exec) => {
return markdownBody
}

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

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

return {
Expand Down
8 changes: 4 additions & 4 deletions src/mathjax.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require('mathjax/es5/tex-svg')
const tex2svg = (markdownDoc) => {
import 'mathjax/es5/tex-svg'
export const tex2svg = (markdownDoc) => {
return markdownDoc.replace(/<ztext>(.*?)<\/ztext>/g, (s, s1) => {
const tex = decodeURIComponent(s1)
const svg = MathJax.tex2svg(tex)
Expand All @@ -8,6 +8,6 @@ const tex2svg = (markdownDoc) => {
return svg.outerHTML
})
}
Object.assign(module.exports, Object.assign(exports, {
export default {
tex2svg
}))
}
1 change: 1 addition & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export const exec = async (...rest) => {
} catch (err) {
console.warn(err)
}
return exec.returnValue
}

export default {
Expand Down

0 comments on commit 5148c55

Please sign in to comment.