Convert Markdown documents to HTML
docconvert(md) converts the Markdown document(s) md to HTML.
Multiple documents may also be specified using docconvert(md1,md2,...).
docconvert(...,"Theme",t) sets the theme t. Available themes are light, dark, and auto (responsive, default). For viewing as part of the MATLAB documentation, especially prior to R2025a, light mode works best. For viewing standalone, responsive mode works well.
docconvert(...,"Stylesheets",css) includes the stylesheet(s) css.
docconvert(...,"Scripts",js) includes the script(s) js. Scripts are included at the end of the body in the order specified to ensure that the HTML content is loaded and rendered before the scripts run. 🧪
docconvert(...,"Root",r) publishes to the root folder r, placing stylesheets and scripts in the subfolder resources. The root folder must be a common ancestor of the Markdown documents. If not specified, the root folder is the lowest common ancestor.
docconvert(...,"Interpreter",in) uses the text interpreter in. Available interpreters are "latex" (LaTeX markup) and "none" (literal text, default). Use single dollar signs $...$ to display equations inline, and double dollar signs $$...$$ to display equations on their own line, centered.
[html,res] = docconvert(...) returns the names of the HTML document(s) html and the resources folder res created.
| Name | Description | Type | Required |
|---|---|---|---|
md➡️ |
Markdown document(s), as an absolute or relative path; wildcards are supported | string(s) | yes |
t➡️ |
theme: light, dark, or auto; default is auto |
string(s) | |
css➡️ |
CSS stylesheet(s), as an absolute or relative path; wildcards are supported | string(s) | |
js➡️ |
JavaScript script(s), as an absolute or relative path; wildcards are supported | string(s) | 🧪 |
r➡️ |
root folder, as an absolute or relative path; default is the lowest common ancestor of md |
string | |
in➡️ |
text interpreter: latex or none; default is none |
string | |
➡️html |
HTML document(s) created, as an absolute path | string(s) | |
➡️res |
resources folder created, as an absolute path | string |
docconvert("mickey/pluto.md") converts a single Markdown document mickey/pluto.md to HTML mickey/pluto.html. Note that this path is relative.
docconvert("C:\daisy\mickey\pluto.md") also converts a single Markdown document, this time specified using an absolute path.
docconvert("mickey/*.md") converts all Markdown documents in mickey to HTML.
docconvert("mickey/**/*.md") converts all Markdown documents in mickey and its subfolders.
docconvert(["mickey/pluto.md" "mickey/donald.md"]) converts multiple Markdown documents to HTML.
docconvert("mickey/pluto.md","Stylesheets","huey/louie.css") copies the stylesheet huey/louie.css to the resources folder and includes a <link> in the HTML <head>.
docconvert("mickey/pluto.md","Scripts","morty/ferdie.js") copies the script morty/ferdie.js to the resources folder and includes a <script> in the HTML <body>. 🧪
docconvert("mickey/goofy/*.md","Root","mickey") sets the root folder to mickey, rather than the lowest common ancestor mickey/goofy of the Markdown documents.
The conversion consists of 7 steps:
- Read the Markdown document
- Convert Markdown to an HTML fragment using the GitHub Markdown API service
- Tidy up the HTML fragment in preparation for XML postprocessing
- Replace
.mdlinks in the fragment to.html-- Markdown links to Markdown, HTML links to HTML - Build an HTML document around the HTML fragment
- including default stylesheets, specified stylesheets, and specified scripts
- using the first level-1 heading
# Headingas the<html><title>
- Copy the specified stylesheets and scripts to the
resourcesfolder in the root folder - Write the document to an HTML document next to the original Markdown document
DocMaker seeks to provide pleasant style by default, but you can override the default styles by specifying your own stylesheets.
For example, to make level-2 headings ## Heading blue, create and specify a stylesheet with:
h2 {
color: blue;
}Since cascading stylesheets cascade, later styles override earlier styles.
This feature depends on reverse-engineering the HTML generated by the GitHub Markdown API service, although much of the behavior is obvious.
Generated HTML may be postprocessed in the browser using JavaScript. Postprocessing code may be included by specifying the optional input Scripts. Scripts are included at the end of the body in the order specified to ensure that the HTML content is loaded and rendered before the scripts run.
This feature is experimental 🧪 and may be removed in a future version.
home 🏠 | convert ➡️ | run 🏃 | index 📜 | delete ♻️ | workspace 👷 | about 🐣 | ©️ MathWorks 2024-2026