@the_dissidents/libemmm 0.0.7 → 0.0.8

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/index.js CHANGED
@@ -41,6 +41,7 @@ __export(index_exports, {
41
41
  SystemModifierDefinition: () => SystemModifierDefinition,
42
42
  debugPrint: () => debugPrint,
43
43
  emmmVersion: () => emmmVersion,
44
+ helper: () => modifier_helper_exports,
44
45
  messages: () => messages_exports,
45
46
  parse: () => parse,
46
47
  setDebugLevel: () => setDebugLevel
@@ -78,6 +79,9 @@ var ModifierBase = class {
78
79
  this.slotType = slotType;
79
80
  if (args) Object.assign(this, args);
80
81
  }
82
+ /**
83
+ * Common values: heading, emphasis, keyword, highlight, commentary, comment, link, quote
84
+ */
81
85
  roleHint;
82
86
  /**
83
87
  * If true, any modifier encountered inside it will *not* be expanded *during parse-content*,
@@ -87,7 +91,7 @@ var ModifierBase = class {
87
91
  delayContentExpansion = false;
88
92
  /**
89
93
  * If true, such a modifier will always be expanded whenever it is encountered, *even if*
90
- * contained in a modifier with `delayContentExpansion`. In the vast majority of cases,
94
+ * it is contained in a modifier with `delayContentExpansion`. In the vast majority of cases,
91
95
  * you shouldn't be using this.
92
96
  */
93
97
  alwaysTryExpand = false;
@@ -341,14 +345,14 @@ var StringSource = class {
341
345
  }
342
346
  return [line, pos - linepos];
343
347
  }
344
- getLineStart(n) {
348
+ getRowStart(n) {
345
349
  assert(n >= 0);
346
350
  if (n >= this.lineMap.length) return Infinity;
347
351
  return this.lineMap[n];
348
352
  }
349
- getLine(n) {
350
- const start = this.getLineStart(n);
351
- const end = this.getLineStart(n + 1);
353
+ getRow(n) {
354
+ const start = this.getRowStart(n);
355
+ const end = this.getRowStart(n + 1);
352
356
  if (start === Infinity) return void 0;
353
357
  return this.src.substring(start, end - 1);
354
358
  }
@@ -482,7 +486,7 @@ function debugPrintRange(loc, context = 1) {
482
486
  const endLine = Math.min(loc.source.nLines - 1, er + context);
483
487
  let lines = [];
484
488
  for (let i = startLine; i <= endLine; i++) {
485
- const line = loc.source.getLine(i);
489
+ const line = loc.source.getRow(i);
486
490
  lines.push((i + 1).toString().padStart(rowWidth) + " | " + line);
487
491
  if (i >= sr && i <= er) {
488
492
  const startPos = i == sr ? sc : 0;
@@ -1021,6 +1025,7 @@ var Parser = class {
1021
1025
  end: to ?? this.scanner.position()
1022
1026
  };
1023
1027
  }
1028
+ /* istanbul ignore next -- @preserve */
1024
1029
  #defs(type) {
1025
1030
  switch (type) {
1026
1031
  case 5 /* SystemModifier */:
@@ -1554,9 +1559,9 @@ function parse(scanner, cxt) {
1554
1559
 
1555
1560
  // src/renderer.ts
1556
1561
  var RenderContext = class {
1557
- constructor(config2, parseContext, state) {
1562
+ constructor(config2, parsedDocument, state) {
1558
1563
  this.config = config2;
1559
- this.parseContext = parseContext;
1564
+ this.parsedDocument = parsedDocument;
1560
1565
  this.state = state;
1561
1566
  }
1562
1567
  renderEntity(node) {
@@ -1594,7 +1599,7 @@ var RenderConfiguration = class _RenderConfiguration {
1594
1599
  blockRenderers = /* @__PURE__ */ new Map();
1595
1600
  inlineRenderers = /* @__PURE__ */ new Map();
1596
1601
  render(doc, state) {
1597
- let cxt = new RenderContext(this, doc.context, state);
1602
+ let cxt = new RenderContext(this, doc, state);
1598
1603
  let results = doc.toStripped().root.content.map((x) => cxt.renderEntity(x)).filter((x) => x !== void 0);
1599
1604
  return this.postprocessor(results, cxt);
1600
1605
  }
@@ -1617,6 +1622,14 @@ var RenderConfiguration = class _RenderConfiguration {
1617
1622
  };
1618
1623
 
1619
1624
  // src/modifier-helper.ts
1625
+ var modifier_helper_exports = {};
1626
+ __export(modifier_helper_exports, {
1627
+ checkArgumentLength: () => checkArgumentLength,
1628
+ checkArguments: () => checkArguments,
1629
+ onlyPermitPlaintextParagraph: () => onlyPermitPlaintextParagraph,
1630
+ onlyPermitSimpleParagraphs: () => onlyPermitSimpleParagraphs,
1631
+ onlyPermitSingleBlock: () => onlyPermitSingleBlock
1632
+ });
1620
1633
  function checkArgumentLength(node, min, max = min) {
1621
1634
  if (min !== void 0 && node.arguments.length < min || max !== void 0 && node.arguments.length > max) {
1622
1635
  return [new ArgumentCountMismatchMessage({
@@ -2439,44 +2452,23 @@ function resolveId(id, cxt) {
2439
2452
  value = cxt.variables.get(id);
2440
2453
  return value;
2441
2454
  }
2442
- var ifdefBlock = (name, x) => new BlockModifierDefinition(
2443
- name,
2444
- 0 /* Normal */,
2445
- {
2446
- prepareExpand(node, cxt) {
2447
- const check = checkArguments(node, 1);
2448
- if (check) return check;
2449
- const arg = node.arguments[0];
2450
- const id = arg.expansion;
2451
- if (id == "") return [new InvalidArgumentMessage(arg.location)];
2452
- const value = resolveId(id, cxt);
2453
- node.state = value !== void 0;
2454
- return [];
2455
- },
2456
- expand(node) {
2457
- return node.state == x ? node.content : [];
2458
- }
2459
- }
2460
- );
2461
- var ifdefInline = (name, x) => new InlineModifierDefinition(
2462
- name,
2463
- 0 /* Normal */,
2464
- {
2465
- prepareExpand(node, cxt) {
2466
- const check = checkArguments(node, 1);
2467
- if (check) return check;
2468
- const arg = node.arguments[0];
2469
- const id = arg.expansion;
2470
- if (id == "") return [new InvalidArgumentMessage(arg.location)];
2471
- const value = resolveId(id, cxt);
2472
- node.state = value !== void 0;
2473
- return [];
2474
- },
2475
- expand(node) {
2476
- return node.state == x ? node.content : [];
2477
- }
2455
+ var ifdefBody = (x) => ({
2456
+ prepareExpand(node, cxt) {
2457
+ const check = checkArguments(node, 1);
2458
+ if (check) return check;
2459
+ const arg = node.arguments[0];
2460
+ const id = arg.expansion;
2461
+ if (id == "") return [new InvalidArgumentMessage(arg.location)];
2462
+ const value = resolveId(id, cxt);
2463
+ node.state = value !== void 0;
2464
+ return [];
2465
+ },
2466
+ expand(node) {
2467
+ return node.state == x ? node.content : [];
2478
2468
  }
2479
- );
2469
+ });
2470
+ var ifdefBlock = (name, x) => new BlockModifierDefinition(name, 0 /* Normal */, ifdefBody(x));
2471
+ var ifdefInline = (name, x) => new InlineModifierDefinition(name, 0 /* Normal */, ifdefBody(x));
2480
2472
  var IfdefBlockMod = ifdefBlock("ifdef", true);
2481
2473
  var IfndefBlockMod = ifdefBlock("ifndef", false);
2482
2474
  var IfdefInlineMod = ifdefInline("ifdef", true);
@@ -2593,7 +2585,8 @@ builtin.inlineModifiers.add(
2593
2585
  builtin.argumentInterpolators.add(GetVarInterpolator);
2594
2586
  var BuiltinConfiguration = Object.freeze(builtin);
2595
2587
 
2596
- // src/default/bullets.ts
2588
+ // src/default/bullets.tsx
2589
+ var import_jsx_runtime = require("minimal-jsx-runtime/jsx-runtime");
2597
2590
  var bulletItemBlock = new BlockModifierDefinition(
2598
2591
  "bullet-item",
2599
2592
  0 /* Normal */,
@@ -2624,20 +2617,22 @@ var subItemBlock = new BlockModifierDefinition(
2624
2617
  );
2625
2618
  var BulletBlocks = [bulletItemBlock, orderedListItemBlock, subItemBlock];
2626
2619
  var BulletBlockRenderersHTML = [
2627
- [bulletItemBlock, (node, cxt) => {
2628
- return `<li>${cxt.state.render(node.content, cxt)}</li>`;
2629
- }],
2630
- [subItemBlock, (node, cxt) => {
2631
- return `<div class='subitem'>${cxt.state.render(node.content, cxt)}</div>`;
2632
- }],
2633
- [orderedListItemBlock, (node, cxt) => {
2634
- if (node.state === void 0)
2635
- return cxt.state.invalidBlock(node, "bad format");
2636
- return `<li value='${node.state}'>${cxt.state.render(node.content, cxt)}</li>`;
2637
- }]
2620
+ [
2621
+ bulletItemBlock,
2622
+ (node, cxt) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: cxt.state.render(node.content, cxt) })
2623
+ ],
2624
+ [
2625
+ subItemBlock,
2626
+ (node, cxt) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { class: "subitem", children: cxt.state.render(node.content, cxt) })
2627
+ ],
2628
+ [
2629
+ orderedListItemBlock,
2630
+ (node, cxt) => node.state === void 0 ? cxt.state.invalidBlock(node, "bad format") : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { value: node.state, children: cxt.state.render(node.content, cxt) })
2631
+ ]
2638
2632
  ];
2639
2633
 
2640
- // src/default/headings.ts
2634
+ // src/default/headings.tsx
2635
+ var import_jsx_runtime2 = require("minimal-jsx-runtime/jsx-runtime");
2641
2636
  var headings = Symbol();
2642
2637
  function initHeadings(cxt) {
2643
2638
  cxt.init(headings, {
@@ -2743,37 +2738,103 @@ var HeadingBlocks = [headingBlock, implicitHeadingBlock, numberedHeadingBlock];
2743
2738
  var HeadingBlockRenderersHTML = [
2744
2739
  [headingBlock, (node, cxt) => {
2745
2740
  if (node.state !== void 0) {
2746
- let tag = "h" + node.state.level;
2747
- let para = node.content[0];
2748
- return `<${tag}>${cxt.state.render(para.content, cxt)}</${tag}>`;
2741
+ const tag = "h" + node.state.level;
2742
+ const para = node.content[0];
2743
+ const element = document.createElement(tag);
2744
+ element.appendChild(cxt.state.render(para.content, cxt));
2745
+ return element;
2749
2746
  }
2750
2747
  return cxt.state.invalidBlock(node, "Bad format");
2751
2748
  }],
2752
2749
  [implicitHeadingBlock, (node, cxt) => {
2753
2750
  if (node.state !== void 0) {
2754
- let tag = "h" + node.state.level;
2755
- return `<${tag} class='implicit'></${tag}>`;
2751
+ const tag = "h" + node.state.level;
2752
+ const element = document.createElement(tag);
2753
+ element.className = "implicit";
2754
+ return element;
2756
2755
  }
2757
2756
  return cxt.state.invalidBlock(node, "Bad format");
2758
2757
  }],
2759
2758
  [numberedHeadingBlock, (node, cxt) => {
2760
2759
  if (node.state !== void 0) {
2761
- let tag = "h" + node.state.level;
2762
- let para = node.content[0];
2763
- return `<${tag}><span class='heading-number'>${node.state.name}</span>${cxt.state.render(para.content, cxt)}</${tag}>`;
2760
+ const tag = "h" + node.state.level;
2761
+ const para = node.content[0];
2762
+ const element = document.createElement(tag);
2763
+ element.appendChild(/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { class: "heading-number", children: node.state.name }));
2764
+ element.appendChild(cxt.state.render(para.content, cxt));
2765
+ return element;
2764
2766
  }
2765
2767
  return cxt.state.invalidBlock(node, "Bad format");
2766
2768
  }]
2767
2769
  ];
2768
2770
 
2769
- // src/default/notes.ts
2771
+ // src/default/notes.tsx
2772
+ var import_jsx_runtime3 = require("minimal-jsx-runtime/jsx-runtime");
2770
2773
  var notes = Symbol();
2771
2774
  function initNotes(cxt) {
2772
2775
  cxt.init(notes, {
2773
2776
  systems: /* @__PURE__ */ new Map(),
2774
- definitions: []
2777
+ defaultSystem: {
2778
+ position: "preserve",
2779
+ autonumber: false
2780
+ },
2781
+ definitions: [],
2782
+ currentId: 0
2775
2783
  });
2776
2784
  }
2785
+ function getSystem(cxt, name) {
2786
+ const defs = cxt.get(notes);
2787
+ let system;
2788
+ if (name) {
2789
+ if (!defs.systems.has(name)) {
2790
+ system = { ...defs.defaultSystem };
2791
+ defs.systems.set(name, system);
2792
+ } else {
2793
+ system = defs.systems.get(name);
2794
+ }
2795
+ } else {
2796
+ system = defs.defaultSystem;
2797
+ }
2798
+ return system;
2799
+ }
2800
+ var notePositionSystem = new SystemModifierDefinition(
2801
+ "note-position",
2802
+ 2 /* None */,
2803
+ {
2804
+ prepareExpand(node, cxt, immediate) {
2805
+ let msgs = checkArguments(node, 1, 2);
2806
+ if (msgs) return msgs;
2807
+ const type = node.arguments[0].expansion.trim();
2808
+ if (type != "global" && type != "preserve")
2809
+ return [new InvalidArgumentMessage(
2810
+ node.arguments[0].location,
2811
+ "should be `preserve` or `global`"
2812
+ )];
2813
+ const name = node.arguments.at(1)?.expansion.trim();
2814
+ getSystem(cxt, name).position = type;
2815
+ return [];
2816
+ }
2817
+ }
2818
+ );
2819
+ var noteRenumberingSystem = new SystemModifierDefinition(
2820
+ "note-renumbering",
2821
+ 2 /* None */,
2822
+ {
2823
+ prepareExpand(node, cxt, immediate) {
2824
+ let msgs = checkArguments(node, 1, 2);
2825
+ if (msgs) return msgs;
2826
+ const type = node.arguments[0].expansion.trim();
2827
+ if (type != "on" && type != "off")
2828
+ return [new InvalidArgumentMessage(
2829
+ node.arguments[0].location,
2830
+ "should be `preserve` or `global`"
2831
+ )];
2832
+ const name = node.arguments.at(1)?.expansion.trim();
2833
+ getSystem(cxt, name).autonumber = type == "on";
2834
+ return [];
2835
+ }
2836
+ }
2837
+ );
2777
2838
  var noteMarkerInline = new InlineModifierDefinition(
2778
2839
  "note",
2779
2840
  2 /* None */,
@@ -2795,13 +2856,15 @@ var noteInline = new InlineModifierDefinition(
2795
2856
  prepareExpand(node) {
2796
2857
  let msgs = checkArguments(node, 0, 1);
2797
2858
  if (msgs) return msgs;
2798
- node.state = node.arguments.at(0)?.expansion ?? "";
2859
+ node.state = node.arguments.at(0)?.expansion?.trim() ?? "";
2799
2860
  return [];
2800
2861
  },
2801
2862
  afterProcessExpansion(node, cxt) {
2802
2863
  if (node.state !== void 0) {
2803
- cxt.get(notes).definitions.push({
2864
+ const defs = cxt.get(notes);
2865
+ defs.definitions.push({
2804
2866
  system: "",
2867
+ id: defs.currentId,
2805
2868
  name: node.state,
2806
2869
  location: node.location,
2807
2870
  content: [{
@@ -2814,6 +2877,7 @@ var noteInline = new InlineModifierDefinition(
2814
2877
  content: node.content
2815
2878
  }]
2816
2879
  });
2880
+ defs.currentId++;
2817
2881
  }
2818
2882
  return [];
2819
2883
  }
@@ -2824,58 +2888,73 @@ var noteBlock = new BlockModifierDefinition(
2824
2888
  0 /* Normal */,
2825
2889
  {
2826
2890
  roleHint: "quote",
2827
- prepareExpand(node) {
2828
- let msgs = checkArguments(node, 1);
2891
+ prepareExpand(node, cxt) {
2892
+ let msgs = checkArguments(node, 1, 2);
2829
2893
  if (msgs) return msgs;
2830
- node.state = node.arguments[0].expansion;
2831
- return [];
2832
- },
2833
- afterProcessExpansion(node, cxt) {
2834
- if (node.state !== void 0) {
2835
- let content = stripNode(...node.content);
2836
- debug.trace(`add note: system=<${""}> name=${node.state} @${node.location.start}`);
2837
- debug.trace(`-->
2894
+ const name = node.arguments[0].expansion.trim();
2895
+ const system = node.arguments.at(1)?.expansion.trim() ?? "";
2896
+ const content = stripNode(...node.content);
2897
+ debug.trace(`add note: system=<${""}> name=${node.state} @${node.location.start}`);
2898
+ debug.trace(`-->
2838
2899
  `, debugPrint.node(...content));
2839
- cxt.get(notes).definitions.push({
2840
- system: "",
2841
- name: node.state,
2842
- location: node.location,
2843
- content
2844
- });
2845
- }
2846
- node.expansion = [];
2900
+ const defs = cxt.get(notes);
2901
+ const entry = {
2902
+ id: defs.currentId,
2903
+ system,
2904
+ name,
2905
+ location: node.location,
2906
+ content
2907
+ };
2908
+ defs.currentId++;
2909
+ defs.definitions.push(entry);
2910
+ node.state = entry;
2847
2911
  return [];
2848
2912
  }
2849
2913
  }
2850
2914
  );
2851
2915
  var NoteBlocks = [noteBlock];
2852
2916
  var NoteInlines = [noteInline, noteMarkerInline];
2917
+ var NoteSystems = [notePositionSystem, noteRenumberingSystem];
2918
+ function makeNoteHTML(def, cxt) {
2919
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { class: "note", id: `note-id-${def.id}`, children: [
2920
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { class: "note-name", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("a", { href: `#notemarker-id-${def.id}`, children: def.name }) }) }),
2921
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { class: "note-content", children: cxt.state.render(def.content, cxt) })
2922
+ ] });
2923
+ }
2853
2924
  var NoteInlineRenderersHTML = [
2854
2925
  [noteMarkerInline, (node, cxt) => {
2855
2926
  if (node.state === void 0)
2856
2927
  return cxt.state.invalidInline(node, "bad format");
2857
- const defs = cxt.parseContext.get(notes).definitions;
2928
+ const defs = cxt.parsedDocument.context.get(notes).definitions;
2858
2929
  const note = defs.findIndex((x) => (
2859
2930
  /*x.position >= node.start &&*/
2860
2931
  x.name == node.state
2861
2932
  ));
2862
- if (note < 0)
2863
- return `<sup class='note invalid'>Not found: ${node.state}</sup>`;
2864
- return `<sup class='note' id='notemarker-id-${note}'><a href='#note-id-${note}'>${node.state}</a></sup>`;
2933
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("sup", { class: "note", id: `notemarker-id-${note}`, children: note < 0 ? `Not found: ${node.state}` : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("a", { href: `#note-id-${note}`, children: node.state }) });
2934
+ }]
2935
+ ];
2936
+ var NoteBlockRenderersHTML = [
2937
+ [noteBlock, (node, cxt) => {
2938
+ if (node.state === void 0)
2939
+ return cxt.state.invalidBlock(node, "bad format");
2940
+ const defs = cxt.parsedDocument.context.get(notes);
2941
+ const system = defs.systems.get(node.state.system) ?? defs.defaultSystem;
2942
+ if (system.position != "preserve") return [];
2943
+ return makeNoteHTML(node.state, cxt);
2865
2944
  }]
2866
2945
  ];
2867
2946
  var NotesFooterPlugin = (cxt) => {
2868
- let defs = cxt.parseContext.get(notes).definitions;
2869
- if (defs.length == 0) return void 0;
2870
- return `<hr/>
2871
- <section class='notes'>
2872
- ${defs.map((x, i) => `<section class='note' id='note-id-${i}'>
2873
- <div class='note-name'><p><a href='#notemarker-id-${i}'>${x.name}</a></p></div>
2874
- <div class='note-content'>${cxt.state.render(x.content, cxt)}</div></section>`).join("\n")}
2875
- </section>`;
2947
+ const defs = cxt.parsedDocument.context.get(notes);
2948
+ const items = cxt.parsedDocument.context.get(notes).definitions.filter((x) => (defs.systems.get(x.system) ?? defs.defaultSystem).position == "global");
2949
+ if (items.length == 0) return void 0;
2950
+ return [
2951
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("hr", {}),
2952
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("section", { class: "notes-global", children: items.map((x) => makeNoteHTML(x, cxt)) })
2953
+ ];
2876
2954
  };
2877
2955
 
2878
- // src/default/code.ts
2956
+ // src/default/code.tsx
2957
+ var import_jsx_runtime4 = require("minimal-jsx-runtime/jsx-runtime");
2879
2958
  var CodeBlock = new BlockModifierDefinition(
2880
2959
  "code",
2881
2960
  1 /* Preformatted */,
@@ -2886,14 +2965,17 @@ var CodeInline = new InlineModifierDefinition(
2886
2965
  1 /* Preformatted */,
2887
2966
  { roleHint: "code" }
2888
2967
  );
2889
- var CodeBlockRendererHTML = [CodeBlock, (node, cxt) => {
2890
- return `<pre><code>${cxt.state.render(node.content, cxt)}</code></pre>`;
2891
- }];
2892
- var CodeInlineRendererHTML = [CodeInline, (node, cxt) => {
2893
- return `<span><code>${cxt.state.render(node.content, cxt)}</code></span>`;
2894
- }];
2968
+ var CodeBlockRendererHTML = [
2969
+ CodeBlock,
2970
+ (node, cxt) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("pre", { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("code", { children: cxt.state.render(node.content, cxt) }) })
2971
+ ];
2972
+ var CodeInlineRendererHTML = [
2973
+ CodeInline,
2974
+ (node, cxt) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("code", { children: cxt.state.render(node.content, cxt) }) })
2975
+ ];
2895
2976
 
2896
- // src/default/quotes.ts
2977
+ // src/default/quotes.tsx
2978
+ var import_jsx_runtime5 = require("minimal-jsx-runtime/jsx-runtime");
2897
2979
  var quoteBlock = new BlockModifierDefinition(
2898
2980
  "quote",
2899
2981
  0 /* Normal */,
@@ -2904,6 +2986,16 @@ var epitaphBlock = new BlockModifierDefinition(
2904
2986
  0 /* Normal */,
2905
2987
  { roleHint: "quote" }
2906
2988
  );
2989
+ var calloutBlock = new BlockModifierDefinition(
2990
+ "callout",
2991
+ 0 /* Normal */,
2992
+ { roleHint: "quote" }
2993
+ );
2994
+ var detailBlock = new BlockModifierDefinition(
2995
+ "detail",
2996
+ 0 /* Normal */,
2997
+ { roleHint: "quote" }
2998
+ );
2907
2999
  var attributionBlock = new BlockModifierDefinition(
2908
3000
  "by",
2909
3001
  0 /* Normal */,
@@ -2919,23 +3011,34 @@ var attributionBlock = new BlockModifierDefinition(
2919
3011
  }
2920
3012
  }
2921
3013
  );
2922
- var QuoteBlocks = [quoteBlock, epitaphBlock, attributionBlock];
3014
+ var QuoteBlocks = [quoteBlock, epitaphBlock, calloutBlock, detailBlock, attributionBlock];
2923
3015
  var QuoteBlockRenderersHTML = [
2924
- [quoteBlock, (node, cxt) => {
2925
- return `<blockquote>${cxt.state.render(node.content, cxt)}</blockquote>`;
2926
- }],
2927
- [epitaphBlock, (node, cxt) => {
2928
- return `<blockquote class='epitaph'>${cxt.state.render(node.content, cxt)}</blockquote>`;
2929
- }],
3016
+ [
3017
+ quoteBlock,
3018
+ (node, cxt) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("blockquote", { children: cxt.state.render(node.content, cxt) })
3019
+ ],
3020
+ [
3021
+ epitaphBlock,
3022
+ (node, cxt) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("blockquote", { class: "epitaph", children: cxt.state.render(node.content, cxt) })
3023
+ ],
3024
+ [
3025
+ detailBlock,
3026
+ (node, cxt) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { class: "detail", children: cxt.state.render(node.content, cxt) })
3027
+ ],
3028
+ [
3029
+ calloutBlock,
3030
+ (node, cxt) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("aside", { children: cxt.state.render(node.content, cxt) })
3031
+ ],
2930
3032
  [attributionBlock, (node, cxt) => {
2931
3033
  if (!node.state)
2932
3034
  return cxt.state.invalidBlock(node, "bad format");
2933
3035
  let para = node.content[0];
2934
- return `<p class='attribution'>${cxt.state.render(para.content, cxt)}</p>`;
3036
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { class: "attribution", children: cxt.state.render(para.content, cxt) });
2935
3037
  }]
2936
3038
  ];
2937
3039
 
2938
- // src/default/inline-styles.ts
3040
+ // src/default/inline-styles.tsx
3041
+ var import_jsx_runtime6 = require("minimal-jsx-runtime/jsx-runtime");
2939
3042
  var emphasisInline = new InlineModifierDefinition(
2940
3043
  "emphasis",
2941
3044
  0 /* Normal */,
@@ -2956,23 +3059,37 @@ var commentaryInline = new InlineModifierDefinition(
2956
3059
  0 /* Normal */,
2957
3060
  { roleHint: "commentary" }
2958
3061
  );
2959
- var InlineStyles = [emphasisInline, keywordInline, highlightInline, commentaryInline];
3062
+ var sequenceInline = new InlineModifierDefinition(
3063
+ "seq",
3064
+ 0 /* Normal */,
3065
+ { roleHint: "commentary" }
3066
+ );
3067
+ var InlineStyles = [emphasisInline, keywordInline, highlightInline, commentaryInline, sequenceInline];
2960
3068
  var InlineStyleRenderersHTML = [
2961
- [emphasisInline, (node, cxt) => {
2962
- return `<em>${cxt.state.render(node.content, cxt)}</em>`;
2963
- }],
2964
- [keywordInline, (node, cxt) => {
2965
- return `<b>${cxt.state.render(node.content, cxt)}</b>`;
2966
- }],
2967
- [highlightInline, (node, cxt) => {
2968
- return `<mark>${cxt.state.render(node.content, cxt)}</mark>`;
2969
- }],
2970
- [commentaryInline, (node, cxt) => {
2971
- return `<span class='commentary'>${cxt.state.render(node.content, cxt)}</span>`;
2972
- }]
3069
+ [
3070
+ emphasisInline,
3071
+ (node, cxt) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("em", { children: cxt.state.render(node.content, cxt) })
3072
+ ],
3073
+ [
3074
+ keywordInline,
3075
+ (node, cxt) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("b", { children: cxt.state.render(node.content, cxt) })
3076
+ ],
3077
+ [
3078
+ highlightInline,
3079
+ (node, cxt) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("mark", { children: cxt.state.render(node.content, cxt) })
3080
+ ],
3081
+ [
3082
+ commentaryInline,
3083
+ (node, cxt) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { class: "commentary", children: cxt.state.render(node.content, cxt) })
3084
+ ],
3085
+ [
3086
+ sequenceInline,
3087
+ (node, cxt) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { class: "seq", children: cxt.state.render(node.content, cxt) })
3088
+ ]
2973
3089
  ];
2974
3090
 
2975
- // src/default/misc.ts
3091
+ // src/default/misc.tsx
3092
+ var import_jsx_runtime7 = require("minimal-jsx-runtime/jsx-runtime");
2976
3093
  var rubyInline = new InlineModifierDefinition(
2977
3094
  "ruby",
2978
3095
  0 /* Normal */,
@@ -3048,43 +3165,46 @@ var imageBlock = new BlockModifierDefinition(
3048
3165
  var MiscInlines = [rubyInline, linkInline];
3049
3166
  var MiscBlocks = [styleBlock, breakBlock, linkBlock, imageBlock];
3050
3167
  var MiscInlineRenderersHTML = [
3051
- [rubyInline, (node, cxt) => {
3052
- if (node.state === void 0)
3053
- return cxt.state.invalidInline(node, "bad format");
3054
- return `<ruby>${cxt.state.render(node.content, cxt)}<rt>${node.state}</rt></ruby>`;
3055
- }],
3056
- [linkInline, (node, cxt) => {
3057
- if (node.state === void 0)
3058
- return cxt.state.invalidInline(node, "bad format");
3059
- return `<a href="${encodeURI(node.state)}">${cxt.state.render(node.content, cxt)}</a>`;
3060
- }]
3168
+ [
3169
+ rubyInline,
3170
+ (node, cxt) => node.state === void 0 ? cxt.state.invalidInline(node, "bad format") : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("ruby", { children: [
3171
+ cxt.state.render(node.content, cxt),
3172
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("rt", { children: node.state })
3173
+ ] })
3174
+ ],
3175
+ [
3176
+ linkInline,
3177
+ (node, cxt) => node.state === void 0 ? cxt.state.invalidInline(node, "bad format") : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("a", { href: encodeURI(node.state), children: cxt.state.render(node.content, cxt) })
3178
+ ]
3061
3179
  ];
3062
3180
  var MiscBlockRenderersHTML = [
3063
- [styleBlock, (node, cxt) => {
3064
- if (node.state === void 0)
3065
- return cxt.state.invalidBlock(node, "bad format");
3066
- return `<div class="emmmstyle-${node.state}" style="display:contents">${cxt.state.render(node.content, cxt)}</div>`;
3067
- }],
3068
- [breakBlock, () => {
3069
- return `<hr>`;
3070
- }],
3071
- [linkBlock, (node, cxt) => {
3072
- if (node.state === void 0)
3073
- return cxt.state.invalidBlock(node, "bad format");
3074
- return `<a href="${encodeURI(node.state)}">${cxt.state.render(node.content, cxt)}</a>`;
3075
- }],
3181
+ [
3182
+ styleBlock,
3183
+ (node, cxt) => node.state === void 0 ? cxt.state.invalidBlock(node, "bad format") : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { class: `emmmstyle-${node.state}`, style: "display:contents", children: cxt.state.render(node.content, cxt) })
3184
+ ],
3185
+ [breakBlock, () => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("hr", {})],
3186
+ [
3187
+ linkBlock,
3188
+ (node, cxt) => {
3189
+ if (node.state === void 0)
3190
+ return cxt.state.invalidBlock(node, "bad format");
3191
+ const content = cxt.state.render(node.content, cxt);
3192
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("a", { href: encodeURI(node.state), children: content.childElementCount > 0 ? content : node.state });
3193
+ }
3194
+ ],
3076
3195
  [imageBlock, (node, cxt) => {
3077
- let transformed;
3078
3196
  if (node.state === void 0)
3079
3197
  return cxt.state.invalidBlock(node, "bad format");
3198
+ let transformed;
3080
3199
  try {
3081
3200
  transformed = cxt.config.options.transformAsset(node.state);
3082
3201
  } catch {
3083
3202
  return cxt.state.invalidBlock(node, "unable to transform asset");
3084
3203
  }
3085
- const img = transformed ? `<img src="${transformed}" data-original-src="${node.state}"/>` : `<img src="${node.state}"/>`;
3086
- const para = node.content.length == 0 ? "" : "\n<figcaption>" + cxt.state.render(node.content[0].content, cxt) + "</figcaption>";
3087
- return `<figure>${img}${para}</figure>`;
3204
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("figure", { children: [
3205
+ transformed ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("img", { src: transformed, "data-original-src": node.state }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("img", { src: node.state }),
3206
+ node.content.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("figcaption", { children: cxt.state.render(node.content[0].content, cxt) }) : []
3207
+ ] });
3088
3208
  }]
3089
3209
  ];
3090
3210
 
@@ -3139,34 +3259,45 @@ config.inlineModifiers.add(
3139
3259
  ...NoteInlines
3140
3260
  );
3141
3261
  config.systemModifiers.add(
3142
- ...VarWrappers
3262
+ ...VarWrappers,
3263
+ ...NoteSystems
3143
3264
  );
3144
3265
  var DefaultConfiguration = Object.freeze(config);
3145
3266
 
3146
- // src/default/html-renderer.ts
3267
+ // src/default/html-renderer.tsx
3268
+ var import_jsx_runtime8 = require("minimal-jsx-runtime/jsx-runtime");
3147
3269
  var HTMLRenderState = class {
3148
3270
  title = "";
3149
3271
  stylesheet = "";
3150
3272
  // FIXME: very unsafe!
3151
3273
  cssVariables = /* @__PURE__ */ new Map();
3152
- // https://stackoverflow.com/questions/7381974
3153
- escape(content) {
3154
- return content.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;").replaceAll("\n", "<br/>");
3155
- }
3156
3274
  invalidBlock(node, msg) {
3157
3275
  let name = NodeType[node.type];
3158
3276
  if (node.type === 7 /* BlockModifier */)
3159
3277
  name += ` (${node.mod.name})`;
3160
- return `<details class='invalid'><summary>Invalid ${this.escape(name)}</summary><i>${this.escape(msg)}</i></details>`;
3278
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("details", { class: "invalid", children: [
3279
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("summary", { children: [
3280
+ "Invalid ",
3281
+ name
3282
+ ] }),
3283
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("i", { children: msg })
3284
+ ] });
3161
3285
  }
3162
3286
  invalidInline(node, msg) {
3163
3287
  let name = NodeType[node.type];
3164
3288
  if (node.type === 6 /* InlineModifier */)
3165
3289
  name += ` (${node.mod.name})`;
3166
- return `<span class='invalid'>Invalid ${this.escape(name)} \u2013 <i>${this.escape(msg)}</i></span>`;
3290
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { class: "invalid", children: [
3291
+ "Invalid ",
3292
+ name,
3293
+ ": ",
3294
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("i", { children: msg })
3295
+ ] });
3167
3296
  }
3168
3297
  render(elems, cxt) {
3169
- return elems.map((x) => cxt.renderEntity(x)).filter((x) => x !== void 0).join("");
3298
+ let fragment = new DocumentFragment();
3299
+ elems.map((x) => cxt.renderEntity(x)).filter((x) => x !== void 0).flat().forEach((x) => fragment.appendChild(x));
3300
+ return fragment;
3170
3301
  }
3171
3302
  };
3172
3303
  var htmlConfig = new RenderConfiguration(
@@ -3174,7 +3305,8 @@ var htmlConfig = new RenderConfiguration(
3174
3305
  headPlugins: [],
3175
3306
  headerPlugins: [],
3176
3307
  footerPlugins: [NotesFooterPlugin],
3177
- transformAsset: (x) => void 0
3308
+ postprocessPlugins: [],
3309
+ transformAsset: () => void 0
3178
3310
  // postprocessPlugins: [],
3179
3311
  },
3180
3312
  (results, cxt) => {
@@ -3182,35 +3314,41 @@ var htmlConfig = new RenderConfiguration(
3182
3314
  /var\(--(.*?)\)/g,
3183
3315
  (m, c) => cxt.state.cssVariables.get(c) ?? m
3184
3316
  );
3185
- return `
3186
- <!DOCTYPE html>
3187
- <html>
3188
- <head>
3189
- <meta charset="UTF-8">
3190
- ${cxt.config.options.headPlugins.map((x) => x(cxt)).filter((x) => x !== void 0).join("\n")}
3191
- <title>${cxt.state.escape(cxt.state.title)}</title>
3192
- <style>${styles}</style>
3193
- </head>
3194
- <body>
3195
- <section class="article-container">
3196
- <section class="article-body">
3197
- ${cxt.config.options.headerPlugins.map((x) => x(cxt)).filter((x) => x !== void 0).join("\n")}
3198
- ${results.join("\n")}
3199
- ${cxt.config.options.footerPlugins.map((x) => x(cxt)).filter((x) => x !== void 0).join("\n")}
3200
- </section>
3201
- </section>
3202
- </body>
3203
- </html>`;
3317
+ let doc = document.implementation.createHTMLDocument(cxt.state.title);
3318
+ doc.head.append(
3319
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("meta", { charset: "UTF-8" }),
3320
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("style", { children: styles }),
3321
+ ...cxt.config.options.headPlugins.map((x) => x(cxt)).filter((x) => x !== void 0).flat()
3322
+ );
3323
+ doc.body.append(
3324
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("section", { class: "article-container", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("section", { class: "article-body", children: [
3325
+ cxt.config.options.headerPlugins.map((x) => x(cxt)).filter((x) => x !== void 0),
3326
+ results,
3327
+ cxt.config.options.footerPlugins.map((x) => x(cxt)).filter((x) => x !== void 0)
3328
+ ] }) })
3329
+ );
3330
+ for (const p of cxt.config.options.postprocessPlugins) {
3331
+ p(cxt, doc);
3332
+ }
3333
+ return doc;
3204
3334
  }
3205
3335
  );
3206
- htmlConfig.paragraphRenderer = (node, cxt) => `<p>${node.content.map((x) => cxt.renderEntity(x)).filter((x) => x !== void 0).join("")}</p>`;
3336
+ htmlConfig.paragraphRenderer = (node, cxt) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { children: node.content.map((x) => cxt.renderEntity(x)).filter((x) => x !== void 0) });
3207
3337
  htmlConfig.textRenderer = (node, cxt) => {
3208
3338
  switch (node.type) {
3209
3339
  case 2 /* Preformatted */:
3210
- return cxt.state.escape(node.content.text);
3340
+ return new Text(node.content.text);
3211
3341
  case 3 /* Text */:
3212
3342
  case 4 /* Escaped */:
3213
- return cxt.state.escape(node.content);
3343
+ const split = node.content.split("\n");
3344
+ const result = [];
3345
+ for (let i = 0; i < split.length; i++) {
3346
+ result.push(new Text(split[i]));
3347
+ if (i < split.length - 1)
3348
+ result.push(/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("br", {}));
3349
+ }
3350
+ console.log(result);
3351
+ return result;
3214
3352
  default:
3215
3353
  return debug.never(node);
3216
3354
  }
@@ -3226,8 +3364,8 @@ htmlConfig.addBlockRenderer(
3226
3364
  ...BulletBlockRenderersHTML,
3227
3365
  CodeBlockRendererHTML,
3228
3366
  ...QuoteBlockRenderersHTML,
3229
- ...MiscBlockRenderersHTML
3230
- // TODO: notes
3367
+ ...MiscBlockRenderersHTML,
3368
+ ...NoteBlockRenderersHTML
3231
3369
  );
3232
3370
  htmlConfig.addInlineRenderer(
3233
3371
  CodeInlineRendererHTML,
@@ -3265,6 +3403,7 @@ function setDebugLevel(level) {
3265
3403
  SystemModifierDefinition,
3266
3404
  debugPrint,
3267
3405
  emmmVersion,
3406
+ helper,
3268
3407
  messages,
3269
3408
  parse,
3270
3409
  setDebugLevel