-
Notifications
You must be signed in to change notification settings - Fork 1
Exporting
Mdview combines two functionalities into a single binary: it serves as both a Markdown Viewer and a Converter to multiple formats. This page focuses on the Converter part.
The Converter can turn Markdown into HTML (XHTML or HTML5), text, and text with color codes (ANSI and VT100). Of course, HTML is the most popular format because it allows reusing your documents for various applications, such as printing and exporting to PDF. The ANSI and VT100 output modes are mainly useful to colorize Markdown syntax for terminal output. Text output is likely not too useful; but it is there.
As discussed in the Viewer page, one can export the current page to the web browser. When the preview button is clicked, internally the Viewer executes a command similar to the following for the loaded page, README.md:
mdview --html --html5 --html-full --html-css=2 --output=/tmp/README.md.html . ./README.mdWithin the exported document, /tmp/README.md.html, all internal links pointing to file names ending with ".md" are changed so they end with ".md.html".
With this knowledge, and some shell scripting, you could create a set of coordinated HTML files that can be navigated as a small web.
For example, the following shell script fragment populates the local-web directory exporting all Markdown files in directory md-docs to HTML:
# change both paths to the actual locations
web=/path/to/local-web
mkd=/path/to/md-docs
for md in "$mkd/"*.md; do
mdview --html --html5 --html-full \
--html-css=2 --toc-level=3 \
--html-base="$web" \
--output="$web/${md##/}.html" "$md"
doneLeave out --html-css=2 if you prefer a basic look for your HTML pages.
You could also try changing 2 to 1 to apply the Viewer's page look to your HTML.
Leave out --toc-level (or set it to 0) to omit the Table of Contents.
The --html-base option sets the root of relative links within the HTML document.
If you will publish your local-web folder online, do not set the HTML base but instead delete the <base> tag from all exported HTML files.
Often a Markdown page includes some images.
You do need to copy all images from md-docs to your local-web directory, replicating the same sub-directory structure.