markmap-lib 0.16.0 → 0.16.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.
- package/dist/browser/index.iife.js +99 -65
- package/dist/browser/index.mjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.no-plugins.js +1 -1
- package/dist/index.no-plugins.mjs +1 -1
- package/package.json +3 -3
|
@@ -13992,16 +13992,47 @@
|
|
|
13992
13992
|
const parse = getParse((content, options, isDocument2, context) => options.xmlMode || options._useHtmlParser2 ? parseDocument(content, options) : parseWithParse5(content, options, isDocument2, context));
|
|
13993
13993
|
const load$2 = getLoad(parse, (dom, options) => options.xmlMode || options._useHtmlParser2 ? render$1(dom, options) : renderWithParse5(dom));
|
|
13994
13994
|
load$2([]);
|
|
13995
|
+
const defaultSelectorRules = {
|
|
13996
|
+
"div,p": ({ $node }) => ({
|
|
13997
|
+
queue: $node.children()
|
|
13998
|
+
}),
|
|
13999
|
+
"h1,h2,h3,h4,h5,h6": ({ $node, getContent }) => ({
|
|
14000
|
+
...getContent($node.contents())
|
|
14001
|
+
}),
|
|
14002
|
+
"ul,ol": ({ $node }) => ({
|
|
14003
|
+
queue: $node.children(),
|
|
14004
|
+
nesting: true
|
|
14005
|
+
}),
|
|
14006
|
+
li: ({ $node, getContent }) => {
|
|
14007
|
+
const queue = $node.children().filter("ul,ol");
|
|
14008
|
+
let content;
|
|
14009
|
+
if ($node.contents().first().is("div,p")) {
|
|
14010
|
+
content = getContent($node.children().first());
|
|
14011
|
+
} else {
|
|
14012
|
+
let $contents = $node.contents();
|
|
14013
|
+
const i2 = $contents.index(queue);
|
|
14014
|
+
if (i2 >= 0)
|
|
14015
|
+
$contents = $contents.slice(0, i2);
|
|
14016
|
+
content = getContent($contents);
|
|
14017
|
+
}
|
|
14018
|
+
return {
|
|
14019
|
+
queue,
|
|
14020
|
+
nesting: true,
|
|
14021
|
+
...content
|
|
14022
|
+
};
|
|
14023
|
+
},
|
|
14024
|
+
"table,pre,p>img:only-child": ({ $node, getContent }) => ({
|
|
14025
|
+
...getContent($node)
|
|
14026
|
+
})
|
|
14027
|
+
};
|
|
14028
|
+
const defaultOptions = {
|
|
14029
|
+
selector: "h1,h2,h3,h4,h5,h6,ul,ol,li,table,pre,p>img:only-child",
|
|
14030
|
+
selectorRules: defaultSelectorRules
|
|
14031
|
+
};
|
|
13995
14032
|
const MARKMAP_COMMENT_PREFIX = "markmap: ";
|
|
13996
14033
|
const SELECTOR_HEADING = /^h[1-6]$/;
|
|
13997
14034
|
const SELECTOR_LIST = /^[uo]l$/;
|
|
13998
14035
|
const SELECTOR_LIST_ITEM = /^li$/;
|
|
13999
|
-
const defaultOptions = {
|
|
14000
|
-
selector: "h1,h2,h3,h4,h5,h6,ul,ol,li,table,pre,p>img:only-child",
|
|
14001
|
-
selectorWrapper: "div,p",
|
|
14002
|
-
selectorNesting: "ul,ol,li",
|
|
14003
|
-
selectorPreserveTag: "table,pre,img"
|
|
14004
|
-
};
|
|
14005
14036
|
function getLevel(tagName) {
|
|
14006
14037
|
if (SELECTOR_HEADING.test(tagName))
|
|
14007
14038
|
return +tagName[1];
|
|
@@ -14028,43 +14059,28 @@
|
|
|
14028
14059
|
childrenLevel: 0,
|
|
14029
14060
|
children: []
|
|
14030
14061
|
};
|
|
14031
|
-
const elMap = {
|
|
14032
|
-
[id]: $2("<div>")
|
|
14033
|
-
};
|
|
14034
14062
|
const headingStack = [];
|
|
14035
14063
|
let skippingHeading = 0;
|
|
14036
|
-
|
|
14037
|
-
walkTree(rootNode, (node, next2) => {
|
|
14038
|
-
next2();
|
|
14039
|
-
const $el = elMap[node.id];
|
|
14040
|
-
$el.contents().each((_, child) => {
|
|
14041
|
-
if (child.type === "comment") {
|
|
14042
|
-
const data22 = child.data.trim();
|
|
14043
|
-
if (data22.startsWith(MARKMAP_COMMENT_PREFIX)) {
|
|
14044
|
-
node.comments || (node.comments = []);
|
|
14045
|
-
node.comments.push(data22.slice(MARKMAP_COMMENT_PREFIX.length).trim());
|
|
14046
|
-
$2(child).remove();
|
|
14047
|
-
}
|
|
14048
|
-
}
|
|
14049
|
-
});
|
|
14050
|
-
const data2 = $el.data();
|
|
14051
|
-
if (data2 && Object.keys(data2).length) {
|
|
14052
|
-
node.data = data2;
|
|
14053
|
-
}
|
|
14054
|
-
node.html = (($el.is(options.selectorPreserveTag) ? $2.html($el) : $el.html()) || "").trimEnd();
|
|
14055
|
-
});
|
|
14064
|
+
checkNodes($root.children());
|
|
14056
14065
|
return rootNode;
|
|
14057
|
-
function addChild(
|
|
14058
|
-
|
|
14066
|
+
function addChild(props) {
|
|
14067
|
+
var _a2;
|
|
14068
|
+
const { parent: parent2 } = props;
|
|
14059
14069
|
const node = {
|
|
14060
14070
|
id: ++id,
|
|
14061
|
-
tag:
|
|
14062
|
-
|
|
14063
|
-
|
|
14071
|
+
tag: props.tagName,
|
|
14072
|
+
level: props.level,
|
|
14073
|
+
html: props.html,
|
|
14064
14074
|
childrenLevel: 0,
|
|
14065
|
-
children: nesting ? [] : void 0,
|
|
14075
|
+
children: props.nesting ? [] : void 0,
|
|
14066
14076
|
parent: parent2.id
|
|
14067
14077
|
};
|
|
14078
|
+
if ((_a2 = props.comments) == null ? void 0 : _a2.length) {
|
|
14079
|
+
node.comments = props.comments;
|
|
14080
|
+
}
|
|
14081
|
+
if (Object.keys(props.data || {}).length) {
|
|
14082
|
+
node.data = props.data;
|
|
14083
|
+
}
|
|
14068
14084
|
if (parent2.children) {
|
|
14069
14085
|
if (parent2.childrenLevel === 0 || parent2.childrenLevel > node.level) {
|
|
14070
14086
|
parent2.children = [];
|
|
@@ -14074,7 +14090,6 @@
|
|
|
14074
14090
|
parent2.children.push(node);
|
|
14075
14091
|
}
|
|
14076
14092
|
}
|
|
14077
|
-
elMap[node.id] = $child;
|
|
14078
14093
|
return node;
|
|
14079
14094
|
}
|
|
14080
14095
|
function getCurrentHeading(level) {
|
|
@@ -14084,45 +14099,64 @@
|
|
|
14084
14099
|
}
|
|
14085
14100
|
return heading2 || rootNode;
|
|
14086
14101
|
}
|
|
14087
|
-
function
|
|
14088
|
-
|
|
14102
|
+
function getContent($node) {
|
|
14103
|
+
var _a2;
|
|
14104
|
+
const result = extractMagicComments($node);
|
|
14105
|
+
const html22 = (_a2 = $2.html(result.$node)) == null ? void 0 : _a2.trimEnd();
|
|
14106
|
+
return { comments: result.comments, html: html22 };
|
|
14107
|
+
}
|
|
14108
|
+
function extractMagicComments($node) {
|
|
14109
|
+
const comments = [];
|
|
14110
|
+
$node = $node.filter((_, child) => {
|
|
14111
|
+
if (child.type === "comment") {
|
|
14112
|
+
const data2 = child.data.trim();
|
|
14113
|
+
if (data2.startsWith(MARKMAP_COMMENT_PREFIX)) {
|
|
14114
|
+
comments.push(data2.slice(MARKMAP_COMMENT_PREFIX.length).trim());
|
|
14115
|
+
return false;
|
|
14116
|
+
}
|
|
14117
|
+
}
|
|
14118
|
+
return true;
|
|
14119
|
+
});
|
|
14120
|
+
return { $node, comments };
|
|
14121
|
+
}
|
|
14122
|
+
function checkNodes($els, node) {
|
|
14123
|
+
$els.each((_, child) => {
|
|
14124
|
+
var _a2;
|
|
14089
14125
|
const $child = $2(child);
|
|
14090
|
-
|
|
14091
|
-
|
|
14126
|
+
const rule = (_a2 = Object.entries(options.selectorRules).find(
|
|
14127
|
+
([selector]) => $child.is(selector)
|
|
14128
|
+
)) == null ? void 0 : _a2[1];
|
|
14129
|
+
const result = rule == null ? void 0 : rule({ $node: $child, $: $2, getContent });
|
|
14130
|
+
if ((result == null ? void 0 : result.queue) && !result.nesting) {
|
|
14131
|
+
checkNodes(result.queue, node);
|
|
14092
14132
|
return;
|
|
14093
14133
|
}
|
|
14094
|
-
|
|
14095
|
-
|
|
14096
|
-
if (
|
|
14097
|
-
skippingHeading =
|
|
14134
|
+
const level = getLevel(child.tagName);
|
|
14135
|
+
if (!result) {
|
|
14136
|
+
if (level <= 6) {
|
|
14137
|
+
skippingHeading = level;
|
|
14098
14138
|
}
|
|
14099
14139
|
return;
|
|
14100
14140
|
}
|
|
14101
|
-
|
|
14102
|
-
if (skippingHeading > 0 && level > skippingHeading) {
|
|
14141
|
+
if (skippingHeading > 0 && level > skippingHeading)
|
|
14103
14142
|
return;
|
|
14104
|
-
|
|
14105
|
-
skippingHeading = 0;
|
|
14106
|
-
if ($child.is(options.selectorNesting)) {
|
|
14107
|
-
const childNode2 = addChild(
|
|
14108
|
-
$child,
|
|
14109
|
-
node || getCurrentHeading(level),
|
|
14110
|
-
true
|
|
14111
|
-
);
|
|
14112
|
-
if (childNode2) {
|
|
14113
|
-
checkNode($child, childNode2);
|
|
14114
|
-
$child.remove();
|
|
14115
|
-
}
|
|
14143
|
+
if (!$child.is(options.selector))
|
|
14116
14144
|
return;
|
|
14117
|
-
|
|
14145
|
+
skippingHeading = 0;
|
|
14118
14146
|
const isHeading = level <= 6;
|
|
14119
|
-
const childNode = addChild(
|
|
14120
|
-
|
|
14121
|
-
|
|
14122
|
-
|
|
14123
|
-
|
|
14147
|
+
const childNode = addChild({
|
|
14148
|
+
parent: node || getCurrentHeading(level),
|
|
14149
|
+
nesting: !!result.queue || isHeading,
|
|
14150
|
+
tagName: child.tagName,
|
|
14151
|
+
level,
|
|
14152
|
+
html: result.html || "",
|
|
14153
|
+
comments: result.comments,
|
|
14154
|
+
data: $child.data()
|
|
14155
|
+
});
|
|
14124
14156
|
if (isHeading)
|
|
14125
14157
|
headingStack.push(childNode);
|
|
14158
|
+
if (result.queue)
|
|
14159
|
+
checkNodes(result.queue, childNode);
|
|
14126
14160
|
});
|
|
14127
14161
|
}
|
|
14128
14162
|
}
|
|
@@ -21252,7 +21286,7 @@
|
|
|
21252
21286
|
}
|
|
21253
21287
|
}
|
|
21254
21288
|
const transformerVersions = {
|
|
21255
|
-
"markmap-lib": "0.16.
|
|
21289
|
+
"markmap-lib": "0.16.1"
|
|
21256
21290
|
};
|
|
21257
21291
|
exports.Transformer = Transformer;
|
|
21258
21292
|
exports.builtInPlugins = builtInPlugins;
|
package/dist/browser/index.mjs
CHANGED
package/dist/index.js
CHANGED
package/dist/index.mjs
CHANGED
package/dist/index.no-plugins.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markmap-lib",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"description": "Visualize your Markdown as mindmaps with Markmap",
|
|
5
5
|
"author": "Gerald <gera2ld@live.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"highlight.js": "^11.8.0",
|
|
68
68
|
"js-yaml": "^4.1.0",
|
|
69
69
|
"katex": "^0.16.8",
|
|
70
|
-
"markmap-html-parser": "0.16.
|
|
70
|
+
"markmap-html-parser": "0.16.1",
|
|
71
71
|
"markmap-view": "0.16.0",
|
|
72
72
|
"prismjs": "^1.29.0",
|
|
73
73
|
"remarkable": "^2.0.1",
|
|
@@ -90,5 +90,5 @@
|
|
|
90
90
|
"^(.*\\.svg)\\?raw$": "$1"
|
|
91
91
|
}
|
|
92
92
|
},
|
|
93
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "f10ad62ef03e02a1843484cca51521f48989fab7"
|
|
94
94
|
}
|