1.2.5 • Published 2 months ago

@aiello/wechat-to-markdown v1.2.5

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago

说明

输入微信公众号地址,将其转换为 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/, ''),
        },
    },
},
...

使用到的包

axios (著名的请求库)

cheerio (可以用 JQuery 方式操作 html 源码)

turndown (html to markdown)

turndown-plugin-gfm (turndown 解析部分 html 元素插件)

参考

html2md (一个非常完善的 url to markdown 项目)

待做事项

  1. 需要支持转化后的 markdown 代码可以替换图片地址到 cdn(微信的图片会有域名限制,非 weixin 域名不可以访问图片)
1.2.5

2 months ago

1.2.3

2 months ago