Skip to content

LuckyRyan-web/wechat-to-markdown

Repository files navigation

description

Enter the WeChat public address to convert it to markdown format

English | 简体中文

return options

interface TurnDownResult {
    success: boolean
    code: number
    data?: {
        title?: string
        author?: string
        content?: string
    }
    msg?: string
}

Basic Usage

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/, ''),
        },
    },
},
...

Packages

axios

cheerio

turndown (html to markdown)

turndown-plugin-gfm (turndown parsing partial html element plugin)

Reference

html2md (A very well developed url to markdown project)

TODO

  1. The markdown code that supports conversion can replace the image and upload it to the cdn