@aiello/wechat-to-markdown
v1.2.9
Published
解析微信文章 URL 为 markdown
Downloads
67
Maintainers
Readme
说明
输入微信公众号地址,将其转换为 markdown 格式
English | 简体中文
返回属性
interface TurnDownResult {
success: boolean
code: number
data?: {
title?: string
author?: string
content?: string
}
msg?: string
}
基本用法
CommonJs
const transformHtml2Markdown = require('@ryan-liu/wechat-to-markdown').default
setTimeout(async () => {
const articleData = await transformHtml2Markdown('https://mp.weixin.qq.com/s/9d5DWg7YdMHPvVl-2KLH2w')
const { title, author, content } = articleData.data
console.log('title', title)
console.log('author', author)
console.log('content', content)
}, 0)
vue3
index.ts
import transformHtml2Markdown from '@ryan-liu/wechat-to-markdown'
setup() {
const getData = async () => {
const articleData = await transformHtml2Markdown(
'/api/s/9d5DWg7YdMHPvVl-2KLH2w'
)
const { title, author, content } = articleData.data
console.log('title', title)
console.log('author', author)
console.log('content', content)
}
getData()
return {}
},
vite.config.ts
...
server: {
proxy: {
'/api': {
target: 'https://mp.weixin.qq.com',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
},
},
},
...
使用到的包
cheerio (可以用 JQuery 方式操作 html 源码)
turndown-plugin-gfm (turndown 解析部分 html 元素插件)
参考
html2md (一个非常完善的 url to markdown 项目)
待做事项
- 需要支持转化后的 markdown 代码可以替换图片地址到 cdn(微信的图片会有域名限制,非 weixin 域名不可以访问图片)