markmap-lib
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
/*! markmap-lib v0.12.0 | MIT License */ | ||
/*! markmap-lib v0.13.0-alpha.0 | MIT License */ | ||
import _extends from '@babel/runtime/helpers/esm/extends'; | ||
@@ -11,3 +11,3 @@ import { persistCSS, persistJS, wrapFunction, Hook } from 'markmap-common'; | ||
const template = "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n<title>Markmap</title>\n<style>\n* {\n margin: 0;\n padding: 0;\n}\n#mindmap {\n display: block;\n width: 100vw;\n height: 100vh;\n}\n</style>\n<!--CSS-->\n</head>\n<body>\n<svg id=\"mindmap\"></svg>\n<!--JS-->\n</body>\n</html>\n"; | ||
const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.2.7"}`].map(src => ({ | ||
const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.13.0-alpha.0"}`].map(src => ({ | ||
type: 'script', | ||
@@ -18,9 +18,6 @@ data: { | ||
})); | ||
const defaultGetOptions = (markmap, jsonOptions) => markmap.deriveOptions(jsonOptions); | ||
function fillTemplate(root, assets, extra) { | ||
if (typeof extra === 'function') { | ||
extra = { | ||
getOptions: extra | ||
}; | ||
} | ||
extra = _extends({ | ||
@@ -36,13 +33,12 @@ baseJs: BASE_JS | ||
getMarkmap: () => window.markmap, | ||
getOptions: extra.getOptions, | ||
data: root | ||
getOptions: extra.getOptions || defaultGetOptions, | ||
jsonOptions: extra.jsonOptions, | ||
root | ||
}; | ||
const jsList = [...persistJS(extra.baseJs), ...persistJS([...(scripts || []), { | ||
const jsList = [...persistJS([...extra.baseJs, ...(scripts || []), { | ||
type: 'iife', | ||
data: { | ||
fn: (getMarkmap, getOptions, data) => { | ||
const { | ||
Markmap | ||
} = getMarkmap(); | ||
window.mm = Markmap.create('svg#mindmap', getOptions == null ? void 0 : getOptions(), data); | ||
fn: (getMarkmap, getOptions, root, jsonOptions) => { | ||
const markmap = getMarkmap(); | ||
window.mm = markmap.Markmap.create('svg#mindmap', getOptions == null ? void 0 : getOptions(markmap, jsonOptions), root); | ||
}, | ||
@@ -52,5 +48,6 @@ getParams: ({ | ||
getOptions, | ||
data | ||
root, | ||
jsonOptions | ||
}) => { | ||
return [getMarkmap, getOptions, data]; | ||
return [getMarkmap, getOptions, root, jsonOptions]; | ||
} | ||
@@ -134,3 +131,3 @@ } | ||
if (!grammar) { | ||
if (!grammar && lang) { | ||
loadLanguages([lang]); | ||
@@ -157,3 +154,3 @@ grammar = Prism.languages[lang]; | ||
data: { | ||
href: `https://cdn.jsdelivr.net/npm/prismjs@${"1.25.0"}/themes/prism.css` | ||
href: `https://cdn.jsdelivr.net/npm/prismjs@${"1.28.0"}/themes/prism.css` | ||
} | ||
@@ -219,14 +216,14 @@ }] | ||
function cleanNode(node, depth = 0) { | ||
if (node.t === 'heading') { | ||
if (node.type === 'heading') { | ||
// drop all paragraphs | ||
node.c = node.c.filter(item => item.t !== 'paragraph'); | ||
} else if (node.t === 'list_item') { | ||
var _node$p; | ||
node.children = node.children.filter(item => item.type !== 'paragraph'); | ||
} else if (node.type === 'list_item') { | ||
var _node$payload; | ||
// keep first paragraph as content of list_item, drop others | ||
node.c = node.c.filter(item => { | ||
if (['paragraph', 'fence'].includes(item.t)) { | ||
if (!node.v) { | ||
node.v = item.v; | ||
node.p = _extends({}, node.p, item.p); | ||
node.children = node.children.filter(item => { | ||
if (['paragraph', 'fence'].includes(item.type)) { | ||
if (!node.content) { | ||
node.content = item.content; | ||
node.payload = _extends({}, node.payload, item.payload); | ||
} | ||
@@ -240,12 +237,12 @@ | ||
if (((_node$p = node.p) == null ? void 0 : _node$p.index) != null) { | ||
node.v = `${node.p.index}. ${node.v}`; | ||
if (((_node$payload = node.payload) == null ? void 0 : _node$payload.index) != null) { | ||
node.content = `${node.payload.index}. ${node.content}`; | ||
} | ||
} else if (node.t === 'ordered_list') { | ||
var _node$p$start, _node$p2; | ||
} else if (node.type === 'ordered_list') { | ||
var _node$payload$startIn, _node$payload2; | ||
let index = (_node$p$start = (_node$p2 = node.p) == null ? void 0 : _node$p2.start) != null ? _node$p$start : 1; | ||
node.c.forEach(item => { | ||
if (item.t === 'list_item') { | ||
item.p = _extends({}, item.p, { | ||
let index = (_node$payload$startIn = (_node$payload2 = node.payload) == null ? void 0 : _node$payload2.startIndex) != null ? _node$payload$startIn : 1; | ||
node.children.forEach(item => { | ||
if (item.type === 'list_item') { | ||
item.payload = _extends({}, item.payload, { | ||
index | ||
@@ -258,13 +255,13 @@ }); | ||
if (node.c.length === 0) { | ||
delete node.c; | ||
if (node.children.length === 0) { | ||
delete node.children; | ||
} else { | ||
node.c.forEach(child => cleanNode(child, depth + 1)); | ||
node.children.forEach(child => cleanNode(child, depth + 1)); | ||
if (node.c.length === 1 && !node.c[0].v) { | ||
node.c = node.c[0].c; | ||
if (node.children.length === 1 && !node.children[0].content) { | ||
node.children = node.children[0].children; | ||
} | ||
} | ||
node.d = depth; | ||
node.depth = depth; | ||
} | ||
@@ -286,3 +283,3 @@ | ||
this.assetsMap = assetsMap; | ||
const md = new Remarkable({ | ||
const md = new Remarkable('full', { | ||
html: true, | ||
@@ -292,3 +289,2 @@ breaks: true, | ||
}); | ||
md.block.ruler.enable(['deflist']); | ||
md.renderer.rules.htmltag = wrapFunction(md.renderer.rules.htmltag, { | ||
@@ -306,10 +302,9 @@ after: ctx => { | ||
md | ||
} = this; // TODO deal with <dl><dt> | ||
} = this; | ||
const root = { | ||
t: 'root', | ||
d: 0, | ||
v: '', | ||
c: [], | ||
p: {} | ||
type: 'root', | ||
depth: 0, | ||
content: '', | ||
children: [], | ||
payload: {} | ||
}; | ||
@@ -333,3 +328,3 @@ const stack = [root]; | ||
while (((_current = current) == null ? void 0 : _current.d) >= depth) { | ||
while (((_current = current) == null ? void 0 : _current.depth) >= depth) { | ||
var _current; | ||
@@ -343,6 +338,6 @@ | ||
depth = Math.max(depth, ((_current2 = current) == null ? void 0 : _current2.d) || 0) + 1; | ||
depth = Math.max(depth, ((_current2 = current) == null ? void 0 : _current2.depth) || 0) + 1; | ||
if (type === 'ordered_list') { | ||
payload.start = token.order; | ||
payload.startIndex = token.order; | ||
} | ||
@@ -352,15 +347,15 @@ } | ||
const item = { | ||
t: type, | ||
d: depth, | ||
p: payload, | ||
v: '', | ||
c: [] | ||
type, | ||
depth, | ||
payload, | ||
content: '', | ||
children: [] | ||
}; | ||
current.c.push(item); | ||
current.children.push(item); | ||
stack.push(item); | ||
} else if (!current) { | ||
continue; | ||
} else if (token.type === `${current.t}_close`) { | ||
if (current.t === 'heading') { | ||
depth = current.d; | ||
} else if (token.type === `${current.type}_close`) { | ||
if (current.type === 'heading') { | ||
depth = current.depth; | ||
} else { | ||
@@ -376,3 +371,3 @@ stack.pop(); | ||
if (data === 'fold') { | ||
current.p.f = true; | ||
current.payload.fold = true; | ||
ctx.result = ''; | ||
@@ -383,3 +378,3 @@ } | ||
revoke(); | ||
current.v = `${current.v || ''}${text}`; | ||
current.content = `${current.content || ''}${text}`; | ||
} else if (token.type === 'fence') { | ||
@@ -390,7 +385,7 @@ let result = md.renderer.render([token], md.options, {}); // Remarkable only adds className to `<code>` but not `<pre>`, copy it to make PrismJS style work. | ||
if (matches) result = result.replace('<pre>', `<pre${matches[1]}>`); | ||
current.c.push({ | ||
t: token.type, | ||
d: depth + 1, | ||
v: result, | ||
c: [] | ||
current.children.push({ | ||
type: token.type, | ||
depth: depth + 1, | ||
content: result, | ||
children: [] | ||
}); | ||
@@ -404,3 +399,3 @@ } else ; | ||
transform(content) { | ||
var _root$c; | ||
var _root$children; | ||
@@ -414,3 +409,3 @@ const context = { | ||
cleanNode(root); | ||
if (((_root$c = root.c) == null ? void 0 : _root$c.length) === 1) root = root.c[0]; | ||
if (((_root$children = root.children) == null ? void 0 : _root$children.length) === 1) root = root.children[0]; | ||
return _extends({}, context, { | ||
@@ -417,0 +412,0 @@ root |
@@ -1,2 +0,2 @@ | ||
/*! markmap-lib v0.12.0 | MIT License */ | ||
/*! markmap-lib v0.13.0-alpha.0 | MIT License */ | ||
'use strict'; | ||
@@ -21,3 +21,3 @@ | ||
const template = "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n<title>Markmap</title>\n<style>\n* {\n margin: 0;\n padding: 0;\n}\n#mindmap {\n display: block;\n width: 100vw;\n height: 100vh;\n}\n</style>\n<!--CSS-->\n</head>\n<body>\n<svg id=\"mindmap\"></svg>\n<!--JS-->\n</body>\n</html>\n"; | ||
const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.2.7"}`].map(src => ({ | ||
const BASE_JS = [`https://cdn.jsdelivr.net/npm/d3@${"6.7.0"}`, `https://cdn.jsdelivr.net/npm/markmap-view@${"0.13.0-alpha.0"}`].map(src => ({ | ||
type: 'script', | ||
@@ -28,9 +28,6 @@ data: { | ||
})); | ||
const defaultGetOptions = (markmap, jsonOptions) => markmap.deriveOptions(jsonOptions); | ||
function fillTemplate(root, assets, extra) { | ||
if (typeof extra === 'function') { | ||
extra = { | ||
getOptions: extra | ||
}; | ||
} | ||
extra = _extends__default({ | ||
@@ -46,13 +43,12 @@ baseJs: BASE_JS | ||
getMarkmap: () => window.markmap, | ||
getOptions: extra.getOptions, | ||
data: root | ||
getOptions: extra.getOptions || defaultGetOptions, | ||
jsonOptions: extra.jsonOptions, | ||
root | ||
}; | ||
const jsList = [...markmapCommon.persistJS(extra.baseJs), ...markmapCommon.persistJS([...(scripts || []), { | ||
const jsList = [...markmapCommon.persistJS([...extra.baseJs, ...(scripts || []), { | ||
type: 'iife', | ||
data: { | ||
fn: (getMarkmap, getOptions, data) => { | ||
const { | ||
Markmap | ||
} = getMarkmap(); | ||
window.mm = Markmap.create('svg#mindmap', getOptions == null ? void 0 : getOptions(), data); | ||
fn: (getMarkmap, getOptions, root, jsonOptions) => { | ||
const markmap = getMarkmap(); | ||
window.mm = markmap.Markmap.create('svg#mindmap', getOptions == null ? void 0 : getOptions(markmap, jsonOptions), root); | ||
}, | ||
@@ -62,5 +58,6 @@ getParams: ({ | ||
getOptions, | ||
data | ||
root, | ||
jsonOptions | ||
}) => { | ||
return [getMarkmap, getOptions, data]; | ||
return [getMarkmap, getOptions, root, jsonOptions]; | ||
} | ||
@@ -144,3 +141,3 @@ } | ||
if (!grammar) { | ||
if (!grammar && lang) { | ||
loadLanguages__default([lang]); | ||
@@ -167,3 +164,3 @@ grammar = Prism__default.languages[lang]; | ||
data: { | ||
href: `https://cdn.jsdelivr.net/npm/prismjs@${"1.25.0"}/themes/prism.css` | ||
href: `https://cdn.jsdelivr.net/npm/prismjs@${"1.28.0"}/themes/prism.css` | ||
} | ||
@@ -229,14 +226,14 @@ }] | ||
function cleanNode(node, depth = 0) { | ||
if (node.t === 'heading') { | ||
if (node.type === 'heading') { | ||
// drop all paragraphs | ||
node.c = node.c.filter(item => item.t !== 'paragraph'); | ||
} else if (node.t === 'list_item') { | ||
var _node$p; | ||
node.children = node.children.filter(item => item.type !== 'paragraph'); | ||
} else if (node.type === 'list_item') { | ||
var _node$payload; | ||
// keep first paragraph as content of list_item, drop others | ||
node.c = node.c.filter(item => { | ||
if (['paragraph', 'fence'].includes(item.t)) { | ||
if (!node.v) { | ||
node.v = item.v; | ||
node.p = _extends__default({}, node.p, item.p); | ||
node.children = node.children.filter(item => { | ||
if (['paragraph', 'fence'].includes(item.type)) { | ||
if (!node.content) { | ||
node.content = item.content; | ||
node.payload = _extends__default({}, node.payload, item.payload); | ||
} | ||
@@ -250,12 +247,12 @@ | ||
if (((_node$p = node.p) == null ? void 0 : _node$p.index) != null) { | ||
node.v = `${node.p.index}. ${node.v}`; | ||
if (((_node$payload = node.payload) == null ? void 0 : _node$payload.index) != null) { | ||
node.content = `${node.payload.index}. ${node.content}`; | ||
} | ||
} else if (node.t === 'ordered_list') { | ||
var _node$p$start, _node$p2; | ||
} else if (node.type === 'ordered_list') { | ||
var _node$payload$startIn, _node$payload2; | ||
let index = (_node$p$start = (_node$p2 = node.p) == null ? void 0 : _node$p2.start) != null ? _node$p$start : 1; | ||
node.c.forEach(item => { | ||
if (item.t === 'list_item') { | ||
item.p = _extends__default({}, item.p, { | ||
let index = (_node$payload$startIn = (_node$payload2 = node.payload) == null ? void 0 : _node$payload2.startIndex) != null ? _node$payload$startIn : 1; | ||
node.children.forEach(item => { | ||
if (item.type === 'list_item') { | ||
item.payload = _extends__default({}, item.payload, { | ||
index | ||
@@ -268,13 +265,13 @@ }); | ||
if (node.c.length === 0) { | ||
delete node.c; | ||
if (node.children.length === 0) { | ||
delete node.children; | ||
} else { | ||
node.c.forEach(child => cleanNode(child, depth + 1)); | ||
node.children.forEach(child => cleanNode(child, depth + 1)); | ||
if (node.c.length === 1 && !node.c[0].v) { | ||
node.c = node.c[0].c; | ||
if (node.children.length === 1 && !node.children[0].content) { | ||
node.children = node.children[0].children; | ||
} | ||
} | ||
node.d = depth; | ||
node.depth = depth; | ||
} | ||
@@ -296,3 +293,3 @@ | ||
this.assetsMap = assetsMap; | ||
const md = new remarkable.Remarkable({ | ||
const md = new remarkable.Remarkable('full', { | ||
html: true, | ||
@@ -302,3 +299,2 @@ breaks: true, | ||
}); | ||
md.block.ruler.enable(['deflist']); | ||
md.renderer.rules.htmltag = markmapCommon.wrapFunction(md.renderer.rules.htmltag, { | ||
@@ -316,10 +312,9 @@ after: ctx => { | ||
md | ||
} = this; // TODO deal with <dl><dt> | ||
} = this; | ||
const root = { | ||
t: 'root', | ||
d: 0, | ||
v: '', | ||
c: [], | ||
p: {} | ||
type: 'root', | ||
depth: 0, | ||
content: '', | ||
children: [], | ||
payload: {} | ||
}; | ||
@@ -343,3 +338,3 @@ const stack = [root]; | ||
while (((_current = current) == null ? void 0 : _current.d) >= depth) { | ||
while (((_current = current) == null ? void 0 : _current.depth) >= depth) { | ||
var _current; | ||
@@ -353,6 +348,6 @@ | ||
depth = Math.max(depth, ((_current2 = current) == null ? void 0 : _current2.d) || 0) + 1; | ||
depth = Math.max(depth, ((_current2 = current) == null ? void 0 : _current2.depth) || 0) + 1; | ||
if (type === 'ordered_list') { | ||
payload.start = token.order; | ||
payload.startIndex = token.order; | ||
} | ||
@@ -362,15 +357,15 @@ } | ||
const item = { | ||
t: type, | ||
d: depth, | ||
p: payload, | ||
v: '', | ||
c: [] | ||
type, | ||
depth, | ||
payload, | ||
content: '', | ||
children: [] | ||
}; | ||
current.c.push(item); | ||
current.children.push(item); | ||
stack.push(item); | ||
} else if (!current) { | ||
continue; | ||
} else if (token.type === `${current.t}_close`) { | ||
if (current.t === 'heading') { | ||
depth = current.d; | ||
} else if (token.type === `${current.type}_close`) { | ||
if (current.type === 'heading') { | ||
depth = current.depth; | ||
} else { | ||
@@ -386,3 +381,3 @@ stack.pop(); | ||
if (data === 'fold') { | ||
current.p.f = true; | ||
current.payload.fold = true; | ||
ctx.result = ''; | ||
@@ -393,3 +388,3 @@ } | ||
revoke(); | ||
current.v = `${current.v || ''}${text}`; | ||
current.content = `${current.content || ''}${text}`; | ||
} else if (token.type === 'fence') { | ||
@@ -400,7 +395,7 @@ let result = md.renderer.render([token], md.options, {}); // Remarkable only adds className to `<code>` but not `<pre>`, copy it to make PrismJS style work. | ||
if (matches) result = result.replace('<pre>', `<pre${matches[1]}>`); | ||
current.c.push({ | ||
t: token.type, | ||
d: depth + 1, | ||
v: result, | ||
c: [] | ||
current.children.push({ | ||
type: token.type, | ||
depth: depth + 1, | ||
content: result, | ||
children: [] | ||
}); | ||
@@ -414,3 +409,3 @@ } else ; | ||
transform(content) { | ||
var _root$c; | ||
var _root$children; | ||
@@ -424,3 +419,3 @@ const context = { | ||
cleanNode(root); | ||
if (((_root$c = root.c) == null ? void 0 : _root$c.length) === 1) root = root.c[0]; | ||
if (((_root$children = root.children) == null ? void 0 : _root$children.length) === 1) root = root.children[0]; | ||
return _extends__default({}, context, { | ||
@@ -427,0 +422,0 @@ root |
{ | ||
"name": "markmap-lib", | ||
"version": "0.12.0", | ||
"version": "0.13.0-alpha.0", | ||
"description": "Visualize your Markdown as mindmaps with Markmap", | ||
@@ -38,3 +38,3 @@ "author": "Gerald <gera2ld@live.com>", | ||
"@types/remarkable": "^2.0.3", | ||
"markmap-view": "^0.2.7" | ||
"markmap-view": "^0.13.0-alpha.0" | ||
}, | ||
@@ -45,3 +45,3 @@ "dependencies": { | ||
"katex": "^0.15.1", | ||
"markmap-common": "^0.1.6", | ||
"markmap-common": "^0.13.0-alpha.0", | ||
"prismjs": "^1.25.0", | ||
@@ -51,3 +51,3 @@ "remarkable": "^2.0.1", | ||
}, | ||
"gitHead": "fbec667e1706813f9f60bea6a971f3820858ca40" | ||
"gitHead": "969aa149f36580954e77b7ba434e5c48b409cfc2" | ||
} |
import { JSItem, INode } from 'markmap-common'; | ||
import type { IMarkmapOptions, IMarkmapJSONOptions } from 'markmap-view'; | ||
import { IAssets } from './types'; | ||
export declare function fillTemplate(root: INode | undefined, assets: IAssets, extra?: { | ||
baseJs?: JSItem[]; | ||
getOptions?: () => any; | ||
} | (() => any)): string; | ||
jsonOptions?: IMarkmapJSONOptions; | ||
getOptions?: (markmap: typeof window.markmap, jsonOptions: IMarkmapJSONOptions) => Partial<IMarkmapOptions>; | ||
}): string; |
import type { Remarkable } from 'remarkable'; | ||
import { CSSItem, JSItem, INode, IWrapContext, Hook } from 'markmap-common'; | ||
declare type Htmltag = Remarkable.Rule<Remarkable.HtmlTagToken, string>; | ||
export interface ITransformHooks { | ||
@@ -15,3 +16,3 @@ /** | ||
*/ | ||
htmltag: Hook<[ctx: IWrapContext<any>]>; | ||
htmltag: Hook<[ctx: IWrapContext<Parameters<Htmltag>, ReturnType<Htmltag>>]>; | ||
/** | ||
@@ -46,3 +47,3 @@ * Indicate that the last transformation is not complete for reasons like | ||
features: IFeatures; | ||
frontmatter?: any; | ||
frontmatter?: unknown; | ||
} | ||
@@ -56,1 +57,2 @@ export interface ITransformResult extends ITransformContext { | ||
} | ||
export {}; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
460325
0.09%12173
0.64%+ Added
- Removed