I am used to taking notes or creating with Markdown. When I wanted to share it with Zhihu, I found that Zhihu did not provide good support for importing Markdown into articles. It does not support tables, and it needs to disclose pictures of accessible urls, as well as zhihu’s private formula editing function.

So there is a tool called MD2ZHIhu that converts markdown documents directly into a format that can be imported into Zhihu. There are three main conversions: formula, table and picture.

For example, the markdown source code:

| Data size | Data Set | gzip size | slimarry size | avg size | ratio | | --: | :-- | --: | :-- | --: | --: | | | 1000 rand u32: [0, 1000] | | x 824 byte | 6 bit/elt 18% | | | | 1000000 rand u32: [0, 1000000] 702 KB | | | x 5 bit/elt 15% | | | 1000000 | IPv4 DB 2 MB | | 2 MB | 16 bit/elt 50% | | | 600 |slim] [] star count | 602 byte | 832 byte | 10 bit/elt | 26% | $$ ||X{\vec {\beta }}-Y||^{2} $$ ! [](/post-res/md2zhihu/boo.jpg)Copy the code

The import effect before taking is like this:

After taking it, the import effect is… Shuang shuang shuang:

What are you waiting for? With it!!!!!! :

Install

pip install md2zhihu
Copy the code

Usage

md2zhihu your_great_work.md
Copy the code

This command converts markdown into a format that can be imported directly by zhihu article editor and stored in the default directory _md2: _MD2 /your_great_work/your_great_work.md. For example, using this example, the following conversion/upload steps will be printed:

Then import this document through zhihu editor.

The -o option can be used to adjust the output directory, for example:

md2zhihu your_great_work.md -o my_zhihu_works/
Copy the code

Features

  • Formula conversion:

    For example,

    $$
    ||X{\vec {\beta }}-Y||^{2}
    $$
    Copy the code

    A reference to the Tex rendering engine that can be directly used by Zhihu:

    <img src="https://www.zhihu.com/equation?tex=||X{\vec {\beta }}-Y||^{2}\\" alt="||X{\vec {\beta }}-Y||^{2}\\" class="ee_img tr_noresize" eeimg="1">
    Copy the code
  • Automatically identifies block formulas and inline formulas.

  • Tables: Convert markdown tables into HTML to support direct import of Zhihu.

  • Image: MD2ZHIhu uploads the image to Github and references the image in Markdown for replacement.

    • Default commands such as md2zhihu your_great_work.md require that the current working directory be a git(the authors assume that the user uses Git to save their work), and md2ZHIhu will set up a random branch to hold all the images.

    • Can also use the specified git repo to save images, for example, using the repo github.com/openacid/openacid.github.io to save pictures, the requirement is for the repo push permissions:

      md2zhihu your_great_work.md -r https://github.com/openacid/openacid.github.io.git
      Copy the code

Limitation

  • The table of Zhihu does not support markdown format in table cell. For example, hyperlinks in the table cannot be rendered and will be converted into plain text by Zhihu.

  • Md2zhihu cannot handle jekyll/ Github page function tags for example

    { % octicon mark-github height:24 % }
    Copy the code

    Will be processed as plain text. This text needs to be manually deleted or modified after being imported.

To improve the

What needs, come in and chat: flirt with me in Github discussion

{% include build_ref %}