Replace Current Markmap Rendering with Official Markmap Rendering Engine#198
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Deploying markdown-viewer with
|
| Latest commit: |
e4004d8
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://703bee46.markdown-viewer.pages.dev |
| Branch Preview URL: | https://fix-markmap-nested-code-bloc.markdown-viewer.pages.dev |
Deploying markdownviewer with
|
| Latest commit: |
e4004d8
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://fa1eb95d.markdownviewer.pages.dev |
| Branch Preview URL: | https://fix-markmap-nested-code-bloc.markdownviewer.pages.dev |
…x template previews
6f940f9 to
1fa553d
Compare
e3c21d9 to
1fa553d
Compare
…y disabling autoFit and applying tight viewBox
…te() to ensure rendering completes before SVG serialization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace Current Markmap Rendering with Official Markmap Rendering Engine
Problem & Root Causes Resolved
Incorrect Renderer: Replaced the previous simple Blue/Gray indentation-based box layout generator with the official
markmap-libandmarkmap-viewrendering engines.Code Blocks Ignored/Omitted: Fixed a bug in
preview-worker.jswhere the segmented preview block splitter prematurely split themarkmapblock at inner code blocks by normalizing Markmap fences before block splitting.Accidental Canvas Panning/Dragging: In the normal preview pane, the canvas could be dragged out of view. Disabled D3 zoom and panning listeners on the preview canvas to keep it fixed, while retaining full CSS-based panning/zooming inside the fullscreen/zoom modal.
Excessive Vertical Whitespace: Resized the SVG height dynamically post-layout using the exact node tree bounds (
rect.y2 - rect.y1) to prevent large empty spaces.Blank Template Previews (Root Cause Found & Fixed):
The
Markmap.create(svg, opts, data)static method internally firessetData(data).then(() => fit())— a detached promise chain that returns immediately without waiting for rendering. ThesetData()method itself isasyncbecause it containsawait new Promise(requestAnimationFrame)to measure foreignObject sizes via_relayout(). After therequestAnimationFrame, it applies node positions through D3 transitions.Because
Markmap.create()returns the instance beforesetData()completes, the offscreen serialization helper (renderMarkmapPreviewSvg) callsnew XMLSerializer().serializeToString(svg)on an SVG that has no rendered content — the nodes, paths, circles, and foreignObjects haven't been created yet.Fix: Replaced
Markmap.create(svg, opts, root)with manual construction:This ensures all SVG child elements are in the DOM before serialization.
Vertical Centering: Set
autoFit: falsein the options to preventrenderData()from callingthis.fit()at the end (line 1314 of markmap-view.js). Applied a tightviewBoxusing the computed layout bounds for compact mode, with relative CSS dimensions to let the browser center via flexbox.Files Changed
preview-worker.js&desktop-app/resources/js/preview-worker.jsscript.js&desktop-app/resources/js/script.jsstyles.css&desktop-app/resources/styles.cssdesktop-app/prepare.jsTesting & Verification