Markdown to HTML converter

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
siberia-man
Posts: 178
Joined: 26 Dec 2013 09:28
Contact:

Markdown to HTML converter

#1 Post by siberia-man » 11 Sep 2021 15:37

Earlier jfl implemented his own batch script which converts markdown to HTML sending requests towards GitHub or another API with curl. His script is published in thread A dual Batch+CSS script to convert Markdown to HTML. Since that time I kept hope to combine both ways -- using local pandoc and requesting Git API using curl or wget.

After all I finished my attempts on implementing the own script (the set of scripts on shell, batch and perl, in fact) converting markdown to HTML. Initially they were two -- shell and batch both using pandoc. There are three scripts now attempting to establish almost the same result.

Perl uses Text::Markdown for local conversion and HTTP::Tiny to query API.

Shell and batch scripts invoke pandoc for local use and curl or wget to convert remotely (via API).

If a server requires a token it can be provided with the -t TOKEN-FILE or -T TOKEN options.

Convert locally:

Code: Select all

git-md-html README.md
Convert remotely using git API

Code: Select all

git-md-html -u README.md
All scripts are located on my GitHub at https://github.com/ildar-shaimordanov/git-markdown-html

siberia-man
Posts: 178
Joined: 26 Dec 2013 09:28
Contact:

Re: Markdown to HTML converter

#2 Post by siberia-man » 12 Sep 2021 00:40

More words about some circumstances having to do with particular implementations.

Because of its limitation, the batch script accepts the -u/-U and -t/-T options in this order exactly. It can be changed to enable an arbitrary order but makes the script more complicated. Right now I don't want to do this work.

The shell version doesn't have this limitation. Also it's POSIX-ly compatible. But in some cases it fails:
-- wget from BusyBox 1.34 doesn't support the --post-file option
-- wget 1.11.4 from Gow (The lightweight alternative to Cygwin) fails with SSL connections
-- wget 1.8.2 from UnxUtils doesn't support both --post-data and --no-check-certificate options

Fortunately, wget from Cygwin works fine!

In some cases working with another hosts over HTTPS both curl and wget fail. To escape this issue I hard coded their invocation as curl --insecure and wget --no-check-certificate.

Perl requires Text::Markdown and HTTP::Tiny (and also IO::Socket::SSL and Net::SSLeay). If they are still not installed, You have to install them on your own before using the Perl script. For now I haven't used Text::Markdown actively and don't know its limitation. At least it's compatible with the original markdown and likely doesn't support GFM (GitHub Flavored Markdown).

Post Reply