markmap-cli 0.5.3-alpha.0 → 0.13.0-alpha.0

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.
package/README.md CHANGED
@@ -29,10 +29,9 @@ Create a markmap from a Markdown input file
29
29
 
30
30
  Options:
31
31
  -V, --version output the version number
32
- -o, --output <output> specify filename of the output HTML
33
- --enable-mathjax enable MathJax support
34
- --enable-prism enable PrismJS support
35
32
  --no-open do not open the output file after generation
33
+ --no-toolbar do not show toolbar
34
+ -o, --output <output> specify filename of the output HTML
36
35
  -w, --watch watch the input file and update output on the fly, note that this feature is for development only
37
36
  -h, --help display help for command
38
37
  ```
package/bin/cli.js CHANGED
File without changes
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! markmap-cli v0.5.3-alpha.0+d958166 | MIT License */
1
+ /*! markmap-cli v0.13.0-alpha.0 | MIT License */
2
2
  'use strict';
3
3
 
4
4
  var fs = require('fs');
@@ -10,14 +10,14 @@ var http = require('http');
10
10
  var Koa = require('koa');
11
11
  var chokidar = require('chokidar');
12
12
 
13
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e['default'] : e; }
13
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
14
14
 
15
15
  var open__default = /*#__PURE__*/_interopDefaultLegacy(open);
16
16
  var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
17
17
  var Koa__default = /*#__PURE__*/_interopDefaultLegacy(Koa);
18
18
  var chokidar__default = /*#__PURE__*/_interopDefaultLegacy(chokidar);
19
19
 
20
- const TOOLBAR_VERSION = "0.1.6";
20
+ const TOOLBAR_VERSION = "0.13.0-alpha.0";
21
21
  const TOOLBAR_CSS = `npm/markmap-toolbar@${TOOLBAR_VERSION}/dist/style.min.css`;
22
22
  const TOOLBAR_JS = `npm/markmap-toolbar@${TOOLBAR_VERSION}/dist/index.umd.min.js`;
23
23
 
@@ -59,8 +59,6 @@ function addToolbar(assets) {
59
59
  }
60
60
  class Defer {
61
61
  constructor() {
62
- this.resolve = void 0;
63
- this.reject = void 0;
64
62
  this.promise = new Promise((resolve, reject) => {
65
63
  this.resolve = resolve;
66
64
  this.reject = reject;
@@ -69,6 +67,8 @@ class Defer {
69
67
 
70
68
  }
71
69
 
70
+ /* eslint-disable max-classes-per-file */
71
+
72
72
  function consecutive(fn) {
73
73
  let promise;
74
74
  return () => {
@@ -88,8 +88,6 @@ class BufferContentProvider {
88
88
  this.deferredSet = new Set();
89
89
  this.events = new events.EventEmitter();
90
90
  this.ts = 0;
91
- this.content = void 0;
92
- this.line = void 0;
93
91
  this.events.on('content', () => {
94
92
  this.feed({
95
93
  ts: this.ts,
@@ -152,7 +150,6 @@ class FileSystemProvider extends BufferContentProvider {
152
150
  constructor(fileName) {
153
151
  super();
154
152
  this.fileName = fileName;
155
- this.watcher = void 0;
156
153
  this.watcher = chokidar__default.watch(fileName).on('all', consecutive(() => this.update()));
157
154
  }
158
155
 
@@ -170,57 +167,34 @@ class FileSystemProvider extends BufferContentProvider {
170
167
 
171
168
  function startServer(paddingBottom) {
172
169
  let ts = 0;
173
- let root;
174
- let line;
175
170
  const {
176
- mm
171
+ mm,
172
+ markmap
177
173
  } = window;
178
174
  refresh();
179
175
 
180
176
  function refresh() {
181
177
  fetch(`/data?ts=${ts}`).then(res => res.json()).then(res => {
182
178
  if (res.ts && res.ts > ts && res.result) {
183
- mm.setData(root = res.result.root);
179
+ const {
180
+ root,
181
+ frontmatter
182
+ } = res.result;
183
+ mm.setOptions(markmap.deriveOptions(frontmatter == null ? void 0 : frontmatter.markmap));
184
+ mm.setData(root);
184
185
  if (!ts) mm.fit();
185
186
  ts = res.ts;
186
- line = null;
187
- }
188
-
189
- if (root && res.line != null && line !== res.line) {
190
- line = res.line;
191
- const active = findActiveNode();
192
- if (active) mm.ensureView(active, {
193
- bottom: paddingBottom
194
- });
195
187
  }
196
188
 
197
189
  setTimeout(refresh, 300);
198
190
  });
199
191
  }
200
-
201
- function findActiveNode() {
202
- let best;
203
- dfs(root);
204
- return best;
205
-
206
- function dfs(node) {
207
- var _node$p, _node$c;
208
-
209
- const lines = (_node$p = node.p) == null ? void 0 : _node$p.lines;
210
-
211
- if (lines && lines[0] <= line && line < lines[1]) {
212
- best = node;
213
- }
214
-
215
- (_node$c = node.c) == null ? void 0 : _node$c.forEach(dfs);
216
- }
217
- }
218
192
  }
219
193
 
220
194
  function setUpServer(transformer, provider, options) {
221
195
  let assets = transformer.getAssets();
222
196
  if (options.toolbar) assets = addToolbar(assets);
223
- const html = markmapLib.fillTemplate(null, assets) + `<script>(${startServer.toString()})(${options.toolbar ? 60 : 0})</script>`;
197
+ const html = `${markmapLib.fillTemplate(null, assets)}<script>(${startServer.toString()})(${options.toolbar ? 60 : 0})</script>`;
224
198
  const app = new Koa__default();
225
199
  app.use(async (ctx, next) => {
226
200
  if (ctx.path === '/') {
@@ -273,11 +247,14 @@ async function createMarkmap(options) {
273
247
  const transformer = new markmapLib.Transformer();
274
248
  const {
275
249
  root,
276
- features
250
+ features,
251
+ frontmatter
277
252
  } = transformer.transform(options.content || '');
278
253
  let assets = transformer.getUsedAssets(features);
279
254
  if (options.toolbar) assets = addToolbar(assets);
280
- const html = markmapLib.fillTemplate(root, assets);
255
+ const html = markmapLib.fillTemplate(root, assets, {
256
+ jsonOptions: frontmatter == null ? void 0 : frontmatter.markmap
257
+ });
281
258
  const output = options.output || 'markmap.html';
282
259
  await fs.promises.writeFile(output, html, 'utf8');
283
260
  if (options.open) open__default(output);
@@ -308,6 +285,6 @@ function main(version) {
308
285
  exports.createMarkmap = createMarkmap;
309
286
  exports.develop = develop;
310
287
  exports.main = main;
311
- Object.keys(markmapLib).forEach(function (k) {
288
+ for (var k in markmapLib) {
312
289
  if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = markmapLib[k];
313
- });
290
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markmap-cli",
3
- "version": "0.5.3-alpha.0+d958166",
3
+ "version": "0.13.0-alpha.0",
4
4
  "description": "Create markmaps from CLI",
5
5
  "author": "Gerald <gera2ld@live.com>",
6
6
  "license": "MIT",
@@ -24,7 +24,6 @@
24
24
  "scripts": {
25
25
  "dev": "rollup -wc rollup.conf.js",
26
26
  "clean": "del-cli dist types",
27
- "lint": "eslint --ext .ts .",
28
27
  "build:types": "tsc",
29
28
  "build:js": "rollup -c rollup.conf.js"
30
29
  },
@@ -43,12 +42,12 @@
43
42
  "chokidar": "^3.5.1",
44
43
  "commander": "^7.1.0",
45
44
  "koa": "^2.13.1",
46
- "markmap-lib": "^0.11.6",
45
+ "markmap-lib": "^0.13.0-alpha.0",
47
46
  "open": "^8.0.3",
48
47
  "update-notifier": "^5.1.0"
49
48
  },
50
49
  "engines": {
51
50
  "node": ">=10"
52
51
  },
53
- "gitHead": "d9581669a1b201e0894b13213439a658084a4e26"
52
+ "gitHead": "969aa149f36580954e77b7ba434e5c48b409cfc2"
54
53
  }
@@ -1,17 +1,17 @@
1
- import { IDevelopOptions } from './util';
2
- interface IFileUpdate {
3
- ts?: number;
4
- content?: string;
5
- line?: number;
6
- }
7
- interface IContentProvider {
8
- getUpdate: (ts: number, timeout?: number) => Promise<IFileUpdate>;
9
- setContent: (content: string) => void;
10
- setCursor: (line: number) => void;
11
- dispose: () => void;
12
- }
13
- export declare function develop(fileName: string | undefined, options: IDevelopOptions): Promise<{
14
- provider: IContentProvider;
15
- close(): Promise<void>;
16
- }>;
17
- export {};
1
+ import { IDevelopOptions } from './util';
2
+ interface IFileUpdate {
3
+ ts?: number;
4
+ content?: string;
5
+ line?: number;
6
+ }
7
+ interface IContentProvider {
8
+ getUpdate: (ts: number, timeout?: number) => Promise<IFileUpdate>;
9
+ setContent: (content: string) => void;
10
+ setCursor: (line: number) => void;
11
+ dispose: () => void;
12
+ }
13
+ export declare function develop(fileName: string | undefined, options: IDevelopOptions): Promise<{
14
+ provider: IContentProvider;
15
+ close(): Promise<void>;
16
+ }>;
17
+ export {};
package/types/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { IMarkmapCreateOptions } from 'markmap-lib';
2
- import { IDevelopOptions } from './util';
3
- import { develop } from './dev-server';
4
- export * from 'markmap-lib';
5
- export { develop };
6
- export declare function createMarkmap(options: IMarkmapCreateOptions & IDevelopOptions): Promise<void>;
7
- export declare function main(version: string): void;
1
+ import type { IMarkmapCreateOptions } from 'markmap-lib';
2
+ import { IDevelopOptions } from './util';
3
+ import { develop } from './dev-server';
4
+ export * from 'markmap-lib';
5
+ export { develop };
6
+ export declare function createMarkmap(options: IMarkmapCreateOptions & IDevelopOptions): Promise<void>;
7
+ export declare function main(version: string): void;
package/types/util.d.ts CHANGED
@@ -1,17 +1,17 @@
1
- import { IAssets } from 'markmap-lib';
2
- export interface IDevelopOptions {
3
- /**
4
- * whether to open the generated markmap in browser
5
- */
6
- open: boolean;
7
- /**
8
- * whether to show default toolbar
9
- */
10
- toolbar: boolean;
11
- }
12
- export declare function addToolbar(assets: IAssets): IAssets;
13
- export declare class Defer<T> {
14
- resolve: (value: T) => void;
15
- reject: (err: Error) => void;
16
- promise: Promise<unknown>;
17
- }
1
+ import { IAssets } from 'markmap-lib';
2
+ export interface IDevelopOptions {
3
+ /**
4
+ * whether to open the generated markmap in browser
5
+ */
6
+ open: boolean;
7
+ /**
8
+ * whether to show default toolbar
9
+ */
10
+ toolbar: boolean;
11
+ }
12
+ export declare function addToolbar(assets: IAssets): IAssets;
13
+ export declare class Defer<T> {
14
+ resolve: (value: T) => void;
15
+ reject: (err: Error) => void;
16
+ promise: Promise<unknown>;
17
+ }