mdmod: Markdown Click-to-Edit for VS Code
A VS Code custom editor that ports the mdmod desktop app. A .md file is shown rendered, and you
click any element to edit its raw Markdown in place. The rest of the document stays rendered.
Install for local testing
Option A: install the packaged extension.
cd vscode-extension
npm install
npm run package # writes mdmod-click-edit.vsix
code --install-extension mdmod-click-edit.vsix
Reload VS Code afterwards. To remove it: code --uninstall-extension RichardTraviolia.mdmod-click-edit.
Option B: run it from source. Open the vscode-extension folder in VS Code and press F5. A
second VS Code window (the Extension Development Host) opens on ../tests/fixtures with the
extension loaded.
Opening a file with it
The extension does not replace the normal text editor. To use it on a .md file:
- Right-click the file in the Explorer and choose Open with Click-to-Edit, or
- with the file open as text, click the pencil icon in the editor title bar, or
- right-click the editor tab, choose Reopen Editor With…, then Markdown Click-to-Edit (mdmod).
To make it the default for Markdown, use Reopen Editor With… → Configure default editor for
'*.md'…. The Open Markdown Source button in the title bar switches back to the text editor.
Using it
| Action |
Effect |
| Click an element |
Its raw Markdown opens in a text box at the same position |
| Click the space between elements |
Edit the blank lines there; type to insert new content |
| Click outside the text box, or Ctrl+Enter |
Commit the edit |
| Esc |
Discard the edit |
| Tab / Shift+Tab in the text box |
Indent / outdent, as in the text editor (uses editor.tabSize and editor.insertSpaces) |
| Ctrl+S |
Commit and save |
| Ctrl+Z / Ctrl+Y outside the text box |
Undo / redo committed edits (VS Code's own undo) |
| Shift+Up / Shift+Down |
Extend the edited range by one element up or down, or shrink it back |
| Ctrl+Shift+Up / Ctrl+Shift+Down |
Move the other edge of the range |
| Shift+Left / Shift+Right |
Widen to the enclosing list item / step back in |
| Ctrl+Shift+Left / Ctrl+Shift+Right |
Widen to the top level / return to the element first clicked |
| Ctrl+click a link |
Open http(s) and mailto links externally; open .md links in this editor |
While editing, the round icon next to the text box shows a green check for valid Markdown or a
red cross with the problems in its tooltip. The Changes panel in the bottom right shows the
edit as rendered elements: removed in red, added in green. Mermaid code blocks are drawn as
diagrams.
Deleting all of an element's text removes the element and one neighboring gap of blank lines,
as in the desktop app.
Tables
A table is split into elements the way a list is: the header (header line plus separator line)
is one element, and each body row is its own element. Clicking a row edits only that row's
line. Shift+Up/Down extends the edit to the rows above and below, as with sibling list items,
and Shift+Left widens it to the whole table. Clicking the thin strip between two rows inserts
a new row there; deleting all of a row's text removes the row.
When an edit starts in a table body, the Changes panel always shows the table header above the
edited rows, and the lint check compares cell counts against that header. Tables inside list
items are not split; they stay part of the list item.
How it relates to the desktop app
The parsing, gap, deletion, scope, and lint rules are ported from src/units.rs,
src/document.rs, src/app.rs, and src/preview.rs; test/core.test.ts ports the Rust tests
that cover them. Parsing uses markdown-it instead of pulldown-cmark, so rare edge cases may split
into elements slightly differently.
VS Code's TextDocument is the data model, so VS Code handles saving, the unsaved-changes dot,
the save prompt on close, undo/redo of committed edits, and reloading when the file changes on
disk. Edits change only the source range of the edited element; line endings follow the file.
Differences from the desktop app:
- Images display inline, where they appear in the text, instead of below the block.
- HTML blocks render as literal paragraph text (markdown-it treats them as paragraphs when HTML
is disabled), not as a separate HTML block element.
- Text typed into an open text box is not part of the document until committed, so VS Code does
not count it as an unsaved change. Commit before closing the tab.
Development
npm run build # bundle to dist/
npm run watch # rebuild on change
npm test # unit tests for the core logic
npm run typecheck
Uploading to the Visual Studio Marketplace
The file to upload is the packaged .vsix:
cd vscode-extension
npm install
npm run package # writes vscode-extension/mdmod-click-edit.vsix
Upload vscode-extension/mdmod-click-edit.vsix (in the repository, next to package.json).
Do not upload anything from dist/ or dist-test/; those are build intermediates that the
.vsix already contains.
Before packaging:
- The
publisher field in package.json must match your Marketplace publisher ID, or the
upload is rejected.
- Each upload needs a higher
version in package.json than the last one. Rebuild the .vsix
after changing it.
Then go to https://marketplace.visualstudio.com/manage, select your publisher, and choose
New extension → Visual Studio Code. For a later version, use ⋯ → Update on the existing
extension instead.