A dual Batch+CSS script to convert Markdown to HTML
Posted: 05 Dec 2019 17:35
I've published on my github SysToolsLib library a new batch file called md2h.bat.
This batch converts a Markdown text file into an HTML file, and displays it in a Web browser.
This is useful if you're editing Markdown files, and want to know what they will look like once pushed into GitHub.
For that md2h.bat uses a number of interesting techniques:
Enjoy!
This batch converts a Markdown text file into an HTML file, and displays it in a Web browser.
This is useful if you're editing Markdown files, and want to know what they will look like once pushed into GitHub.
For that md2h.bat uses a number of interesting techniques:
- It is a dual Batch+CSS script.
This adds to a long line of dual language batch scripts published on this forum. For example see this thread.
It's done in a rather classic way, by hiding the batch section in a CSS comment.
The lucky find is that the initial @echo off directive is interpreted by CSS as a style directive, for an <@echo> tag having a child <off> tag, etc. - It uses GitHub's own REST MarkDown API to generate the HTML.
This is interesting because there are many different Markdown dialects, with subtle differences.
By using GitHub's own APIs, we can be sure that the generated HTML will look exactly the same once pushed into GitHub. - As GitHub's MarkDown API does not generate any style sheet, I'm reusing one published in this gist.
- Currently it uses curl.exe for doing the REST API calls.
curl.exe is distributed as part of the standard Windows 10 updates since early 2018.
If you don't have it, you can download it from the Official curl download page for Windows.
I considered using JavaScript code for doing the same. This would have allowed md2h.bat to work on all versions of Windows without an external dependency on curl...
But so far I've not found a way to do a triple Batch+CSS+JavaScript script!
Code: Select all
md2h README.md