GitHub Action
md2zhihu
Converts markdown to a single-file version that has no local asset dependency and can be imported into zhihu.com with just one click.
md | imported | |
---|---|---|
original | ||
converted |
This is the recommended way since you do not need install anything locally, just
a git
is quite enough.
md2zhihu
action: https://github.com/marketplace/actions/md2zhihu
Add action definition into the git repo you have markdowns to convert:
.github/workflows/md2zhihu.yml
:
name: md2zhihu
on: [push]
jobs:
md2zhihu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: drmingdrmer/[email protected]
env:
GITHUB_USERNAME: ${{ github.repository_owner }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
pattern: >
_posts/*.md
_posts/*.markdown
The next push github converts markdowns in _posts/
and creates a new commit
that contains the converted markdowns in folder _md2zhihu
.
E.g., the single-file version of one of my blog posts: https://github.com/drmingdrmer/drmingdrmer.github.io/blob/master/_md2zhihu/dict-cmp.md
To retrieve the converted markdowns, merge branch _md2zhihu/md
,
or access the branch directly on the web:
https://github.com/drmingdrmer/drmingdrmer.github.io/blob/master/_md2zhihu/dict-cmp.md
Since all external assets are uploaded copy-paste this page will work as expected.
Action Options
-
pattern
:file pattern to convert
required: True default:
**/*.md
-
output_dir
:dir to store converted markdown
required: True default:
_md2zhihu
-
md_branch
:The branch name to push converted markdown to. A build overrides previous built branch. If you want to persist the built markdowns, merge this branch.
required: True default:
_md2zhihu/md
-
asset_branch
:The branch name in which assets are stored.
required: True default:
_md2zhihu/asset
-
target_platform
:The platform that the converted markdown should be compatible toṫCurrently supported platforms are zhihu, wechat, weibo, simple.
simple
converts almost everything to images and removes most text styles. E.g. inline code block is converted to normal text.required: True default:
zhihu
System requirement: MaxOS
# For rendering table to html
brew install pandoc imagemagick node
npm install -g @mermaid-js/mermaid-cli
pip install md2zhihu
In a git work dir:
md2zhihu your_great_work.md -r .
This command convert your_great_work.md
to _md2/your_great_work.md
.
And the assets it references are uploaded to the default git remote.
Or using another git to store assets, e.g.:
md2zhihu your_great_work.md -r [email protected]:drmingdrmer/md2test.git@test
You must have write access to the git repo
Trouble shoot
pip install --verbose md2zhihu
Confirm that install done successfully.which md2zhihu
Confirm that the binary can be found: e.g.:/Users/drdrxp/xp/py3virtual/p38/bin/md2zhihu
.echo $PATH
Confirmat that the install path is included inPATH
:...:/Users/drdrxp/xp/py3virtual/p38/bin:...
-
Transform latex to image:
E.g.
$$ ||X{\vec {\beta }}-Y||^{2} $$
is converted to<img src="https://www.zhihu.com/equation?tex=||X{\vec {\beta }}-Y||^{2}\\" ...>
-
Transform table to html.
-
Upload images.
-
Transform mermaid code block to image:
graph LR A[Hard edge] -->|Link text| B(Round edge) B --> C{Decision} C -->|One| D[Result one] C -->|Two| E[Result two]
is converted to:
-
Transform graphviz code block to image:
digraph R { node [shape=plaintext] rankdir=LR X0X0 [ label="0-0"] X0X0 -> X1X0 [ color="#aaaadd"] X0X0 -> X2X3 [ color="#aaaadd"] }
is converted to:
-
Generate link list::
original converted imported
-
zhihu.com does not support markdown syntax inside a table cell. These in-table-cell content are transformed to plain text.
-
md2zhihu can not deal with jekyll/github page tags. E.g.
{% octicon mark-github height:24 %}
.