preface

Markdown is a very powerful and syntactically concise markup language. We ** (especially technologists) ** prefer it for writing documents, blogs, articles, etc.

Some platforms, such as Nuggets and CSDN, are heavily used by technicians, so their editors support MarkDown, while some platforms, such as wechat and Zhihu, are not so friendly to Markdown users.

Some tools can parse markdown into HTML compatible with these platforms, such as MDnice.

But if you’re not the author of an article that’s already been published and you want to retweet or borrow a paragraph from it, typography may cause you to scratch your head. It would be nice to have an HTML converter that works on all platforms.

Based on this problem, we investigated some HTML-to-Markdown tools and found that they didn’t work very well in practice, so we developed Sitdown ourselves.

usage

Non-development environment

If you just want to get things done quickly, you can just go to our Demo page.

  1. Paste the source HTML into the input box on the left.

  2. Select the platform from which the HTML is sourced.

  3. Click on the transform. The transformation markdown is generated in the box on the right and copied to your clipboard at the same time.

The development environment

// Node
var { Sitdown } = require('sitdown')

var sitdown = new Sitdown()
var markdown = sitdown.HTMLToMD('your HTML')
Copy the code
// ES
import { Sitdown } from 'sitdown/src.esm'

var sitdown = new Sitdown()
var markdown = sitdown.HTMLToMD('your HTML')
Copy the code

If you want to convert HTML for a platform, you can use plug-ins:

Such as:

import { Sitdown } from 'sitdown/src.esm';
import { applyJuejinRule } from '@sitdown/juejin/src.esm';

let sitdown = new Sitdown({
      keepFilter: ['style'],
      codeBlockStyle: 'fenced',
      bulletListMarker: The '-',
      hr: The '-'}); sitdown.use(applyJuejinRule);Copy the code

Use with MDnice

Mdnice is a markdown to HTML artifact. Markdown can generate wechat HTML and Zhihu HTML for various topics through its transformation.

It integrates directly with SitDown:

conclusion

This library also draws on the ideas of the open source community and some code libraries, some details still need to be improved and improved. So it’s also MIT protocol, so if you’re interested in mdNICE related projects, you’re welcome to make pr contributions.