Skip to content

Instantly share code, notes, and snippets.

@dixonsiu
Last active June 9, 2021 01:15
Show Gist options
  • Save dixonsiu/28c473f93722e586e6d53b035923967c to your computer and use it in GitHub Desktop.
Save dixonsiu/28c473f93722e586e6d53b035923967c to your computer and use it in GitHub Desktop.
How to convert markdown link to html using Pandoc

How to convert markdown link to html using Pandoc

Issue

Pandoc cannot convert a link's URL as expected.
Markdown:

[Document](./document.md)

HTML:

<a href="./document.md">Document</a>

Expected HTML:

<a href="./document.html">Document</a>

Procedures

According to ota-meshi's procedures, it is quite easy.
The following is what I did in less than 15 minutes.

  1. Down and install Pandoc

  2. Down and install Python because Panflute requies Python to run.

  3. According to Panflute's guide I executed the following command.

    • no proxy

        > pip install panflute
      
    • behind proxy

        > pip install panflute --proxy http://<user id>:<password>@<proxy address>
      
  4. I also install pypandoc so that I can avoid using external commands.

    • no proxy

        > pip install pypandoc
      
    • behind proxy

        > pip install pypandoc --proxy http://<user id>:<password>@<proxy address>
      
  5. Copy and paste the following Python files to a temp folder.

    1. convert_link.py
    2. markdown_to_html.py
  6. Move to the directory that contains markdown file(s).

  7. Execute the following command.
    By the way, this command automatically convert README.md to index.html.
      - To use Japanese CSS (/ja/github.css)  

         > python <path to the temp folder>/markdown_to_html.py --locale ja
    
    • To use English CSS (/en/github.css)

        > python <path to the temp folder>/markdown_to_html.py --locale en
      
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment