markmap-lib 0.15.9-alpha.0 → 0.15.9-alpha.11

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.
@@ -3,7 +3,7 @@
3
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';
4
4
  const baseJsPaths = [
5
5
  `d3@${"7.8.5"}/dist/d3.min.js`,
6
- `markmap-view@${"0.15.9-alpha.0"}/dist/browser/index.js`
6
+ `markmap-view@${"0.15.8"}/dist/browser/index.js`
7
7
  ];
8
8
  const testPath = "npm2url/dist/index.cjs";
9
9
  const defaultProviders = {
@@ -14066,12 +14066,14 @@
14066
14066
  const parse = getParse((content, options, isDocument2, context) => options.xmlMode || options._useHtmlParser2 ? parseDocument(content, options) : parseWithParse5(content, options, isDocument2, context));
14067
14067
  const load$2 = getLoad(parse, (dom, options) => options.xmlMode || options._useHtmlParser2 ? render$1(dom, options) : renderWithParse5(dom));
14068
14068
  load$2([]);
14069
+ const MARKMAP_COMMENT_PREFIX = "markmap: ";
14069
14070
  const SELECTOR_HEADING = /^h[1-6]$/;
14070
14071
  const SELECTOR_LIST = /^[uo]l$/;
14071
14072
  const SELECTOR_LIST_ITEM = /^li$/;
14072
14073
  const defaultOptions = {
14073
- selector: "h1,h2,h3,h4,h5,h6,ul,ol,li,table,pre,p>img:first-child:last-child",
14074
- selectorPreserveContent: "table,pre",
14074
+ selector: "h1,h2,h3,h4,h5,h6,ul,ol,li,table,pre,p>img:only-child",
14075
+ selectorWrapper: "div,p",
14076
+ selectorNesting: "ul,ol,li",
14075
14077
  selectorPreserveTag: "table,pre,img"
14076
14078
  };
14077
14079
  function getLevel(tagName) {
@@ -14089,71 +14091,139 @@
14089
14091
  ...opts
14090
14092
  };
14091
14093
  const $2 = load$2(html2);
14094
+ const $root = $2("body");
14092
14095
  let id = 0;
14093
- const elMap = {
14094
- [id]: $2("<div>")
14095
- };
14096
- const root2 = {
14096
+ const rootNode = {
14097
14097
  id,
14098
14098
  tag: "",
14099
14099
  html: "",
14100
14100
  level: 0,
14101
+ parent: 0,
14101
14102
  childrenLevel: 0,
14102
- children: [],
14103
- parent: 0
14103
+ children: []
14104
14104
  };
14105
- const nodeMap = {
14106
- [id]: root2
14105
+ const elMap = {
14106
+ [id]: $2("<div>")
14107
14107
  };
14108
- let cur = root2;
14109
- $2(options.selector).each((_, el) => {
14108
+ const headingStack = [];
14109
+ let skippingHeading = 0;
14110
+ checkNode($root);
14111
+ walkTree(rootNode, (node, next2) => {
14112
+ next2();
14113
+ const $el = elMap[node.id];
14114
+ $el.contents().each((_, child) => {
14115
+ if (child.type === "comment") {
14116
+ const data22 = child.data.trim();
14117
+ if (data22.startsWith(MARKMAP_COMMENT_PREFIX)) {
14118
+ node.comments || (node.comments = []);
14119
+ node.comments.push(data22.slice(MARKMAP_COMMENT_PREFIX.length).trim());
14120
+ $2(child).remove();
14121
+ }
14122
+ }
14123
+ });
14124
+ const data2 = $el.data();
14125
+ if (data2 && Object.keys(data2).length) {
14126
+ node.data = data2;
14127
+ }
14128
+ node.html = (($el.is(options.selectorPreserveTag) ? $2.html($el) : $el.html()) || "").trimEnd();
14129
+ });
14130
+ return rootNode;
14131
+ function addChild($child, parent2, nesting) {
14132
+ const child = $child[0];
14110
14133
  const node = {
14111
14134
  id: ++id,
14112
- tag: el.tagName,
14135
+ tag: child.tagName,
14113
14136
  html: "",
14114
- level: getLevel(el.tagName),
14137
+ level: getLevel(child.tagName),
14115
14138
  childrenLevel: 0,
14116
- children: $2(el).is(options.selectorPreserveContent) ? void 0 : [],
14117
- parent: 0
14139
+ children: nesting ? [] : void 0,
14140
+ parent: parent2.id
14118
14141
  };
14119
- elMap[node.id] = $2(el);
14120
- nodeMap[node.id] = node;
14121
- if (node.level <= 6) {
14122
- while (cur !== root2 && (cur.level > 6 || cur.tag >= node.tag)) {
14123
- cur = nodeMap[cur.parent];
14142
+ if (parent2.children) {
14143
+ if (parent2.childrenLevel === 0 || parent2.childrenLevel > node.level) {
14144
+ parent2.children = [];
14145
+ parent2.childrenLevel = node.level;
14124
14146
  }
14125
- } else {
14126
- while (cur !== root2 && cur.level > 6 && !elMap[cur.id].find(el).length) {
14127
- cur = nodeMap[cur.parent];
14147
+ if (parent2.childrenLevel === node.level) {
14148
+ parent2.children.push(node);
14128
14149
  }
14129
14150
  }
14130
- if (cur.children) {
14131
- node.parent = cur.id;
14132
- const level = getLevel(node.tag);
14133
- if (!cur.childrenLevel || cur.childrenLevel > level) {
14134
- cur.childrenLevel = level;
14135
- cur.children = [];
14151
+ elMap[node.id] = $child;
14152
+ return node;
14153
+ }
14154
+ function getCurrentHeading(level) {
14155
+ let heading2;
14156
+ while ((heading2 = headingStack.at(-1)) && heading2.level >= level) {
14157
+ headingStack.pop();
14158
+ }
14159
+ return heading2 || rootNode;
14160
+ }
14161
+ function checkNode($el, node) {
14162
+ $el.children().each((_, child) => {
14163
+ const $child = $2(child);
14164
+ if ($child.is(options.selectorWrapper)) {
14165
+ checkNode($child);
14166
+ return;
14167
+ }
14168
+ if (!$child.is(options.selector)) {
14169
+ const level2 = getLevel(child.tagName);
14170
+ if (level2 <= 6) {
14171
+ skippingHeading = level2;
14172
+ }
14173
+ return;
14174
+ }
14175
+ const level = getLevel(child.tagName);
14176
+ if (skippingHeading > 0 && level > skippingHeading) {
14177
+ return;
14178
+ }
14179
+ skippingHeading = 0;
14180
+ if ($child.is(options.selectorNesting)) {
14181
+ const childNode2 = addChild(
14182
+ $child,
14183
+ node || getCurrentHeading(level),
14184
+ true
14185
+ );
14186
+ if (childNode2) {
14187
+ checkNode($child, childNode2);
14188
+ $child.remove();
14189
+ }
14190
+ return;
14136
14191
  }
14137
- if (cur.childrenLevel === level) {
14138
- cur.children.push(node);
14192
+ const isHeading = level <= 6;
14193
+ const childNode = addChild(
14194
+ $child,
14195
+ node || getCurrentHeading(level),
14196
+ isHeading
14197
+ );
14198
+ if (isHeading)
14199
+ headingStack.push(childNode);
14200
+ });
14201
+ }
14202
+ }
14203
+ function convertNode(htmlRoot) {
14204
+ return walkTree(htmlRoot, (htmlNode, next2) => {
14205
+ const node = {
14206
+ content: htmlNode.html,
14207
+ children: next2() || []
14208
+ };
14209
+ if (htmlNode.data) {
14210
+ node.payload = {
14211
+ ...htmlNode.data
14212
+ };
14213
+ }
14214
+ if (htmlNode.comments) {
14215
+ if (htmlNode.comments.includes("foldAll")) {
14216
+ node.payload = { ...node.payload, fold: 2 };
14217
+ } else if (htmlNode.comments.includes("fold")) {
14218
+ node.payload = { ...node.payload, fold: 1 };
14139
14219
  }
14140
- cur = node;
14141
14220
  }
14221
+ return node;
14142
14222
  });
14143
- walkTree(root2, (node, next2) => {
14144
- next2();
14145
- const $el = elMap[node.id];
14146
- $el.remove();
14147
- node.html = (($el.is(options.selectorPreserveTag) ? $2.html($el) : $el.html()) || "").trimEnd();
14148
- });
14149
- return root2;
14150
14223
  }
14151
14224
  function buildTree(html2, opts) {
14152
14225
  const htmlRoot = parseHtml(html2, opts);
14153
- return walkTree(htmlRoot, (node, next2) => ({
14154
- content: node.html,
14155
- children: next2() || []
14156
- }));
14226
+ return convertNode(htmlRoot);
14157
14227
  }
14158
14228
  var textarea;
14159
14229
  function decodeEntity(name2) {
@@ -17962,353 +18032,101 @@
17962
18032
  env = env || {};
17963
18033
  return this.renderer.render(this.parseInline(str2, env), this.options, env);
17964
18034
  };
17965
- const rkatex = (md, options) => {
17966
- const backslash = "\\";
17967
- const dollar = "$";
17968
- const opts = options || {};
17969
- const delimiter = opts.delimiter || dollar;
17970
- if (delimiter.length !== 1) {
17971
- throw new Error("invalid delimiter");
17972
- }
17973
- const katex = require$$0;
17974
- const renderKatex = (source, displayMode) => katex.renderToString(
17975
- source,
17976
- {
17977
- displayMode,
17978
- throwOnError: false
17979
- }
17980
- );
17981
- const parseBlockKatex = (state, startLine, endLine) => {
17982
- let haveEndMarker = false;
17983
- let pos = state.bMarks[startLine] + state.tShift[startLine];
17984
- let max = state.eMarks[startLine];
17985
- if (pos + 1 > max) {
17986
- return false;
17987
- }
17988
- const marker = state.src.charAt(pos);
17989
- if (marker !== delimiter) {
17990
- return false;
17991
- }
17992
- let mem = pos;
17993
- pos = state.skipChars(pos, marker);
17994
- let len = pos - mem;
17995
- if (len !== 2) {
17996
- return false;
17997
- }
17998
- let nextLine = startLine;
17999
- for (; ; ) {
18000
- ++nextLine;
18001
- if (nextLine >= endLine) {
18002
- break;
18003
- }
18004
- pos = mem = state.bMarks[nextLine] + state.tShift[nextLine];
18005
- max = state.eMarks[nextLine];
18006
- if (pos < max && state.tShift[nextLine] < state.blkIndent) {
18007
- break;
18008
- }
18009
- if (state.src.charAt(pos) !== delimiter) {
18010
- continue;
18011
- }
18012
- if (state.tShift[nextLine] - state.blkIndent >= 4) {
18013
- continue;
18014
- }
18015
- pos = state.skipChars(pos, marker);
18016
- if (pos - mem < len) {
18017
- continue;
18018
- }
18019
- pos = state.skipSpaces(pos);
18020
- if (pos < max) {
18021
- continue;
18022
- }
18023
- haveEndMarker = true;
18024
- break;
18025
- }
18026
- len = state.tShift[startLine];
18027
- state.line = nextLine + (haveEndMarker ? 1 : 0);
18028
- const content = state.getLines(startLine + 1, nextLine, len, true).replace(/[ \n]+/g, " ").trim();
18029
- state.tokens.push({
18030
- type: "katex",
18031
- params: null,
18032
- content,
18033
- lines: [startLine, state.line],
18034
- level: state.level,
18035
- block: true
18036
- });
18037
- return true;
18035
+ function createTransformHooks(transformer) {
18036
+ return {
18037
+ transformer,
18038
+ parser: new Hook(),
18039
+ beforeParse: new Hook(),
18040
+ afterParse: new Hook(),
18041
+ htmltag: new Hook(),
18042
+ retransform: new Hook()
18038
18043
  };
18039
- const parseInlineKatex = (state, silent) => {
18040
- const start = state.pos;
18041
- const max = state.posMax;
18042
- let pos = start;
18043
- if (state.src.charAt(pos) !== delimiter) {
18044
- return false;
18045
- }
18046
- ++pos;
18047
- while (pos < max && state.src.charAt(pos) === delimiter) {
18048
- ++pos;
18049
- }
18050
- const marker = state.src.slice(start, pos);
18051
- if (marker.length > 2) {
18052
- return false;
18053
- }
18054
- const spanStart = pos;
18055
- let escapedDepth = 0;
18056
- while (pos < max) {
18057
- const char = state.src.charAt(pos);
18058
- if (char === "{" && (pos == 0 || state.src.charAt(pos - 1) != backslash)) {
18059
- escapedDepth += 1;
18060
- } else if (char === "}" && (pos == 0 || state.src.charAt(pos - 1) != backslash)) {
18061
- escapedDepth -= 1;
18062
- if (escapedDepth < 0) {
18063
- return false;
18064
- }
18065
- } else if (char === delimiter && escapedDepth === 0) {
18066
- const matchStart = pos;
18067
- let matchEnd = pos + 1;
18068
- while (matchEnd < max && state.src.charAt(matchEnd) === delimiter) {
18069
- ++matchEnd;
18070
- }
18071
- if (matchEnd - matchStart === marker.length) {
18072
- if (!silent) {
18073
- const content = state.src.slice(spanStart, matchStart).replace(/[ \n]+/g, " ").trim();
18074
- state.push({ type: "katex", content, block: marker.length > 1, level: state.level });
18044
+ }
18045
+ function definePlugin(plugin2) {
18046
+ return plugin2;
18047
+ }
18048
+ const svg_marked = `<svg width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path d="M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2m-9 14-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8z"/></svg>`;
18049
+ const svg_unmarked = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 -3 24 24"><path fill-rule="evenodd" d="M6 5a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1zM3 6a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3v12a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-5z" clip-rule="evenodd"/></svg>`;
18050
+ const name$5 = "checkbox";
18051
+ const plugin$3 = definePlugin({
18052
+ name: name$5,
18053
+ transform(transformHooks) {
18054
+ transformHooks.parser.tap((md) => {
18055
+ md.core.ruler.before(
18056
+ "inline",
18057
+ "checkbox",
18058
+ (state) => {
18059
+ for (let i2 = 2; i2 < state.tokens.length; i2 += 1) {
18060
+ const token = state.tokens[i2];
18061
+ if (token.type === "inline" && token.content) {
18062
+ const prevType = state.tokens[i2 - 1].type;
18063
+ const prevPrevType = state.tokens[i2 - 2].type;
18064
+ if (prevType === "heading_open" || prevType === "paragraph_open" && prevPrevType === "list_item_open") {
18065
+ if (token.content.startsWith("[ ]")) {
18066
+ token.content = `${svg_unmarked} ${token.content.slice(3)}`;
18067
+ } else if (token.content.startsWith("[x]")) {
18068
+ token.content = `${svg_marked} ${token.content.slice(3)}`;
18069
+ }
18070
+ }
18071
+ }
18075
18072
  }
18076
- state.pos = matchEnd;
18077
- return true;
18078
- }
18079
- }
18080
- pos += 1;
18081
- }
18082
- if (!silent) {
18083
- state.pending += marker;
18073
+ return false;
18074
+ },
18075
+ {}
18076
+ );
18077
+ });
18078
+ return {};
18079
+ }
18080
+ });
18081
+ const checkbox = plugin$3;
18082
+ /*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */
18083
+ function isNothing(subject) {
18084
+ return typeof subject === "undefined" || subject === null;
18085
+ }
18086
+ function isObject(subject) {
18087
+ return typeof subject === "object" && subject !== null;
18088
+ }
18089
+ function toArray(sequence) {
18090
+ if (Array.isArray(sequence))
18091
+ return sequence;
18092
+ else if (isNothing(sequence))
18093
+ return [];
18094
+ return [sequence];
18095
+ }
18096
+ function extend(target, source) {
18097
+ var index2, length, key, sourceKeys;
18098
+ if (source) {
18099
+ sourceKeys = Object.keys(source);
18100
+ for (index2 = 0, length = sourceKeys.length; index2 < length; index2 += 1) {
18101
+ key = sourceKeys[index2];
18102
+ target[key] = source[key];
18084
18103
  }
18085
- state.pos += marker.length;
18086
- return true;
18087
- };
18088
- md.inline.ruler.push("katex", parseInlineKatex, options);
18089
- md.block.ruler.push("katex", parseBlockKatex, options);
18090
- md.renderer.rules.katex = (tokens, idx) => renderKatex(tokens[idx].content, tokens[idx].block);
18091
- md.renderer.rules.katex.delimiter = delimiter;
18092
- };
18093
- var remarkableKatex = rkatex;
18094
- const remarkableKatex$1 = /* @__PURE__ */ getDefaultExportFromCjs(remarkableKatex);
18095
- const name$3 = "katex";
18096
- const preloadScripts$1 = [
18097
- `katex@${"0.16.8"}/dist/katex.min.js`
18098
- ].map((path) => buildJSItem(path));
18099
- const webfontloader = buildJSItem(
18100
- `webfontloader@${"1.6.28"}/webfontloader.js`
18101
- );
18102
- webfontloader.data.defer = true;
18103
- const styles$1 = [`katex@${"0.16.8"}/dist/katex.min.css`].map(
18104
- (path) => buildCSSItem(path)
18105
- );
18106
- const config$1 = {
18107
- versions: {
18108
- katex: "0.16.8",
18109
- webfontloader: "1.6.28"
18110
- },
18111
- preloadScripts: preloadScripts$1,
18112
- scripts: [
18113
- {
18114
- type: "iife",
18115
- data: {
18116
- fn: (getMarkmap) => {
18117
- window.WebFontConfig = {
18118
- custom: {
18119
- families: [
18120
- "KaTeX_AMS",
18121
- "KaTeX_Caligraphic:n4,n7",
18122
- "KaTeX_Fraktur:n4,n7",
18123
- "KaTeX_Main:n4,n7,i4,i7",
18124
- "KaTeX_Math:i4,i7",
18125
- "KaTeX_Script",
18126
- "KaTeX_SansSerif:n4,n7,i4",
18127
- "KaTeX_Size1",
18128
- "KaTeX_Size2",
18129
- "KaTeX_Size3",
18130
- "KaTeX_Size4",
18131
- "KaTeX_Typewriter"
18132
- ]
18133
- },
18134
- active: () => {
18135
- getMarkmap().refreshHook.call();
18136
- }
18137
- };
18138
- },
18139
- getParams({ getMarkmap }) {
18140
- return [getMarkmap];
18141
- }
18142
- }
18143
- },
18144
- webfontloader
18145
- ],
18146
- styles: styles$1
18147
- };
18148
- function addDefaultVersions(paths, name2, version) {
18149
- return paths.map((path) => {
18150
- if (typeof path === "string" && !path.includes("://")) {
18151
- if (!path.startsWith("npm:")) {
18152
- path = `npm:${path}`;
18153
- }
18154
- const prefixLength = 4 + name2.length;
18155
- if (path.startsWith(`npm:${name2}/`)) {
18156
- path = `${path.slice(0, prefixLength)}@${version}${path.slice(
18157
- prefixLength
18158
- )}`;
18159
- }
18160
- }
18161
- return path;
18162
- });
18163
- }
18164
- function patchJSItem(urlBuilder, item) {
18165
- if (item.type === "script" && item.data.src) {
18166
- return {
18167
- ...item,
18168
- data: {
18169
- ...item.data,
18170
- src: urlBuilder.getFullUrl(item.data.src)
18171
- }
18172
- };
18173
- }
18174
- return item;
18175
- }
18176
- function patchCSSItem(urlBuilder, item) {
18177
- if (item.type === "stylesheet" && item.data.href) {
18178
- return {
18179
- ...item,
18180
- data: {
18181
- ...item.data,
18182
- href: urlBuilder.getFullUrl(item.data.href)
18183
- }
18184
- };
18185
- }
18186
- return item;
18187
- }
18188
- function createTransformHooks(transformer) {
18189
- return {
18190
- transformer,
18191
- parser: new Hook(),
18192
- beforeParse: new Hook(),
18193
- afterParse: new Hook(),
18194
- htmltag: new Hook(),
18195
- retransform: new Hook()
18196
- };
18197
- }
18198
- function definePlugin(plugin2) {
18199
- return plugin2;
18200
- }
18201
- const plugin$1 = definePlugin({
18202
- name: name$3,
18203
- config: config$1,
18204
- transform(transformHooks) {
18205
- var _a2, _b, _c, _d;
18206
- let loading;
18207
- const preloadScripts2 = ((_b = (_a2 = plugin$1.config) == null ? void 0 : _a2.preloadScripts) == null ? void 0 : _b.map(
18208
- (item) => patchJSItem(transformHooks.transformer.urlBuilder, item)
18209
- )) || [];
18210
- const autoload = () => {
18211
- loading || (loading = loadJS(preloadScripts2));
18212
- return loading;
18213
- };
18214
- const renderKatex = (source, displayMode) => {
18215
- const { katex } = window;
18216
- if (katex) {
18217
- return katex.renderToString(source, {
18218
- displayMode,
18219
- throwOnError: false
18220
- });
18221
- }
18222
- autoload().then(() => {
18223
- transformHooks.retransform.call();
18224
- });
18225
- return source;
18226
- };
18227
- let enableFeature = noop;
18228
- transformHooks.parser.tap((md) => {
18229
- md.use(remarkableKatex$1);
18230
- md.renderer.rules.katex = (tokens, idx) => {
18231
- enableFeature();
18232
- const result = renderKatex(tokens[idx].content, !!tokens[idx].block);
18233
- return result;
18234
- };
18235
- });
18236
- transformHooks.beforeParse.tap((_, context) => {
18237
- enableFeature = () => {
18238
- context.features[name$3] = true;
18239
- };
18240
- });
18241
- transformHooks.afterParse.tap((_, context) => {
18242
- var _a3;
18243
- const markmap = (_a3 = context.frontmatter) == null ? void 0 : _a3.markmap;
18244
- if (markmap) {
18245
- ["extraJs", "extraCss"].forEach((key) => {
18246
- var _a4, _b2;
18247
- const value = markmap[key];
18248
- if (value) {
18249
- markmap[key] = addDefaultVersions(
18250
- value,
18251
- name$3,
18252
- ((_b2 = (_a4 = plugin$1.config) == null ? void 0 : _a4.versions) == null ? void 0 : _b2.katex) || ""
18253
- );
18254
- }
18255
- });
18256
- }
18257
- });
18258
- return {
18259
- styles: (_c = plugin$1.config) == null ? void 0 : _c.styles,
18260
- scripts: (_d = plugin$1.config) == null ? void 0 : _d.scripts
18261
- };
18262
- }
18263
- });
18264
- /*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */
18265
- function isNothing(subject) {
18266
- return typeof subject === "undefined" || subject === null;
18267
- }
18268
- function isObject(subject) {
18269
- return typeof subject === "object" && subject !== null;
18270
- }
18271
- function toArray(sequence) {
18272
- if (Array.isArray(sequence))
18273
- return sequence;
18274
- else if (isNothing(sequence))
18275
- return [];
18276
- return [sequence];
18277
- }
18278
- function extend(target, source) {
18279
- var index2, length, key, sourceKeys;
18280
- if (source) {
18281
- sourceKeys = Object.keys(source);
18282
- for (index2 = 0, length = sourceKeys.length; index2 < length; index2 += 1) {
18283
- key = sourceKeys[index2];
18284
- target[key] = source[key];
18285
- }
18286
- }
18287
- return target;
18288
- }
18289
- function repeat(string, count) {
18290
- var result = "", cycle;
18291
- for (cycle = 0; cycle < count; cycle += 1) {
18292
- result += string;
18293
- }
18294
- return result;
18295
- }
18296
- function isNegativeZero(number) {
18297
- return number === 0 && Number.NEGATIVE_INFINITY === 1 / number;
18298
- }
18299
- var isNothing_1 = isNothing;
18300
- var isObject_1 = isObject;
18301
- var toArray_1 = toArray;
18302
- var repeat_1 = repeat;
18303
- var isNegativeZero_1 = isNegativeZero;
18304
- var extend_1 = extend;
18305
- var common = {
18306
- isNothing: isNothing_1,
18307
- isObject: isObject_1,
18308
- toArray: toArray_1,
18309
- repeat: repeat_1,
18310
- isNegativeZero: isNegativeZero_1,
18311
- extend: extend_1
18104
+ }
18105
+ return target;
18106
+ }
18107
+ function repeat(string, count) {
18108
+ var result = "", cycle;
18109
+ for (cycle = 0; cycle < count; cycle += 1) {
18110
+ result += string;
18111
+ }
18112
+ return result;
18113
+ }
18114
+ function isNegativeZero(number) {
18115
+ return number === 0 && Number.NEGATIVE_INFINITY === 1 / number;
18116
+ }
18117
+ var isNothing_1 = isNothing;
18118
+ var isObject_1 = isObject;
18119
+ var toArray_1 = toArray;
18120
+ var repeat_1 = repeat;
18121
+ var isNegativeZero_1 = isNegativeZero;
18122
+ var extend_1 = extend;
18123
+ var common = {
18124
+ isNothing: isNothing_1,
18125
+ isObject: isObject_1,
18126
+ toArray: toArray_1,
18127
+ repeat: repeat_1,
18128
+ isNegativeZero: isNegativeZero_1,
18129
+ extend: extend_1
18312
18130
  };
18313
18131
  function formatError(exception2, compact) {
18314
18132
  var where = "", message = exception2.reason || "(unknown reason)";
@@ -20949,9 +20767,10 @@
20949
20767
  safeLoadAll,
20950
20768
  safeDump
20951
20769
  };
20952
- const name$2 = "frontmatter";
20770
+ const yaml = jsYaml;
20771
+ const name$4 = "frontmatter";
20953
20772
  const frontmatter = definePlugin({
20954
- name: name$2,
20773
+ name: name$4,
20955
20774
  transform(transformHooks) {
20956
20775
  transformHooks.beforeParse.tap((md, context) => {
20957
20776
  const { content } = context;
@@ -20963,7 +20782,7 @@
20963
20782
  const raw = content.slice(4, match.index);
20964
20783
  let frontmatter2;
20965
20784
  try {
20966
- frontmatter2 = jsYaml.load(raw);
20785
+ frontmatter2 = yaml.load(raw);
20967
20786
  if (frontmatter2 == null ? void 0 : frontmatter2.markmap) {
20968
20787
  frontmatter2.markmap = normalizeMarkmapJsonOptions(
20969
20788
  frontmatter2.markmap
@@ -21005,54 +20824,52 @@
21005
20824
  return;
21006
20825
  return +value;
21007
20826
  }
21008
- const name$1 = "npmUrl";
21009
- const npmUrl = definePlugin({
21010
- name: name$1,
21011
- transform(transformHooks) {
21012
- transformHooks.afterParse.tap((_, context) => {
21013
- const { frontmatter: frontmatter2 } = context;
21014
- const markmap = frontmatter2 == null ? void 0 : frontmatter2.markmap;
21015
- if (markmap) {
21016
- ["extraJs", "extraCss"].forEach((key) => {
21017
- const value = markmap[key];
21018
- if (value) {
21019
- markmap[key] = value.map((path) => {
21020
- if (path.startsWith("npm:")) {
21021
- return transformHooks.transformer.urlBuilder.getFullUrl(
21022
- path.slice(4)
21023
- );
21024
- }
21025
- return path;
21026
- });
21027
- }
21028
- });
20827
+ function patchJSItem(urlBuilder, item) {
20828
+ if (item.type === "script" && item.data.src) {
20829
+ return {
20830
+ ...item,
20831
+ data: {
20832
+ ...item.data,
20833
+ src: urlBuilder.getFullUrl(item.data.src)
21029
20834
  }
21030
- });
21031
- return {};
20835
+ };
21032
20836
  }
21033
- });
21034
- const name = "hljs";
21035
- const preloadScripts = [
20837
+ return item;
20838
+ }
20839
+ function patchCSSItem(urlBuilder, item) {
20840
+ if (item.type === "stylesheet" && item.data.href) {
20841
+ return {
20842
+ ...item,
20843
+ data: {
20844
+ ...item.data,
20845
+ href: urlBuilder.getFullUrl(item.data.href)
20846
+ }
20847
+ };
20848
+ }
20849
+ return item;
20850
+ }
20851
+ const name$3 = "hljs";
20852
+ const preloadScripts$1 = [
21036
20853
  `@highlightjs/cdn-assets@${"11.8.0"}/highlight.min.js`
21037
20854
  ].map((path) => buildJSItem(path));
21038
- const styles = [
20855
+ const styles$1 = [
21039
20856
  `@highlightjs/cdn-assets@${"11.8.0"}/styles/default.min.css`
21040
20857
  // `highlight.js@${process.env.HLJS_VERSION}/styles/default.css`,
21041
20858
  ].map((path) => buildCSSItem(path));
21042
- const config = {
20859
+ const config$1 = {
21043
20860
  versions: {
21044
20861
  hljs: "11.8.0"
21045
20862
  },
21046
- preloadScripts,
21047
- styles
20863
+ preloadScripts: preloadScripts$1,
20864
+ styles: styles$1
21048
20865
  };
21049
- const plugin = definePlugin({
21050
- name,
21051
- config,
20866
+ const plugin$2 = definePlugin({
20867
+ name: name$3,
20868
+ config: config$1,
21052
20869
  transform(transformHooks) {
21053
20870
  var _a2, _b, _c;
21054
20871
  let loading;
21055
- const preloadScripts2 = ((_b = (_a2 = plugin.config) == null ? void 0 : _a2.preloadScripts) == null ? void 0 : _b.map(
20872
+ const preloadScripts2 = ((_b = (_a2 = plugin$2.config) == null ? void 0 : _a2.preloadScripts) == null ? void 0 : _b.map(
21056
20873
  (item) => patchJSItem(transformHooks.transformer.urlBuilder, item)
21057
20874
  )) || [];
21058
20875
  const autoload = () => {
@@ -21064,9 +20881,9 @@
21064
20881
  md.set({
21065
20882
  highlight: (str2, language) => {
21066
20883
  enableFeature();
21067
- const { hljs } = window;
21068
- if (hljs) {
21069
- return hljs.highlightAuto(str2, language ? [language] : void 0).value;
20884
+ const { hljs: hljs2 } = window;
20885
+ if (hljs2) {
20886
+ return hljs2.highlightAuto(str2, language ? [language] : void 0).value;
21070
20887
  }
21071
20888
  autoload().then(() => {
21072
20889
  transformHooks.retransform.call();
@@ -21077,15 +20894,345 @@
21077
20894
  });
21078
20895
  transformHooks.beforeParse.tap((_, context) => {
21079
20896
  enableFeature = () => {
21080
- context.features[name] = true;
20897
+ context.features[name$3] = true;
21081
20898
  };
21082
20899
  });
21083
20900
  return {
21084
- styles: (_c = plugin.config) == null ? void 0 : _c.styles
20901
+ styles: (_c = plugin$2.config) == null ? void 0 : _c.styles
21085
20902
  };
21086
20903
  }
21087
20904
  });
21088
- const plugins = [frontmatter, plugin$1, plugin, npmUrl];
20905
+ const hljs = plugin$2;
20906
+ const rkatex = (md, options) => {
20907
+ const backslash = "\\";
20908
+ const dollar = "$";
20909
+ const opts = options || {};
20910
+ const delimiter = opts.delimiter || dollar;
20911
+ if (delimiter.length !== 1) {
20912
+ throw new Error("invalid delimiter");
20913
+ }
20914
+ const katex2 = require$$0;
20915
+ const renderKatex = (source, displayMode) => katex2.renderToString(
20916
+ source,
20917
+ {
20918
+ displayMode,
20919
+ throwOnError: false
20920
+ }
20921
+ );
20922
+ const parseBlockKatex = (state, startLine, endLine) => {
20923
+ let haveEndMarker = false;
20924
+ let pos = state.bMarks[startLine] + state.tShift[startLine];
20925
+ let max = state.eMarks[startLine];
20926
+ if (pos + 1 > max) {
20927
+ return false;
20928
+ }
20929
+ const marker = state.src.charAt(pos);
20930
+ if (marker !== delimiter) {
20931
+ return false;
20932
+ }
20933
+ let mem = pos;
20934
+ pos = state.skipChars(pos, marker);
20935
+ let len = pos - mem;
20936
+ if (len !== 2) {
20937
+ return false;
20938
+ }
20939
+ let nextLine = startLine;
20940
+ for (; ; ) {
20941
+ ++nextLine;
20942
+ if (nextLine >= endLine) {
20943
+ break;
20944
+ }
20945
+ pos = mem = state.bMarks[nextLine] + state.tShift[nextLine];
20946
+ max = state.eMarks[nextLine];
20947
+ if (pos < max && state.tShift[nextLine] < state.blkIndent) {
20948
+ break;
20949
+ }
20950
+ if (state.src.charAt(pos) !== delimiter) {
20951
+ continue;
20952
+ }
20953
+ if (state.tShift[nextLine] - state.blkIndent >= 4) {
20954
+ continue;
20955
+ }
20956
+ pos = state.skipChars(pos, marker);
20957
+ if (pos - mem < len) {
20958
+ continue;
20959
+ }
20960
+ pos = state.skipSpaces(pos);
20961
+ if (pos < max) {
20962
+ continue;
20963
+ }
20964
+ haveEndMarker = true;
20965
+ break;
20966
+ }
20967
+ len = state.tShift[startLine];
20968
+ state.line = nextLine + (haveEndMarker ? 1 : 0);
20969
+ const content = state.getLines(startLine + 1, nextLine, len, true).replace(/[ \n]+/g, " ").trim();
20970
+ state.tokens.push({
20971
+ type: "katex",
20972
+ params: null,
20973
+ content,
20974
+ lines: [startLine, state.line],
20975
+ level: state.level,
20976
+ block: true
20977
+ });
20978
+ return true;
20979
+ };
20980
+ const parseInlineKatex = (state, silent) => {
20981
+ const start = state.pos;
20982
+ const max = state.posMax;
20983
+ let pos = start;
20984
+ if (state.src.charAt(pos) !== delimiter) {
20985
+ return false;
20986
+ }
20987
+ ++pos;
20988
+ while (pos < max && state.src.charAt(pos) === delimiter) {
20989
+ ++pos;
20990
+ }
20991
+ const marker = state.src.slice(start, pos);
20992
+ if (marker.length > 2) {
20993
+ return false;
20994
+ }
20995
+ const spanStart = pos;
20996
+ let escapedDepth = 0;
20997
+ while (pos < max) {
20998
+ const char = state.src.charAt(pos);
20999
+ if (char === "{" && (pos == 0 || state.src.charAt(pos - 1) != backslash)) {
21000
+ escapedDepth += 1;
21001
+ } else if (char === "}" && (pos == 0 || state.src.charAt(pos - 1) != backslash)) {
21002
+ escapedDepth -= 1;
21003
+ if (escapedDepth < 0) {
21004
+ return false;
21005
+ }
21006
+ } else if (char === delimiter && escapedDepth === 0) {
21007
+ const matchStart = pos;
21008
+ let matchEnd = pos + 1;
21009
+ while (matchEnd < max && state.src.charAt(matchEnd) === delimiter) {
21010
+ ++matchEnd;
21011
+ }
21012
+ if (matchEnd - matchStart === marker.length) {
21013
+ if (!silent) {
21014
+ const content = state.src.slice(spanStart, matchStart).replace(/[ \n]+/g, " ").trim();
21015
+ state.push({ type: "katex", content, block: marker.length > 1, level: state.level });
21016
+ }
21017
+ state.pos = matchEnd;
21018
+ return true;
21019
+ }
21020
+ }
21021
+ pos += 1;
21022
+ }
21023
+ if (!silent) {
21024
+ state.pending += marker;
21025
+ }
21026
+ state.pos += marker.length;
21027
+ return true;
21028
+ };
21029
+ md.inline.ruler.push("katex", parseInlineKatex, options);
21030
+ md.block.ruler.push("katex", parseBlockKatex, options);
21031
+ md.renderer.rules.katex = (tokens, idx) => renderKatex(tokens[idx].content, tokens[idx].block);
21032
+ md.renderer.rules.katex.delimiter = delimiter;
21033
+ };
21034
+ var remarkableKatex = rkatex;
21035
+ const remarkableKatex$1 = /* @__PURE__ */ getDefaultExportFromCjs(remarkableKatex);
21036
+ const name$2 = "katex";
21037
+ const preloadScripts = [
21038
+ `katex@${"0.16.8"}/dist/katex.min.js`
21039
+ ].map((path) => buildJSItem(path));
21040
+ const webfontloader = buildJSItem(
21041
+ `webfontloader@${"1.6.28"}/webfontloader.js`
21042
+ );
21043
+ webfontloader.data.defer = true;
21044
+ const styles = [`katex@${"0.16.8"}/dist/katex.min.css`].map(
21045
+ (path) => buildCSSItem(path)
21046
+ );
21047
+ const config = {
21048
+ versions: {
21049
+ katex: "0.16.8",
21050
+ webfontloader: "1.6.28"
21051
+ },
21052
+ preloadScripts,
21053
+ scripts: [
21054
+ {
21055
+ type: "iife",
21056
+ data: {
21057
+ fn: (getMarkmap) => {
21058
+ window.WebFontConfig = {
21059
+ custom: {
21060
+ families: [
21061
+ "KaTeX_AMS",
21062
+ "KaTeX_Caligraphic:n4,n7",
21063
+ "KaTeX_Fraktur:n4,n7",
21064
+ "KaTeX_Main:n4,n7,i4,i7",
21065
+ "KaTeX_Math:i4,i7",
21066
+ "KaTeX_Script",
21067
+ "KaTeX_SansSerif:n4,n7,i4",
21068
+ "KaTeX_Size1",
21069
+ "KaTeX_Size2",
21070
+ "KaTeX_Size3",
21071
+ "KaTeX_Size4",
21072
+ "KaTeX_Typewriter"
21073
+ ]
21074
+ },
21075
+ active: () => {
21076
+ getMarkmap().refreshHook.call();
21077
+ }
21078
+ };
21079
+ },
21080
+ getParams({ getMarkmap }) {
21081
+ return [getMarkmap];
21082
+ }
21083
+ }
21084
+ },
21085
+ webfontloader
21086
+ ],
21087
+ styles
21088
+ };
21089
+ function addDefaultVersions(paths, name2, version) {
21090
+ return paths.map((path) => {
21091
+ if (typeof path === "string" && !path.includes("://")) {
21092
+ if (!path.startsWith("npm:")) {
21093
+ path = `npm:${path}`;
21094
+ }
21095
+ const prefixLength = 4 + name2.length;
21096
+ if (path.startsWith(`npm:${name2}/`)) {
21097
+ path = `${path.slice(0, prefixLength)}@${version}${path.slice(
21098
+ prefixLength
21099
+ )}`;
21100
+ }
21101
+ }
21102
+ return path;
21103
+ });
21104
+ }
21105
+ const plugin$1 = definePlugin({
21106
+ name: name$2,
21107
+ config,
21108
+ transform(transformHooks) {
21109
+ var _a2, _b, _c, _d;
21110
+ let loading;
21111
+ const preloadScripts2 = ((_b = (_a2 = plugin$1.config) == null ? void 0 : _a2.preloadScripts) == null ? void 0 : _b.map(
21112
+ (item) => patchJSItem(transformHooks.transformer.urlBuilder, item)
21113
+ )) || [];
21114
+ const autoload = () => {
21115
+ loading || (loading = loadJS(preloadScripts2));
21116
+ return loading;
21117
+ };
21118
+ const renderKatex = (source, displayMode) => {
21119
+ const { katex: katex2 } = window;
21120
+ if (katex2) {
21121
+ return katex2.renderToString(source, {
21122
+ displayMode,
21123
+ throwOnError: false
21124
+ });
21125
+ }
21126
+ autoload().then(() => {
21127
+ transformHooks.retransform.call();
21128
+ });
21129
+ return source;
21130
+ };
21131
+ let enableFeature = noop;
21132
+ transformHooks.parser.tap((md) => {
21133
+ md.use(remarkableKatex$1);
21134
+ md.renderer.rules.katex = (tokens, idx) => {
21135
+ enableFeature();
21136
+ const result = renderKatex(tokens[idx].content, !!tokens[idx].block);
21137
+ return result;
21138
+ };
21139
+ });
21140
+ transformHooks.beforeParse.tap((_, context) => {
21141
+ enableFeature = () => {
21142
+ context.features[name$2] = true;
21143
+ };
21144
+ });
21145
+ transformHooks.afterParse.tap((_, context) => {
21146
+ var _a3;
21147
+ const markmap = (_a3 = context.frontmatter) == null ? void 0 : _a3.markmap;
21148
+ if (markmap) {
21149
+ ["extraJs", "extraCss"].forEach((key) => {
21150
+ var _a4, _b2;
21151
+ const value = markmap[key];
21152
+ if (value) {
21153
+ markmap[key] = addDefaultVersions(
21154
+ value,
21155
+ name$2,
21156
+ ((_b2 = (_a4 = plugin$1.config) == null ? void 0 : _a4.versions) == null ? void 0 : _b2.katex) || ""
21157
+ );
21158
+ }
21159
+ });
21160
+ }
21161
+ });
21162
+ return {
21163
+ styles: (_c = plugin$1.config) == null ? void 0 : _c.styles,
21164
+ scripts: (_d = plugin$1.config) == null ? void 0 : _d.scripts
21165
+ };
21166
+ }
21167
+ });
21168
+ const katex = plugin$1;
21169
+ const name$1 = "npmUrl";
21170
+ const npmUrl = definePlugin({
21171
+ name: name$1,
21172
+ transform(transformHooks) {
21173
+ transformHooks.afterParse.tap((_, context) => {
21174
+ const { frontmatter: frontmatter2 } = context;
21175
+ const markmap = frontmatter2 == null ? void 0 : frontmatter2.markmap;
21176
+ if (markmap) {
21177
+ ["extraJs", "extraCss"].forEach((key) => {
21178
+ const value = markmap[key];
21179
+ if (value) {
21180
+ markmap[key] = value.map((path) => {
21181
+ if (path.startsWith("npm:")) {
21182
+ return transformHooks.transformer.urlBuilder.getFullUrl(
21183
+ path.slice(4)
21184
+ );
21185
+ }
21186
+ return path;
21187
+ });
21188
+ }
21189
+ });
21190
+ }
21191
+ });
21192
+ return {};
21193
+ }
21194
+ });
21195
+ const name = "sourceLines";
21196
+ const plugin = definePlugin({
21197
+ name,
21198
+ transform(transformHooks) {
21199
+ transformHooks.parser.tap((md) => {
21200
+ Object.entries(md.renderer.rules).forEach(([key, value]) => {
21201
+ if (typeof value === "function") {
21202
+ md.renderer.rules[key] = patchRule(value);
21203
+ } else {
21204
+ Object.entries(value).forEach(([k, v]) => {
21205
+ value[k] = patchRule(v);
21206
+ });
21207
+ }
21208
+ });
21209
+ });
21210
+ return {};
21211
+ }
21212
+ });
21213
+ function patchRule(rule, _key) {
21214
+ return wrapFunction(rule, (render2, tokens, idx, ...rest) => {
21215
+ let html2 = render2(tokens, idx, ...rest);
21216
+ const { lines } = tokens[idx];
21217
+ if (lines) {
21218
+ html2 = html2.replace(
21219
+ /^<[\w-]+/,
21220
+ (m) => `${m} data-lines="${lines.join(",")}"`
21221
+ );
21222
+ }
21223
+ return html2;
21224
+ });
21225
+ }
21226
+ const sourceLines = plugin;
21227
+ const plugins = [
21228
+ frontmatter,
21229
+ katex,
21230
+ hljs,
21231
+ npmUrl,
21232
+ checkbox,
21233
+ sourceLines
21234
+ ];
21235
+ const builtInPlugins = plugins;
21089
21236
  function cleanNode(node) {
21090
21237
  while (!node.content && node.children.length === 1) {
21091
21238
  node = node.children[0];
@@ -21102,11 +21249,11 @@
21102
21249
  };
21103
21250
  }
21104
21251
  class Transformer {
21105
- constructor(plugins$1 = plugins) {
21252
+ constructor(plugins2 = builtInPlugins) {
21106
21253
  this.assetsMap = {};
21107
21254
  this.urlBuilder = new UrlBuilder();
21108
21255
  this.hooks = createTransformHooks(this);
21109
- this.plugins = plugins$1.map(
21256
+ this.plugins = plugins2.map(
21110
21257
  (plugin2) => typeof plugin2 === "function" ? plugin2() : plugin2
21111
21258
  );
21112
21259
  const assetsMap = {};
@@ -21223,7 +21370,7 @@
21223
21370
  };
21224
21371
  exports.Transformer = Transformer;
21225
21372
  exports.baseJsPaths = baseJsPaths;
21226
- exports.builtInPlugins = plugins;
21373
+ exports.builtInPlugins = builtInPlugins;
21227
21374
  exports.template = template;
21228
21375
  exports.transformerVersions = transformerVersions;
21229
21376
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });