md-converter Live Preview
A VS Code extension that shows the whole specification next to the editor, the
way md-converter renders it as HTML. Edit any clause file on the left; the
preview on the right updates while you type, and follows the cursor. It can
also show the changes against another Git version.
The preview is produced by md-converter itself, so numbering, cross-references,
notes, examples, figures and tables look as in the generated HTML. Only the
table of contents is left out.
From the same view you can also download the specification as DOCX or HTML,
clean up its Markdown, and start a new specification from a DOCX or a template.
Quick start
Each step ends with a check; do not go on until it passes. The simplest way
needs only Docker: the md-converter image is downloaded from Docker Hub.
Install Docker (Docker Desktop on macOS and Windows) and start it.
Check: docker info prints a server version instead of an error.
Install the extension from the Extensions view, then run Developer:
Reload Window in every open VS Code window.
Open the preview. Open the folder of a specification and click Open
Live Preview in the Preview section of the md-converter view in the
activity bar (book icon): it finds the specification in the workspace and
opens its front page. With one of its .md files open, the book button
(tooltip Open md-converter Live Preview) in the editor title bar, or
md-converter: Open md-converter Live Preview in the Command Palette, does
the same.
Check the ⚙ panel. The first time the preview opens in a project, while
no preview setting has been saved yet, the settings panel opens by itself.
Run md-converter with is Automatic: with Docker running, it uses the
Docker Hub image, and nothing needs to be set. Close the panel with ⚙ or by
clicking outside it. If Docker is not available, a notice says so and the
preview falls back to Python on this computer (see
Requirements).
Check that it works. The first time, the image is downloaded (about
600 MB): a notification shows how many of its layers are done, and the
toolbar shows "Downloading the md-converter image…". Then the whole
specification appears on the right (a few seconds for a large one). The
md-converter Live Preview output channel shows lines such as
Rendered in 120 ms. Edit a paragraph: the preview scrolls to it and
highlights it.
If something goes wrong:
| What you see |
What to do |
| The ⚙ panel opens with a red message |
Fix the setting it names. |
Docker not found or Cannot connect to the Docker daemon |
Install or start Docker. |
| "Docker is not available … runs with Python on this computer" |
With Automatic, Docker was not found or not running when the preview opened: start Docker and reopen the preview, or set up Python. |
| "The md-converter image … could not be downloaded" |
Check the network connection and that Docker is running, then edit a file or reopen the preview to try again. The details are in the output channel. |
pull access denied or manifest unknown |
The image name or tag does not exist: leave Docker Hub image empty. |
| "The download failed" |
The reason is in the notification; the whole log is in the md-converter Conversions output channel. |
preview_server.py not found in this folder |
The md-converter folder in the ⚙ panel is wrong. |
Python interpreter not found or No module named 'bs4' |
Set the interpreter of the environment with md-converter's requirements. |
Errors about pandoc with the Python runner |
Install Pandoc, or start VS Code from a terminal (code .) so it gets the PATH. |
| The preview stays blank after installing a new version |
Run Developer: Reload Window. |
Details of every error are in the md-converter Live Preview output channel.
Requirements
- VS Code 1.90 or later, on the desktop. Web editors cannot run the converter,
so the extension does not work there.
- One of:
- Docker only (used by default when Docker is running): the image holds
md-converter, Python and Pandoc. This is also the way to use it on Windows.
- Python: a local copy of md-converter, a Python environment with its
requirements and Pandoc on the
PATH.
- Git, only to compare with another version.
Settings
The easiest way to set them is the ⚙ button in the preview's toolbar: it
opens a panel with the settings below, saves them in the VS Code user settings,
and restarts the preview. The panel opens by itself the first time the preview
opens in a project while no preview setting has been saved, and when the
preview cannot start, with the problem next to the setting to fix. They are
also in the VS Code settings, under mdConverterPreview.
| Setting |
Description |
mdConverterPreview.runner |
auto (default) is remote when Docker is installed and running when the preview opens, otherwise local, with a notice; remote runs the md-converter image from Docker Hub; local runs md-converter with Python. |
mdConverterPreview.converterPath |
local only: the md-converter folder. When empty, a workspace folder containing md-converter is used. |
mdConverterPreview.pythonPath |
local only: the Python interpreter of that environment. When empty, python3 (python on Windows) is used. Set it explicitly when VS Code is started from the desktop, since a conda environment is not active there. |
mdConverterPreview.remoteImage |
remote only: the image to run. When empty, the md-converter image matching the extension's version; a new extension version downloads its image on first use. |
mdConverterPreview.fileOrder |
Optional file order JSON, as used by md-converter. When empty, file_order.json in the top folder of the workspace is used, if there is one. |
mdConverterPreview.settingsFile |
Optional md-converter settings JSON (--settings). The preview follows its md_to_html options (preprocessing, Pandoc filters, post-processing steps) and, in the WORD look, the formatting of code blocks (html_to_docx paragraph_formatting); the DOCX and HTML downloads use all of it. Saving the file refreshes the preview. When empty, settings.json in the top folder of the workspace is used, if there is one. |
A file_order.json or settings.json found in the workspace is shown in its
empty field in the ⚙ panel; nothing needs to be set to use it.
Docker
With the remote runner (and auto when Docker is running), the md-converter
image matching the extension's version is downloaded from Docker Hub on first
use (for linux/amd64 and linux/arm64). It runs as an unprivileged user, and
the specification's folder is only read.
When a newer image is available, for instance after a fix to the converter,
the toolbar shows ⬆ Newer image: it downloads it and restarts the preview.
To go back to the image of the extension's version, empty Docker Hub image
in the ⚙ panel.
Windows
Install Docker Desktop and follow the Quick start: with Docker
running, Automatic uses the Docker Hub image. Git for Windows is needed
only to compare with another version. The Python runner works too, with a
Windows Python environment and Pandoc.
Use
Open any .md file of the specification and click the book button in the editor
title bar (tooltip Open md-converter Live Preview; the built-in Markdown
preview's button is a different one), or run md-converter: Open md-converter
Live Preview from the Command Palette. The preview shows every Markdown file of
that folder, in md-converter's order.
The md-converter view of the activity bar (book icon) has a Preview section
(Open Live Preview, Compare With…), a Download section (DOCX,
HTML (ZIP), HTML With Changes (ZIP)) and a Cleanup section (All
Files, Current File), plus a Storage section (see
Disk space). The Preview, Download and Cleanup sections work
without a Markdown file open: they look for the folder holding front-page.md
(or clause files) in the workspace, ask which one when there are several, or
let you pick the folder when there is none, and open its first file.
- While you type, the preview shows and highlights the block you are changing.
Unsaved changes are included.
- Moving the cursor or switching file scrolls the preview to the same place.
- Double-click a paragraph, list item, table row or heading in the preview to
open its source file on the line where it starts.
- Conversion errors, such as a malformed
::: delineator, appear at the bottom
left with their file and line; click one to open it. The last good version of
that file stays visible meanwhile.
- ☰ in the toolbar opens and closes the table of contents over the left side
of the preview (all the headings, indented by level); click an entry to go to it.
- The dark mode button of the generated HTML works as there.
- The WORD button next to it shows the document roughly as it looks in the
DOCX (fonts, headings, notes, tables and code as in the ETSI template, on an
A4-wide page, with the code block formatting of the settings JSON); WEB
switches back. Pagination is not simulated.
The first render converts the whole document (a few seconds for a large
specification). After that, an edit converts only the files it affects: well
under a second for a typical clause. Edits that change numbering in other
files, such as a new reference or figure, update those files as well.
Comparing with another version
In the toolbar, pick HEAD, a branch or a tag in Compare with; the second
list then offers the latest 100 commits of that version that changed the
folder, to compare with one of them instead. Off stops comparing, and ⟳
reloads the lists (without fetching). The command md-converter: Compare Live
Preview With… does the same from the Command Palette.
The preview then marks insertions and deletions as md-converter's diff output
does, with the same Diff Controls to step through them, and keeps doing so
while you edit. The toolbar shows what is compared and the number of changes.
The files of that version are read with Git, without checking anything out.
Starting a new specification
In a workspace without a specification (no front-page.md or clause files), the
md-converter view of the activity bar shows a New Specification section
instead:
- From DOCX…: converts a DOCX, such as a published ETSI deliverable, to
Markdown. EMF images are converted to PNG and images trimmed only when
LibreOffice and ImageMagick are available, so not with the Docker image: a
warning in the log says so.
- From Template…: copies the empty skeleton of a TS, TR, GS or GR.
The files are created in the md folder of the workspace (which one, with
several), never over existing Markdown files, and the preview opens on them. The
log is in the md-converter Conversions output channel.
Downloading the DOCX or the HTML
⤓ in the toolbar (which asks for the format), the buttons of the Download
section of the md-converter view, or the md-converter: Download … commands of
the Command Palette convert the specification with md-converter, as the preview
does (Docker or Python), into:
- DOCX: the Word document;
- HTML: a ZIP of the HTML and its CSS;
- HTML with changes: the same ZIP, marking the changes against another
version: the one the preview compares with, or one chosen from a list.
It asks where to save the file (next to the specification's folder by default),
shows the conversion log in the md-converter Conversions output channel and its
progress in a notification, where it can be cancelled. When it is done, Open
or Show in Folder opens the result. The sources are converted from a copy,
so nothing is written next to them.
Cleaning up the Markdown
The Cleanup section of the md-converter view formats the Markdown with
Prettier, keeping md-converter's blocks and tables intact:
- All Files: every Markdown file of the specification's folder, after a
confirmation;
- Current File: only the Markdown file open in the editor.
The files are rewritten in place, so unsaved changes to them are saved first. The
log is in the md-converter Conversions output channel; the preview updates
by itself.
Disk space
The Storage section of the md-converter view shows what the preview keeps on
this computer:
- the md-converter Docker images, with their size (about 600 MB each), marking the
one in use. They are shared by every workspace, and each version update
downloads a new one without removing the previous ones;
- the temporary files left over by a crash. The preview's own cache is in a
temporary folder (or in the container) and is removed when the preview closes.
A folder counts as left over when nothing in it changed for a day.
Remove Old Versions removes the images other than the one in use. Delete All
Preview Data also removes that one and the temporary files, closing the
preview: the image is downloaded again when needed. Both ask first, and Docker
keeps an image that a running preview (of another window, for instance) uses.
⟳ in the section's title refreshes it.
Limitations
- Only top-level
.md files of the folder are rendered; a specification kept in
a single Markdown file is not supported.
- md-converter's settings presets are not applied; the preview uses the default
conversion steps.
- On the first render, a file with a conversion error is left out, together with
files whose cross-references point into it.
- When comparing, a file that exists only in the other version is not shown.
- Double-click finds the line from the block's text; for a block whose text
appears nowhere in its section (generated content), it opens the section's
heading.