v2.0.1

v1 Deprecation

Last updated


v2 ships only the Markdown parser MDParser; this page lists the v1 APIs that were removed, their replacements, a migration example and the v1 vs v2 benchmark.

Keep Using v1


The v1 MDEditor, MDViewer and MDParser class are deprecated and receive no new features. Projects that need the editor pin 1.11.6:
  1. <script src="https://cdn.jsdelivr.net/npm/@pardnchiu/nanomd@1.11.6/dist/NanoMD.js"></script>

  1. npm i @pardnchiu/nanomd@1.11.6

Pin the exact version; @latest or an unversioned URL resolves to v2.

Removed APIs


v1Removedv2 replacement
MDEditorRemoved in v2.0.0Use <textarea>, CodeMirror, Monaco or another editor and pass its content to MDParser.Parse()
MDViewerRemoved in v2.0.0Set container.innerHTML = MDParser.Parse(text).html() and call MDParser.Refresh(container)
new MDParser({ standard }).parse(text)Removed in v2.0.0MDParser.Parse(text).html(); the standard option is gone and the full syntax is always on
PDMarkdownEditorRemoved in v2.0.0No public replacement
ESM exports editor, viewerRemoved in v2.0.0import { MDParser } from "@pardnchiu/nanomd"
sync.editor, sync.delay, sync.scrollRemoved in v2.0.0Listen for input and debounce yourself; see the migration example below
emptyContentRemoved in v2.0.0The caller decides what to render for empty content
hashtag.path, hashtag.targetRemoved in v2.0.0No public replacement; #tag renders as plain text
changeMode(), style.modeRemoved in v2.0.0Set data-mode on the .nanomd container; see Theming
style.fillRemoved in v2.0.0Set data-fill="1" on the .nanomd container
download(), openfile(), undo(), redo(), keyboard shortcuts and toolbarRemoved in v2.0.0Removed with MDEditor; no public replacement

Files and Styles


v1v2
dist/NanoMD.jsdist/parser.js (global MDParser)
dist/NanoMD.esm.jsdist/parser.esm.js
dist/NanoMD.css, dist/NanoMD-output.cssdist/parser.css, loaded automatically by parser.js from the same directory
Container class .pd-md-viewer.nanomd
Material Symbols, Mermaid and code-prettify injected on loadLoaded on demand with MDParser.Init({ enable }); see Dependencies and Refresh

Behavior Changes


Itemv1.11.6v2
$ in textRendered as @dollar@Rendered as is; a $...$ pair is inline math
YouTube/Vimeo previewsNot produced without hashtag.pathEmbedded players are always added
Raw HTMLNot sanitizedDangerous tags, event attributes and javascript: URLs are removed
Invalid Mermaid syntaxShows Mermaid's error graphicFalls back to a plain code block
RuntimeRequires a browser DOMParse() and html() run in Node.js and Workers

v1 vs v2


The same sample document, repeated to each size, rendered to HTML in headless Chrome; runs over 15 seconds are recorded as timeouts, and their ratios use 15 seconds as a lower bound.
Sizev1.11.6 MDParser().parse()v2 Parse().html()Speedup
4.4 KB2.6 ms0.4 ms7×
44.3 KB29.6 ms1.8 ms16×
443.4 KB1,790 ms17.7 ms101×
1.08 MB11,037 ms47.4 ms233×
2.16 MBTimeout82.3 ms182× or more
4.33 MBTimeout156.4 ms96× or more

Migration Example


The v1 editor plus viewer becomes any editor plus a debounced render in v2:
  1. <textarea id="editor" rows="4" style="width:100%"># Hello
  2. Edit me, the preview updates after you stop typing.</textarea>
  3. <div id="viewer" class="nanomd"></div>
  4. <script>
  5. const editor = document.getElementById("editor");
  6. const viewer = document.getElementById("viewer");
  7. let timer;
  8. function render() {
  9. viewer.innerHTML = MDParser.Parse(editor.value).html();
  10. MDParser.Refresh(viewer).catch((err) => console.error(err.message));
  11. }
  12. editor.addEventListener("input", () => {
  13. clearTimeout(timer);
  14. timer = setTimeout(render, 300);
  15. });
  16. render();
  17. console.log(viewer.querySelector(".md-h1").textContent);
  18. </script>
Live preview · @pardnchiu/nanomd@2.0.1
中文