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

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,8 +3,10 @@
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.9-alpha.6"}/dist/browser/index.js`
7
7
  ];
8
+ 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>`;
9
+ 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>`;
8
10
  const testPath = "npm2url/dist/index.cjs";
9
11
  const defaultProviders = {
10
12
  jsdelivr: (path) => `https://cdn.jsdelivr.net/npm/${path}`,
@@ -14066,12 +14068,14 @@
14066
14068
  const parse = getParse((content, options, isDocument2, context) => options.xmlMode || options._useHtmlParser2 ? parseDocument(content, options) : parseWithParse5(content, options, isDocument2, context));
14067
14069
  const load$2 = getLoad(parse, (dom, options) => options.xmlMode || options._useHtmlParser2 ? render$1(dom, options) : renderWithParse5(dom));
14068
14070
  load$2([]);
14071
+ const MARKMAP_COMMENT_PREFIX = "markmap: ";
14069
14072
  const SELECTOR_HEADING = /^h[1-6]$/;
14070
14073
  const SELECTOR_LIST = /^[uo]l$/;
14071
14074
  const SELECTOR_LIST_ITEM = /^li$/;
14072
14075
  const defaultOptions = {
14073
14076
  selector: "h1,h2,h3,h4,h5,h6,ul,ol,li,table,pre,p>img:first-child:last-child",
14074
- selectorPreserveContent: "table,pre",
14077
+ selectorWrapper: "div,p",
14078
+ selectorNesting: "ul,ol,li",
14075
14079
  selectorPreserveTag: "table,pre,img"
14076
14080
  };
14077
14081
  function getLevel(tagName) {
@@ -14089,71 +14093,139 @@
14089
14093
  ...opts
14090
14094
  };
14091
14095
  const $2 = load$2(html2);
14096
+ const $root = $2("body");
14092
14097
  let id = 0;
14093
- const elMap = {
14094
- [id]: $2("<div>")
14095
- };
14096
- const root2 = {
14098
+ const rootNode = {
14097
14099
  id,
14098
14100
  tag: "",
14099
14101
  html: "",
14100
14102
  level: 0,
14103
+ parent: 0,
14101
14104
  childrenLevel: 0,
14102
- children: [],
14103
- parent: 0
14105
+ children: []
14104
14106
  };
14105
- const nodeMap = {
14106
- [id]: root2
14107
+ const elMap = {
14108
+ [id]: $2("<div>")
14107
14109
  };
14108
- let cur = root2;
14109
- $2(options.selector).each((_, el) => {
14110
+ const headingStack = [];
14111
+ let skippingHeading = 0;
14112
+ checkNode($root);
14113
+ walkTree(rootNode, (node, next2) => {
14114
+ next2();
14115
+ const $el = elMap[node.id];
14116
+ $el.contents().each((_, child) => {
14117
+ if (child.type === "comment") {
14118
+ const data22 = child.data.trim();
14119
+ if (data22.startsWith(MARKMAP_COMMENT_PREFIX)) {
14120
+ node.comments || (node.comments = []);
14121
+ node.comments.push(data22.slice(MARKMAP_COMMENT_PREFIX.length).trim());
14122
+ $2(child).remove();
14123
+ }
14124
+ }
14125
+ });
14126
+ const data2 = $el.data();
14127
+ if (data2 && Object.keys(data2).length) {
14128
+ node.data = data2;
14129
+ }
14130
+ node.html = (($el.is(options.selectorPreserveTag) ? $2.html($el) : $el.html()) || "").trimEnd();
14131
+ });
14132
+ return rootNode;
14133
+ function addChild($child, parent2, nesting) {
14134
+ const child = $child[0];
14110
14135
  const node = {
14111
14136
  id: ++id,
14112
- tag: el.tagName,
14137
+ tag: child.tagName,
14113
14138
  html: "",
14114
- level: getLevel(el.tagName),
14139
+ level: getLevel(child.tagName),
14115
14140
  childrenLevel: 0,
14116
- children: $2(el).is(options.selectorPreserveContent) ? void 0 : [],
14117
- parent: 0
14141
+ children: nesting ? [] : void 0,
14142
+ parent: parent2.id
14118
14143
  };
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];
14144
+ if (parent2.children) {
14145
+ if (parent2.childrenLevel === 0 || parent2.childrenLevel > node.level) {
14146
+ parent2.children = [];
14147
+ parent2.childrenLevel = node.level;
14124
14148
  }
14125
- } else {
14126
- while (cur !== root2 && cur.level > 6 && !elMap[cur.id].find(el).length) {
14127
- cur = nodeMap[cur.parent];
14149
+ if (parent2.childrenLevel === node.level) {
14150
+ parent2.children.push(node);
14128
14151
  }
14129
14152
  }
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 = [];
14153
+ elMap[node.id] = $child;
14154
+ return node;
14155
+ }
14156
+ function getCurrentHeading(level) {
14157
+ let heading2;
14158
+ while ((heading2 = headingStack.at(-1)) && heading2.level >= level) {
14159
+ headingStack.pop();
14160
+ }
14161
+ return heading2 || rootNode;
14162
+ }
14163
+ function checkNode($el, node) {
14164
+ $el.children().each((_, child) => {
14165
+ const $child = $2(child);
14166
+ if ($child.is(options.selectorWrapper)) {
14167
+ checkNode($child);
14168
+ return;
14169
+ }
14170
+ if (!$child.is(options.selector)) {
14171
+ const level2 = getLevel(child.tagName);
14172
+ if (level2 <= 6) {
14173
+ skippingHeading = level2;
14174
+ }
14175
+ return;
14176
+ }
14177
+ const level = getLevel(child.tagName);
14178
+ if (skippingHeading > 0 && level > skippingHeading) {
14179
+ return;
14180
+ }
14181
+ skippingHeading = 0;
14182
+ if ($child.is(options.selectorNesting)) {
14183
+ const childNode2 = addChild(
14184
+ $child,
14185
+ node || getCurrentHeading(level),
14186
+ true
14187
+ );
14188
+ if (childNode2) {
14189
+ checkNode($child, childNode2);
14190
+ $child.remove();
14191
+ }
14192
+ return;
14136
14193
  }
14137
- if (cur.childrenLevel === level) {
14138
- cur.children.push(node);
14194
+ const isHeading = level <= 6;
14195
+ const childNode = addChild(
14196
+ $child,
14197
+ node || getCurrentHeading(level),
14198
+ isHeading
14199
+ );
14200
+ if (isHeading)
14201
+ headingStack.push(childNode);
14202
+ });
14203
+ }
14204
+ }
14205
+ function convertNode(htmlRoot) {
14206
+ return walkTree(htmlRoot, (htmlNode, next2) => {
14207
+ const node = {
14208
+ content: htmlNode.html,
14209
+ children: next2() || []
14210
+ };
14211
+ if (htmlNode.data) {
14212
+ node.payload = {
14213
+ ...htmlNode.data
14214
+ };
14215
+ }
14216
+ if (htmlNode.comments) {
14217
+ if (htmlNode.comments.includes("foldAll")) {
14218
+ node.payload = { ...node.payload, fold: 2 };
14219
+ } else if (htmlNode.comments.includes("fold")) {
14220
+ node.payload = { ...node.payload, fold: 1 };
14139
14221
  }
14140
- cur = node;
14141
14222
  }
14223
+ return node;
14142
14224
  });
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
14225
  }
14151
14226
  function buildTree(html2, opts) {
14152
14227
  const htmlRoot = parseHtml(html2, opts);
14153
- return walkTree(htmlRoot, (node, next2) => ({
14154
- content: node.html,
14155
- children: next2() || []
14156
- }));
14228
+ return convertNode(htmlRoot);
14157
14229
  }
14158
14230
  var textarea;
14159
14231
  function decodeEntity(name2) {
@@ -17962,353 +18034,98 @@
17962
18034
  env = env || {};
17963
18035
  return this.renderer.render(this.parseInline(str2, env), this.options, env);
17964
18036
  };
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;
18037
+ function createTransformHooks(transformer) {
18038
+ return {
18039
+ transformer,
18040
+ parser: new Hook(),
18041
+ beforeParse: new Hook(),
18042
+ afterParse: new Hook(),
18043
+ htmltag: new Hook(),
18044
+ retransform: new Hook()
18038
18045
  };
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 });
18046
+ }
18047
+ function definePlugin(plugin2) {
18048
+ return plugin2;
18049
+ }
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
+ /*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */
18082
+ function isNothing(subject) {
18083
+ return typeof subject === "undefined" || subject === null;
18084
+ }
18085
+ function isObject(subject) {
18086
+ return typeof subject === "object" && subject !== null;
18087
+ }
18088
+ function toArray(sequence) {
18089
+ if (Array.isArray(sequence))
18090
+ return sequence;
18091
+ else if (isNothing(sequence))
18092
+ return [];
18093
+ return [sequence];
18094
+ }
18095
+ function extend(target, source) {
18096
+ var index2, length, key, sourceKeys;
18097
+ if (source) {
18098
+ sourceKeys = Object.keys(source);
18099
+ for (index2 = 0, length = sourceKeys.length; index2 < length; index2 += 1) {
18100
+ key = sourceKeys[index2];
18101
+ target[key] = source[key];
18084
18102
  }
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
18103
+ }
18104
+ return target;
18105
+ }
18106
+ function repeat(string, count) {
18107
+ var result = "", cycle;
18108
+ for (cycle = 0; cycle < count; cycle += 1) {
18109
+ result += string;
18110
+ }
18111
+ return result;
18112
+ }
18113
+ function isNegativeZero(number) {
18114
+ return number === 0 && Number.NEGATIVE_INFINITY === 1 / number;
18115
+ }
18116
+ var isNothing_1 = isNothing;
18117
+ var isObject_1 = isObject;
18118
+ var toArray_1 = toArray;
18119
+ var repeat_1 = repeat;
18120
+ var isNegativeZero_1 = isNegativeZero;
18121
+ var extend_1 = extend;
18122
+ var common = {
18123
+ isNothing: isNothing_1,
18124
+ isObject: isObject_1,
18125
+ toArray: toArray_1,
18126
+ repeat: repeat_1,
18127
+ isNegativeZero: isNegativeZero_1,
18128
+ extend: extend_1
18312
18129
  };
18313
18130
  function formatError(exception2, compact) {
18314
18131
  var where = "", message = exception2.reason || "(unknown reason)";
@@ -20949,9 +20766,9 @@
20949
20766
  safeLoadAll,
20950
20767
  safeDump
20951
20768
  };
20952
- const name$2 = "frontmatter";
20769
+ const name$4 = "frontmatter";
20953
20770
  const frontmatter = definePlugin({
20954
- name: name$2,
20771
+ name: name$4,
20955
20772
  transform(transformHooks) {
20956
20773
  transformHooks.beforeParse.tap((md, context) => {
20957
20774
  const { content } = context;
@@ -21005,54 +20822,52 @@
21005
20822
  return;
21006
20823
  return +value;
21007
20824
  }
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
- });
20825
+ function patchJSItem(urlBuilder, item) {
20826
+ if (item.type === "script" && item.data.src) {
20827
+ return {
20828
+ ...item,
20829
+ data: {
20830
+ ...item.data,
20831
+ src: urlBuilder.getFullUrl(item.data.src)
21029
20832
  }
21030
- });
21031
- return {};
20833
+ };
21032
20834
  }
21033
- });
21034
- const name = "hljs";
21035
- const preloadScripts = [
20835
+ return item;
20836
+ }
20837
+ function patchCSSItem(urlBuilder, item) {
20838
+ if (item.type === "stylesheet" && item.data.href) {
20839
+ return {
20840
+ ...item,
20841
+ data: {
20842
+ ...item.data,
20843
+ href: urlBuilder.getFullUrl(item.data.href)
20844
+ }
20845
+ };
20846
+ }
20847
+ return item;
20848
+ }
20849
+ const name$3 = "hljs";
20850
+ const preloadScripts$1 = [
21036
20851
  `@highlightjs/cdn-assets@${"11.8.0"}/highlight.min.js`
21037
20852
  ].map((path) => buildJSItem(path));
21038
- const styles = [
20853
+ const styles$1 = [
21039
20854
  `@highlightjs/cdn-assets@${"11.8.0"}/styles/default.min.css`
21040
20855
  // `highlight.js@${process.env.HLJS_VERSION}/styles/default.css`,
21041
20856
  ].map((path) => buildCSSItem(path));
21042
- const config = {
20857
+ const config$1 = {
21043
20858
  versions: {
21044
20859
  hljs: "11.8.0"
21045
20860
  },
21046
- preloadScripts,
21047
- styles
20861
+ preloadScripts: preloadScripts$1,
20862
+ styles: styles$1
21048
20863
  };
21049
- const plugin = definePlugin({
21050
- name,
21051
- config,
20864
+ const plugin$2 = definePlugin({
20865
+ name: name$3,
20866
+ config: config$1,
21052
20867
  transform(transformHooks) {
21053
20868
  var _a2, _b, _c;
21054
20869
  let loading;
21055
- const preloadScripts2 = ((_b = (_a2 = plugin.config) == null ? void 0 : _a2.preloadScripts) == null ? void 0 : _b.map(
20870
+ const preloadScripts2 = ((_b = (_a2 = plugin$2.config) == null ? void 0 : _a2.preloadScripts) == null ? void 0 : _b.map(
21056
20871
  (item) => patchJSItem(transformHooks.transformer.urlBuilder, item)
21057
20872
  )) || [];
21058
20873
  const autoload = () => {
@@ -21077,15 +20892,341 @@
21077
20892
  });
21078
20893
  transformHooks.beforeParse.tap((_, context) => {
21079
20894
  enableFeature = () => {
21080
- context.features[name] = true;
20895
+ context.features[name$3] = true;
20896
+ };
20897
+ });
20898
+ return {
20899
+ styles: (_c = plugin$2.config) == null ? void 0 : _c.styles
20900
+ };
20901
+ }
20902
+ });
20903
+ const rkatex = (md, options) => {
20904
+ const backslash = "\\";
20905
+ const dollar = "$";
20906
+ const opts = options || {};
20907
+ const delimiter = opts.delimiter || dollar;
20908
+ if (delimiter.length !== 1) {
20909
+ throw new Error("invalid delimiter");
20910
+ }
20911
+ const katex = require$$0;
20912
+ const renderKatex = (source, displayMode) => katex.renderToString(
20913
+ source,
20914
+ {
20915
+ displayMode,
20916
+ throwOnError: false
20917
+ }
20918
+ );
20919
+ const parseBlockKatex = (state, startLine, endLine) => {
20920
+ let haveEndMarker = false;
20921
+ let pos = state.bMarks[startLine] + state.tShift[startLine];
20922
+ let max = state.eMarks[startLine];
20923
+ if (pos + 1 > max) {
20924
+ return false;
20925
+ }
20926
+ const marker = state.src.charAt(pos);
20927
+ if (marker !== delimiter) {
20928
+ return false;
20929
+ }
20930
+ let mem = pos;
20931
+ pos = state.skipChars(pos, marker);
20932
+ let len = pos - mem;
20933
+ if (len !== 2) {
20934
+ return false;
20935
+ }
20936
+ let nextLine = startLine;
20937
+ for (; ; ) {
20938
+ ++nextLine;
20939
+ if (nextLine >= endLine) {
20940
+ break;
20941
+ }
20942
+ pos = mem = state.bMarks[nextLine] + state.tShift[nextLine];
20943
+ max = state.eMarks[nextLine];
20944
+ if (pos < max && state.tShift[nextLine] < state.blkIndent) {
20945
+ break;
20946
+ }
20947
+ if (state.src.charAt(pos) !== delimiter) {
20948
+ continue;
20949
+ }
20950
+ if (state.tShift[nextLine] - state.blkIndent >= 4) {
20951
+ continue;
20952
+ }
20953
+ pos = state.skipChars(pos, marker);
20954
+ if (pos - mem < len) {
20955
+ continue;
20956
+ }
20957
+ pos = state.skipSpaces(pos);
20958
+ if (pos < max) {
20959
+ continue;
20960
+ }
20961
+ haveEndMarker = true;
20962
+ break;
20963
+ }
20964
+ len = state.tShift[startLine];
20965
+ state.line = nextLine + (haveEndMarker ? 1 : 0);
20966
+ const content = state.getLines(startLine + 1, nextLine, len, true).replace(/[ \n]+/g, " ").trim();
20967
+ state.tokens.push({
20968
+ type: "katex",
20969
+ params: null,
20970
+ content,
20971
+ lines: [startLine, state.line],
20972
+ level: state.level,
20973
+ block: true
20974
+ });
20975
+ return true;
20976
+ };
20977
+ const parseInlineKatex = (state, silent) => {
20978
+ const start = state.pos;
20979
+ const max = state.posMax;
20980
+ let pos = start;
20981
+ if (state.src.charAt(pos) !== delimiter) {
20982
+ return false;
20983
+ }
20984
+ ++pos;
20985
+ while (pos < max && state.src.charAt(pos) === delimiter) {
20986
+ ++pos;
20987
+ }
20988
+ const marker = state.src.slice(start, pos);
20989
+ if (marker.length > 2) {
20990
+ return false;
20991
+ }
20992
+ const spanStart = pos;
20993
+ let escapedDepth = 0;
20994
+ while (pos < max) {
20995
+ const char = state.src.charAt(pos);
20996
+ if (char === "{" && (pos == 0 || state.src.charAt(pos - 1) != backslash)) {
20997
+ escapedDepth += 1;
20998
+ } else if (char === "}" && (pos == 0 || state.src.charAt(pos - 1) != backslash)) {
20999
+ escapedDepth -= 1;
21000
+ if (escapedDepth < 0) {
21001
+ return false;
21002
+ }
21003
+ } else if (char === delimiter && escapedDepth === 0) {
21004
+ const matchStart = pos;
21005
+ let matchEnd = pos + 1;
21006
+ while (matchEnd < max && state.src.charAt(matchEnd) === delimiter) {
21007
+ ++matchEnd;
21008
+ }
21009
+ if (matchEnd - matchStart === marker.length) {
21010
+ if (!silent) {
21011
+ const content = state.src.slice(spanStart, matchStart).replace(/[ \n]+/g, " ").trim();
21012
+ state.push({ type: "katex", content, block: marker.length > 1, level: state.level });
21013
+ }
21014
+ state.pos = matchEnd;
21015
+ return true;
21016
+ }
21017
+ }
21018
+ pos += 1;
21019
+ }
21020
+ if (!silent) {
21021
+ state.pending += marker;
21022
+ }
21023
+ state.pos += marker.length;
21024
+ return true;
21025
+ };
21026
+ md.inline.ruler.push("katex", parseInlineKatex, options);
21027
+ md.block.ruler.push("katex", parseBlockKatex, options);
21028
+ md.renderer.rules.katex = (tokens, idx) => renderKatex(tokens[idx].content, tokens[idx].block);
21029
+ md.renderer.rules.katex.delimiter = delimiter;
21030
+ };
21031
+ var remarkableKatex = rkatex;
21032
+ const remarkableKatex$1 = /* @__PURE__ */ getDefaultExportFromCjs(remarkableKatex);
21033
+ const name$2 = "katex";
21034
+ const preloadScripts = [
21035
+ `katex@${"0.16.8"}/dist/katex.min.js`
21036
+ ].map((path) => buildJSItem(path));
21037
+ const webfontloader = buildJSItem(
21038
+ `webfontloader@${"1.6.28"}/webfontloader.js`
21039
+ );
21040
+ webfontloader.data.defer = true;
21041
+ const styles = [`katex@${"0.16.8"}/dist/katex.min.css`].map(
21042
+ (path) => buildCSSItem(path)
21043
+ );
21044
+ const config = {
21045
+ versions: {
21046
+ katex: "0.16.8",
21047
+ webfontloader: "1.6.28"
21048
+ },
21049
+ preloadScripts,
21050
+ scripts: [
21051
+ {
21052
+ type: "iife",
21053
+ data: {
21054
+ fn: (getMarkmap) => {
21055
+ window.WebFontConfig = {
21056
+ custom: {
21057
+ families: [
21058
+ "KaTeX_AMS",
21059
+ "KaTeX_Caligraphic:n4,n7",
21060
+ "KaTeX_Fraktur:n4,n7",
21061
+ "KaTeX_Main:n4,n7,i4,i7",
21062
+ "KaTeX_Math:i4,i7",
21063
+ "KaTeX_Script",
21064
+ "KaTeX_SansSerif:n4,n7,i4",
21065
+ "KaTeX_Size1",
21066
+ "KaTeX_Size2",
21067
+ "KaTeX_Size3",
21068
+ "KaTeX_Size4",
21069
+ "KaTeX_Typewriter"
21070
+ ]
21071
+ },
21072
+ active: () => {
21073
+ getMarkmap().refreshHook.call();
21074
+ }
21075
+ };
21076
+ },
21077
+ getParams({ getMarkmap }) {
21078
+ return [getMarkmap];
21079
+ }
21080
+ }
21081
+ },
21082
+ webfontloader
21083
+ ],
21084
+ styles
21085
+ };
21086
+ function addDefaultVersions(paths, name2, version) {
21087
+ return paths.map((path) => {
21088
+ if (typeof path === "string" && !path.includes("://")) {
21089
+ if (!path.startsWith("npm:")) {
21090
+ path = `npm:${path}`;
21091
+ }
21092
+ const prefixLength = 4 + name2.length;
21093
+ if (path.startsWith(`npm:${name2}/`)) {
21094
+ path = `${path.slice(0, prefixLength)}@${version}${path.slice(
21095
+ prefixLength
21096
+ )}`;
21097
+ }
21098
+ }
21099
+ return path;
21100
+ });
21101
+ }
21102
+ const plugin$1 = definePlugin({
21103
+ name: name$2,
21104
+ config,
21105
+ transform(transformHooks) {
21106
+ var _a2, _b, _c, _d;
21107
+ let loading;
21108
+ const preloadScripts2 = ((_b = (_a2 = plugin$1.config) == null ? void 0 : _a2.preloadScripts) == null ? void 0 : _b.map(
21109
+ (item) => patchJSItem(transformHooks.transformer.urlBuilder, item)
21110
+ )) || [];
21111
+ const autoload = () => {
21112
+ loading || (loading = loadJS(preloadScripts2));
21113
+ return loading;
21114
+ };
21115
+ const renderKatex = (source, displayMode) => {
21116
+ const { katex } = window;
21117
+ if (katex) {
21118
+ return katex.renderToString(source, {
21119
+ displayMode,
21120
+ throwOnError: false
21121
+ });
21122
+ }
21123
+ autoload().then(() => {
21124
+ transformHooks.retransform.call();
21125
+ });
21126
+ return source;
21127
+ };
21128
+ let enableFeature = noop;
21129
+ transformHooks.parser.tap((md) => {
21130
+ md.use(remarkableKatex$1);
21131
+ md.renderer.rules.katex = (tokens, idx) => {
21132
+ enableFeature();
21133
+ const result = renderKatex(tokens[idx].content, !!tokens[idx].block);
21134
+ return result;
21135
+ };
21136
+ });
21137
+ transformHooks.beforeParse.tap((_, context) => {
21138
+ enableFeature = () => {
21139
+ context.features[name$2] = true;
21081
21140
  };
21082
21141
  });
21142
+ transformHooks.afterParse.tap((_, context) => {
21143
+ var _a3;
21144
+ const markmap = (_a3 = context.frontmatter) == null ? void 0 : _a3.markmap;
21145
+ if (markmap) {
21146
+ ["extraJs", "extraCss"].forEach((key) => {
21147
+ var _a4, _b2;
21148
+ const value = markmap[key];
21149
+ if (value) {
21150
+ markmap[key] = addDefaultVersions(
21151
+ value,
21152
+ name$2,
21153
+ ((_b2 = (_a4 = plugin$1.config) == null ? void 0 : _a4.versions) == null ? void 0 : _b2.katex) || ""
21154
+ );
21155
+ }
21156
+ });
21157
+ }
21158
+ });
21083
21159
  return {
21084
- styles: (_c = plugin.config) == null ? void 0 : _c.styles
21160
+ styles: (_c = plugin$1.config) == null ? void 0 : _c.styles,
21161
+ scripts: (_d = plugin$1.config) == null ? void 0 : _d.scripts
21085
21162
  };
21086
21163
  }
21087
21164
  });
21088
- const plugins = [frontmatter, plugin$1, plugin, npmUrl];
21165
+ const name$1 = "npmUrl";
21166
+ const npmUrl = definePlugin({
21167
+ name: name$1,
21168
+ transform(transformHooks) {
21169
+ transformHooks.afterParse.tap((_, context) => {
21170
+ const { frontmatter: frontmatter2 } = context;
21171
+ const markmap = frontmatter2 == null ? void 0 : frontmatter2.markmap;
21172
+ if (markmap) {
21173
+ ["extraJs", "extraCss"].forEach((key) => {
21174
+ const value = markmap[key];
21175
+ if (value) {
21176
+ markmap[key] = value.map((path) => {
21177
+ if (path.startsWith("npm:")) {
21178
+ return transformHooks.transformer.urlBuilder.getFullUrl(
21179
+ path.slice(4)
21180
+ );
21181
+ }
21182
+ return path;
21183
+ });
21184
+ }
21185
+ });
21186
+ }
21187
+ });
21188
+ return {};
21189
+ }
21190
+ });
21191
+ const name = "sourceLines";
21192
+ const plugin = definePlugin({
21193
+ name,
21194
+ transform(transformHooks) {
21195
+ transformHooks.parser.tap((md) => {
21196
+ Object.entries(md.renderer.rules).forEach(([key, value]) => {
21197
+ if (typeof value === "function") {
21198
+ md.renderer.rules[key] = patchRule(value);
21199
+ } else {
21200
+ Object.entries(value).forEach(([k, v]) => {
21201
+ value[k] = patchRule(v);
21202
+ });
21203
+ }
21204
+ });
21205
+ });
21206
+ return {};
21207
+ }
21208
+ });
21209
+ function patchRule(rule) {
21210
+ return wrapFunction(rule, (render2, tokens, idx, ...rest) => {
21211
+ let html2 = render2(tokens, idx, ...rest);
21212
+ const { lines } = tokens[idx];
21213
+ if (lines) {
21214
+ html2 = html2.replace(
21215
+ /^<[\w-]+/,
21216
+ (m) => `${m} data-lines="${lines.join(",")}"`
21217
+ );
21218
+ }
21219
+ return html2;
21220
+ });
21221
+ }
21222
+ const plugins = [
21223
+ frontmatter,
21224
+ plugin$1,
21225
+ plugin$2,
21226
+ npmUrl,
21227
+ plugin$3,
21228
+ plugin
21229
+ ];
21089
21230
  function cleanNode(node) {
21090
21231
  while (!node.content && node.children.length === 1) {
21091
21232
  node = node.children[0];
@@ -21224,6 +21365,8 @@
21224
21365
  exports.Transformer = Transformer;
21225
21366
  exports.baseJsPaths = baseJsPaths;
21226
21367
  exports.builtInPlugins = plugins;
21368
+ exports.svg_marked = svg_marked;
21369
+ exports.svg_unmarked = svg_unmarked;
21227
21370
  exports.template = template;
21228
21371
  exports.transformerVersions = transformerVersions;
21229
21372
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });