markmap-plus 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +153 -9
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -46,19 +46,48 @@ The basic workflow is:
46
46
  <title>markmap-plus basic example</title>
47
47
  </head>
48
48
  <body>
49
- <svg id="mindmap" style="width: 100%; height: 500px"></svg>
50
-
49
+ <button id="export-btn">Export to Markdown</button>
50
+ <svg id="mindmap" style="width: 100%; height: 800px"></svg>
51
51
  <script type="module">
52
- import { Markmap, Transformer } from 'markmap-plus';
53
-
54
- const markdown = `# markmap-plus
55
-
56
- - Built on markmap-lib
57
- - Renders with markmap-view-plus
52
+ import { Markmap, Transformer, toMarkdown } from 'markmap-plus';
53
+
54
+ const initValue = `# Markmap Editor Demo
55
+
56
+ ## How to use
57
+ - Edit node
58
+ - Double-click any node to edit
59
+ - Press Enter to save edits
60
+ - Press Esc to cancel edits
61
+ - Clicking elsewhere also saves
62
+ - Add node
63
+ - Press Enter to add sibling node
64
+ - Press Tab to add child node
65
+ - Click + button to add arbitrary node
66
+ - Delete node
67
+ - Press Delete to remove node
68
+
69
+ ## Supported Markdown Syntax
70
+ ### Heading Levels
71
+ - Level 1 Heading
72
+ - Level 2 Heading
73
+ - Level 3 Heading
74
+
75
+ ### Text Formatting
76
+ - **Bold text**
77
+ - *Italic text*
78
+ - ~~Strikethrough~~
79
+ - \`Inline code\`
80
+
81
+ ## Interaction
82
+ ### Node Operations
83
+ - Click to expand/collapse
84
+ - Double-click to edit content
85
+ - Drag to pan
86
+ - Scroll to zoom
58
87
  `;
59
88
 
60
89
  const transformer = new Transformer();
61
- const { root } = transformer.transform(markdown);
90
+ const { root } = transformer.transform(initValue);
62
91
 
63
92
  const svg = document.getElementById('mindmap');
64
93
  const mm = Markmap.create(svg, {
@@ -68,6 +97,27 @@ The basic workflow is:
68
97
  mm.setData(root).then(() => {
69
98
  mm.fit();
70
99
  });
100
+
101
+ document.getElementById('export-btn').addEventListener('click', () => {
102
+ const pureNode = mm.getData(true);
103
+ if (pureNode) {
104
+ const exportedMarkdown = toMarkdown(pureNode);
105
+ console.log(exportedMarkdown);
106
+ // Create Blob object
107
+ const blob = new Blob([exportedMarkdown], { type: 'text/markdown' });
108
+ // Create download link
109
+ const url = URL.createObjectURL(blob);
110
+ const a = document.createElement('a');
111
+ a.href = url;
112
+ a.download = 'markmap.md';
113
+ // Trigger download
114
+ document.body.appendChild(a);
115
+ a.click();
116
+ // Cleanup
117
+ document.body.removeChild(a);
118
+ URL.revokeObjectURL(url);
119
+ }
120
+ });
71
121
  </script>
72
122
  </body>
73
123
  </html>
@@ -215,6 +265,100 @@ function exportMarkdown() {
215
265
  </template>
216
266
  ```
217
267
 
268
+ ### API
269
+
270
+ #### View Options
271
+
272
+ The `Markmap.create` call accepts a set of options that control how users can interact with the mind map:
273
+
274
+ - `mode`: rendering mode, either `'display'` or `'editable'`.
275
+ - `editable`: whether node text can be edited in-place.
276
+ - `addable`: whether users can create new nodes from the UI.
277
+ - `deletable`: whether nodes can be deleted.
278
+ - `collapseOnHover`: whether child branches auto-collapse when the mouse leaves a node.
279
+ - `hoverBorder`: whether a border is shown when the mouse hovers a node.
280
+ - `clickBorder`: whether a border is shown when a node is selected by click.
281
+ - `inputPlaceholder`: placeholder text shown in the inline input for new nodes.
282
+
283
+ Example:
284
+
285
+ ```ts
286
+ const mm = Markmap.create(svgElement, {
287
+ mode: 'editable',
288
+ editable: true,
289
+ addable: true,
290
+ deletable: true,
291
+ collapseOnHover: true,
292
+ hoverBorder: true,
293
+ clickBorder: true,
294
+ inputPlaceholder: 'Enter text',
295
+ });
296
+ ```
297
+
298
+ #### Transformer
299
+
300
+ `Transformer` is responsible for turning Markdown text into the data structure that Markmap uses to render mind maps.
301
+
302
+ ```ts
303
+ import { Transformer } from 'markmap-plus';
304
+
305
+ const transformer = new Transformer();
306
+ const { root, features, frontmatter } = transformer.transform(markdown);
307
+ ```
308
+
309
+ - `root` is the mind map tree (an `IPureNode`) that you pass to `mm.setData(root)`.
310
+ - `features` describes which plugins and features are used in the Markdown.
311
+ - `frontmatter` contains parsed front‑matter metadata.
312
+
313
+ #### setData
314
+
315
+ `setData` is an instance method on `Markmap`. It applies a new mind map tree to the current instance and triggers a re-render.
316
+
317
+ ```ts
318
+ setData(data?: IPureNode | null, opts?: Partial<IMarkmapOptions>): Promise<void>;
319
+ ```
320
+
321
+ - `data`: the `IPureNode` tree returned from `Transformer.transform`. When omitted, the previous tree is kept.
322
+ - `opts`: optional view options to update together with the data.
323
+
324
+ #### getData
325
+
326
+ `getData` is an instance method on `Markmap` used to export data. It returns the current mind map tree data.
327
+
328
+ ```ts
329
+ getData(): INode | undefined;
330
+ getData(pure: true): IPureNode | undefined;
331
+ ```
332
+
333
+ - `mm.getData()` returns the internal runtime tree (`INode`) including layout `state`.
334
+ - `mm.getData(true)` returns a plain data tree (`IPureNode`) without layout `state`, suitable for serialization and storage.
335
+
336
+ #### toMarkdown
337
+
338
+ `toMarkdown` converts an `IPureNode` tree back into a Markdown string.
339
+
340
+ ```ts
341
+ function toMarkdown(root: IPureNode): string;
342
+ ```
343
+
344
+ Example:
345
+ // Get the current pure data
346
+ const pureNode = mm.getData(true);
347
+ if (pureNode) {
348
+ // Convert back to Markdown string
349
+ const markdown = toMarkdown(pureNode);
350
+ console.log('Exported Markdown:', markdown);
351
+ }
352
+ ```ts
353
+ import { toMarkdown } from 'markmap-plus';
354
+
355
+ const pureNode = mm.getData(true);
356
+ if (pureNode) {
357
+ const markdown = toMarkdown(pureNode);
358
+ console.log(markdown);
359
+ }
360
+ ```
361
+
218
362
  ### More Documentation
219
363
 
220
364
  For more details about interaction, keyboard shortcuts, and full API reference, see the [docs](https://tem-man.github.io/markmap-plus-docs) or the published documentation site.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markmap-plus",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "markmap-plus is an enhanced version of markmap with node creation, editing, and deletion capabilities",
5
5
  "author": "Lin Jiman <temman_lin@qq.com>",
6
6
  "license": "MIT",