pandoc is a universal document converter that supports many formats.
To convert a MarkDown document HTML you can use the following command:
pandoc -s -f markdown -t html5 -o target.html source.md
where:
-s: produces a standalone document, as opposed to just a fragment-f:--fromindicates the source formats-t:--toindicates the target format-o:--outputindicates the target file where the converted document will be written
There are many other useful arguments that you can use to customize the output, for example:
-c:-csslink to a stylesheet. You can use a full URL or a local path-H:--include-in-headerindicates a file to include as a header in the output
Example:
pandoc -s -f markdown -c "assets/md2html.css" -H "assets/header.html" -t html5 -o mynotes.html my_notes.md
Using pandoc to convert a MarkDown file to HTML with Geany build commands
The Geany IDE provides a handy mechanism to assign custom build commands to specific file types.
Follow these steps to create a new menu item in the Build menu that will generate an HTML document in the same directory where your MarkDown file is.
- Open a MarkDown file in Geany
- Go to Build > Set Build Commands
- Under Markdown commands, click on the first empty button and set the name for the menu item in the dialog window that pops up.
- In the Command field, enter the following command:
pandoc -s -f markdown -t html5 %f -c ~/assets/md2html.css -H ~/assets/header.html > %e.html
Now you can simply press F8 to generate an HTML version of your MarkDown document. Check the Message Window (View > Show Message Window) for compilation errors.
Find more information about the available options in Geany's Build commands in the project's documentation: User Guide to configuring the Build Menu.
Author: Lucas Vieites ✦ Published: ✦ Updated: ✦
