@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.mjs CHANGED
@@ -35,6 +35,9 @@ var ModifierBase = class {
35
35
  this.slotType = slotType;
36
36
  if (args) Object.assign(this, args);
37
37
  }
38
+ /**
39
+ * Common values: heading, emphasis, keyword, highlight, commentary, comment, link, quote
40
+ */
38
41
  roleHint;
39
42
  /**
40
43
  * If true, any modifier encountered inside it will *not* be expanded *during parse-content*,
@@ -44,7 +47,7 @@ var ModifierBase = class {
44
47
  delayContentExpansion = false;
45
48
  /**
46
49
  * If true, such a modifier will always be expanded whenever it is encountered, *even if*
47
- * contained in a modifier with `delayContentExpansion`. In the vast majority of cases,
50
+ * it is contained in a modifier with `delayContentExpansion`. In the vast majority of cases,
48
51
  * you shouldn't be using this.
49
52
  */
50
53
  alwaysTryExpand = false;
@@ -298,14 +301,14 @@ var StringSource = class {
298
301
  }
299
302
  return [line, pos - linepos];
300
303
  }
301
- getLineStart(n) {
304
+ getRowStart(n) {
302
305
  assert(n >= 0);
303
306
  if (n >= this.lineMap.length) return Infinity;
304
307
  return this.lineMap[n];
305
308
  }
306
- getLine(n) {
307
- const start = this.getLineStart(n);
308
- const end = this.getLineStart(n + 1);
309
+ getRow(n) {
310
+ const start = this.getRowStart(n);
311
+ const end = this.getRowStart(n + 1);
309
312
  if (start === Infinity) return void 0;
310
313
  return this.src.substring(start, end - 1);
311
314
  }
@@ -439,7 +442,7 @@ function debugPrintRange(loc, context = 1) {
439
442
  const endLine = Math.min(loc.source.nLines - 1, er + context);
440
443
  let lines = [];
441
444
  for (let i = startLine; i <= endLine; i++) {
442
- const line = loc.source.getLine(i);
445
+ const line = loc.source.getRow(i);
443
446
  lines.push((i + 1).toString().padStart(rowWidth) + " | " + line);
444
447
  if (i >= sr && i <= er) {
445
448
  const startPos = i == sr ? sc : 0;
@@ -978,6 +981,7 @@ var Parser = class {
978
981
  end: to ?? this.scanner.position()
979
982
  };
980
983
  }
984
+ /* istanbul ignore next -- @preserve */
981
985
  #defs(type) {
982
986
  switch (type) {
983
987
  case 5 /* SystemModifier */:
@@ -1511,9 +1515,9 @@ function parse(scanner, cxt) {
1511
1515
 
1512
1516
  // src/renderer.ts
1513
1517
  var RenderContext = class {
1514
- constructor(config2, parseContext, state) {
1518
+ constructor(config2, parsedDocument, state) {
1515
1519
  this.config = config2;
1516
- this.parseContext = parseContext;
1520
+ this.parsedDocument = parsedDocument;
1517
1521
  this.state = state;
1518
1522
  }
1519
1523
  renderEntity(node) {
@@ -1551,7 +1555,7 @@ var RenderConfiguration = class _RenderConfiguration {
1551
1555
  blockRenderers = /* @__PURE__ */ new Map();
1552
1556
  inlineRenderers = /* @__PURE__ */ new Map();
1553
1557
  render(doc, state) {
1554
- let cxt = new RenderContext(this, doc.context, state);
1558
+ let cxt = new RenderContext(this, doc, state);
1555
1559
  let results = doc.toStripped().root.content.map((x) => cxt.renderEntity(x)).filter((x) => x !== void 0);
1556
1560
  return this.postprocessor(results, cxt);
1557
1561
  }
@@ -1574,6 +1578,14 @@ var RenderConfiguration = class _RenderConfiguration {
1574
1578
  };
1575
1579
 
1576
1580
  // src/modifier-helper.ts
1581
+ var modifier_helper_exports = {};
1582
+ __export(modifier_helper_exports, {
1583
+ checkArgumentLength: () => checkArgumentLength,
1584
+ checkArguments: () => checkArguments,
1585
+ onlyPermitPlaintextParagraph: () => onlyPermitPlaintextParagraph,
1586
+ onlyPermitSimpleParagraphs: () => onlyPermitSimpleParagraphs,
1587
+ onlyPermitSingleBlock: () => onlyPermitSingleBlock
1588
+ });
1577
1589
  function checkArgumentLength(node, min, max = min) {
1578
1590
  if (min !== void 0 && node.arguments.length < min || max !== void 0 && node.arguments.length > max) {
1579
1591
  return [new ArgumentCountMismatchMessage({
@@ -2396,44 +2408,23 @@ function resolveId(id, cxt) {
2396
2408
  value = cxt.variables.get(id);
2397
2409
  return value;
2398
2410
  }
2399
- var ifdefBlock = (name, x) => new BlockModifierDefinition(
2400
- name,
2401
- 0 /* Normal */,
2402
- {
2403
- prepareExpand(node, cxt) {
2404
- const check = checkArguments(node, 1);
2405
- if (check) return check;
2406
- const arg = node.arguments[0];
2407
- const id = arg.expansion;
2408
- if (id == "") return [new InvalidArgumentMessage(arg.location)];
2409
- const value = resolveId(id, cxt);
2410
- node.state = value !== void 0;
2411
- return [];
2412
- },
2413
- expand(node) {
2414
- return node.state == x ? node.content : [];
2415
- }
2416
- }
2417
- );
2418
- var ifdefInline = (name, x) => new InlineModifierDefinition(
2419
- name,
2420
- 0 /* Normal */,
2421
- {
2422
- prepareExpand(node, cxt) {
2423
- const check = checkArguments(node, 1);
2424
- if (check) return check;
2425
- const arg = node.arguments[0];
2426
- const id = arg.expansion;
2427
- if (id == "") return [new InvalidArgumentMessage(arg.location)];
2428
- const value = resolveId(id, cxt);
2429
- node.state = value !== void 0;
2430
- return [];
2431
- },
2432
- expand(node) {
2433
- return node.state == x ? node.content : [];
2434
- }
2411
+ var ifdefBody = (x) => ({
2412
+ prepareExpand(node, cxt) {
2413
+ const check = checkArguments(node, 1);
2414
+ if (check) return check;
2415
+ const arg = node.arguments[0];
2416
+ const id = arg.expansion;
2417
+ if (id == "") return [new InvalidArgumentMessage(arg.location)];
2418
+ const value = resolveId(id, cxt);
2419
+ node.state = value !== void 0;
2420
+ return [];
2421
+ },
2422
+ expand(node) {
2423
+ return node.state == x ? node.content : [];
2435
2424
  }
2436
- );
2425
+ });
2426
+ var ifdefBlock = (name, x) => new BlockModifierDefinition(name, 0 /* Normal */, ifdefBody(x));
2427
+ var ifdefInline = (name, x) => new InlineModifierDefinition(name, 0 /* Normal */, ifdefBody(x));
2437
2428
  var IfdefBlockMod = ifdefBlock("ifdef", true);
2438
2429
  var IfndefBlockMod = ifdefBlock("ifndef", false);
2439
2430
  var IfdefInlineMod = ifdefInline("ifdef", true);
@@ -2550,7 +2541,8 @@ builtin.inlineModifiers.add(
2550
2541
  builtin.argumentInterpolators.add(GetVarInterpolator);
2551
2542
  var BuiltinConfiguration = Object.freeze(builtin);
2552
2543
 
2553
- // src/default/bullets.ts
2544
+ // src/default/bullets.tsx
2545
+ import { jsx } from "minimal-jsx-runtime/jsx-runtime";
2554
2546
  var bulletItemBlock = new BlockModifierDefinition(
2555
2547
  "bullet-item",
2556
2548
  0 /* Normal */,
@@ -2581,20 +2573,22 @@ var subItemBlock = new BlockModifierDefinition(
2581
2573
  );
2582
2574
  var BulletBlocks = [bulletItemBlock, orderedListItemBlock, subItemBlock];
2583
2575
  var BulletBlockRenderersHTML = [
2584
- [bulletItemBlock, (node, cxt) => {
2585
- return `<li>${cxt.state.render(node.content, cxt)}</li>`;
2586
- }],
2587
- [subItemBlock, (node, cxt) => {
2588
- return `<div class='subitem'>${cxt.state.render(node.content, cxt)}</div>`;
2589
- }],
2590
- [orderedListItemBlock, (node, cxt) => {
2591
- if (node.state === void 0)
2592
- return cxt.state.invalidBlock(node, "bad format");
2593
- return `<li value='${node.state}'>${cxt.state.render(node.content, cxt)}</li>`;
2594
- }]
2576
+ [
2577
+ bulletItemBlock,
2578
+ (node, cxt) => /* @__PURE__ */ jsx("li", { children: cxt.state.render(node.content, cxt) })
2579
+ ],
2580
+ [
2581
+ subItemBlock,
2582
+ (node, cxt) => /* @__PURE__ */ jsx("div", { class: "subitem", children: cxt.state.render(node.content, cxt) })
2583
+ ],
2584
+ [
2585
+ orderedListItemBlock,
2586
+ (node, cxt) => node.state === void 0 ? cxt.state.invalidBlock(node, "bad format") : /* @__PURE__ */ jsx("li", { value: node.state, children: cxt.state.render(node.content, cxt) })
2587
+ ]
2595
2588
  ];
2596
2589
 
2597
- // src/default/headings.ts
2590
+ // src/default/headings.tsx
2591
+ import { jsx as jsx2 } from "minimal-jsx-runtime/jsx-runtime";
2598
2592
  var headings = Symbol();
2599
2593
  function initHeadings(cxt) {
2600
2594
  cxt.init(headings, {
@@ -2700,37 +2694,103 @@ var HeadingBlocks = [headingBlock, implicitHeadingBlock, numberedHeadingBlock];
2700
2694
  var HeadingBlockRenderersHTML = [
2701
2695
  [headingBlock, (node, cxt) => {
2702
2696
  if (node.state !== void 0) {
2703
- let tag = "h" + node.state.level;
2704
- let para = node.content[0];
2705
- return `<${tag}>${cxt.state.render(para.content, cxt)}</${tag}>`;
2697
+ const tag = "h" + node.state.level;
2698
+ const para = node.content[0];
2699
+ const element = document.createElement(tag);
2700
+ element.appendChild(cxt.state.render(para.content, cxt));
2701
+ return element;
2706
2702
  }
2707
2703
  return cxt.state.invalidBlock(node, "Bad format");
2708
2704
  }],
2709
2705
  [implicitHeadingBlock, (node, cxt) => {
2710
2706
  if (node.state !== void 0) {
2711
- let tag = "h" + node.state.level;
2712
- return `<${tag} class='implicit'></${tag}>`;
2707
+ const tag = "h" + node.state.level;
2708
+ const element = document.createElement(tag);
2709
+ element.className = "implicit";
2710
+ return element;
2713
2711
  }
2714
2712
  return cxt.state.invalidBlock(node, "Bad format");
2715
2713
  }],
2716
2714
  [numberedHeadingBlock, (node, cxt) => {
2717
2715
  if (node.state !== void 0) {
2718
- let tag = "h" + node.state.level;
2719
- let para = node.content[0];
2720
- return `<${tag}><span class='heading-number'>${node.state.name}</span>${cxt.state.render(para.content, cxt)}</${tag}>`;
2716
+ const tag = "h" + node.state.level;
2717
+ const para = node.content[0];
2718
+ const element = document.createElement(tag);
2719
+ element.appendChild(/* @__PURE__ */ jsx2("span", { class: "heading-number", children: node.state.name }));
2720
+ element.appendChild(cxt.state.render(para.content, cxt));
2721
+ return element;
2721
2722
  }
2722
2723
  return cxt.state.invalidBlock(node, "Bad format");
2723
2724
  }]
2724
2725
  ];
2725
2726
 
2726
- // src/default/notes.ts
2727
+ // src/default/notes.tsx
2728
+ import { jsx as jsx3, jsxs } from "minimal-jsx-runtime/jsx-runtime";
2727
2729
  var notes = Symbol();
2728
2730
  function initNotes(cxt) {
2729
2731
  cxt.init(notes, {
2730
2732
  systems: /* @__PURE__ */ new Map(),
2731
- definitions: []
2733
+ defaultSystem: {
2734
+ position: "preserve",
2735
+ autonumber: false
2736
+ },
2737
+ definitions: [],
2738
+ currentId: 0
2732
2739
  });
2733
2740
  }
2741
+ function getSystem(cxt, name) {
2742
+ const defs = cxt.get(notes);
2743
+ let system;
2744
+ if (name) {
2745
+ if (!defs.systems.has(name)) {
2746
+ system = { ...defs.defaultSystem };
2747
+ defs.systems.set(name, system);
2748
+ } else {
2749
+ system = defs.systems.get(name);
2750
+ }
2751
+ } else {
2752
+ system = defs.defaultSystem;
2753
+ }
2754
+ return system;
2755
+ }
2756
+ var notePositionSystem = new SystemModifierDefinition(
2757
+ "note-position",
2758
+ 2 /* None */,
2759
+ {
2760
+ prepareExpand(node, cxt, immediate) {
2761
+ let msgs = checkArguments(node, 1, 2);
2762
+ if (msgs) return msgs;
2763
+ const type = node.arguments[0].expansion.trim();
2764
+ if (type != "global" && type != "preserve")
2765
+ return [new InvalidArgumentMessage(
2766
+ node.arguments[0].location,
2767
+ "should be `preserve` or `global`"
2768
+ )];
2769
+ const name = node.arguments.at(1)?.expansion.trim();
2770
+ getSystem(cxt, name).position = type;
2771
+ return [];
2772
+ }
2773
+ }
2774
+ );
2775
+ var noteRenumberingSystem = new SystemModifierDefinition(
2776
+ "note-renumbering",
2777
+ 2 /* None */,
2778
+ {
2779
+ prepareExpand(node, cxt, immediate) {
2780
+ let msgs = checkArguments(node, 1, 2);
2781
+ if (msgs) return msgs;
2782
+ const type = node.arguments[0].expansion.trim();
2783
+ if (type != "on" && type != "off")
2784
+ return [new InvalidArgumentMessage(
2785
+ node.arguments[0].location,
2786
+ "should be `preserve` or `global`"
2787
+ )];
2788
+ const name = node.arguments.at(1)?.expansion.trim();
2789
+ getSystem(cxt, name).autonumber = type == "on";
2790
+ return [];
2791
+ }
2792
+ }
2793
+ );
2734
2794
  var noteMarkerInline = new InlineModifierDefinition(
2735
2795
  "note",
2736
2796
  2 /* None */,
@@ -2752,13 +2812,15 @@ var noteInline = new InlineModifierDefinition(
2752
2812
  prepareExpand(node) {
2753
2813
  let msgs = checkArguments(node, 0, 1);
2754
2814
  if (msgs) return msgs;
2755
- node.state = node.arguments.at(0)?.expansion ?? "";
2815
+ node.state = node.arguments.at(0)?.expansion?.trim() ?? "";
2756
2816
  return [];
2757
2817
  },
2758
2818
  afterProcessExpansion(node, cxt) {
2759
2819
  if (node.state !== void 0) {
2760
- cxt.get(notes).definitions.push({
2820
+ const defs = cxt.get(notes);
2821
+ defs.definitions.push({
2761
2822
  system: "",
2823
+ id: defs.currentId,
2762
2824
  name: node.state,
2763
2825
  location: node.location,
2764
2826
  content: [{
@@ -2771,6 +2833,7 @@ var noteInline = new InlineModifierDefinition(
2771
2833
  content: node.content
2772
2834
  }]
2773
2835
  });
2836
+ defs.currentId++;
2774
2837
  }
2775
2838
  return [];
2776
2839
  }
@@ -2781,58 +2844,73 @@ var noteBlock = new BlockModifierDefinition(
2781
2844
  0 /* Normal */,
2782
2845
  {
2783
2846
  roleHint: "quote",
2784
- prepareExpand(node) {
2785
- let msgs = checkArguments(node, 1);
2847
+ prepareExpand(node, cxt) {
2848
+ let msgs = checkArguments(node, 1, 2);
2786
2849
  if (msgs) return msgs;
2787
- node.state = node.arguments[0].expansion;
2788
- return [];
2789
- },
2790
- afterProcessExpansion(node, cxt) {
2791
- if (node.state !== void 0) {
2792
- let content = stripNode(...node.content);
2793
- debug.trace(`add note: system=<${""}> name=${node.state} @${node.location.start}`);
2794
- debug.trace(`-->
2850
+ const name = node.arguments[0].expansion.trim();
2851
+ const system = node.arguments.at(1)?.expansion.trim() ?? "";
2852
+ const content = stripNode(...node.content);
2853
+ debug.trace(`add note: system=<${""}> name=${node.state} @${node.location.start}`);
2854
+ debug.trace(`-->
2795
2855
  `, debugPrint.node(...content));
2796
- cxt.get(notes).definitions.push({
2797
- system: "",
2798
- name: node.state,
2799
- location: node.location,
2800
- content
2801
- });
2802
- }
2803
- node.expansion = [];
2856
+ const defs = cxt.get(notes);
2857
+ const entry = {
2858
+ id: defs.currentId,
2859
+ system,
2860
+ name,
2861
+ location: node.location,
2862
+ content
2863
+ };
2864
+ defs.currentId++;
2865
+ defs.definitions.push(entry);
2866
+ node.state = entry;
2804
2867
  return [];
2805
2868
  }
2806
2869
  }
2807
2870
  );
2808
2871
  var NoteBlocks = [noteBlock];
2809
2872
  var NoteInlines = [noteInline, noteMarkerInline];
2873
+ var NoteSystems = [notePositionSystem, noteRenumberingSystem];
2874
+ function makeNoteHTML(def, cxt) {
2875
+ return /* @__PURE__ */ jsxs("section", { class: "note", id: `note-id-${def.id}`, children: [
2876
+ /* @__PURE__ */ jsx3("div", { class: "note-name", children: /* @__PURE__ */ jsx3("p", { children: /* @__PURE__ */ jsx3("a", { href: `#notemarker-id-${def.id}`, children: def.name }) }) }),
2877
+ /* @__PURE__ */ jsx3("div", { class: "note-content", children: cxt.state.render(def.content, cxt) })
2878
+ ] });
2879
+ }
2810
2880
  var NoteInlineRenderersHTML = [
2811
2881
  [noteMarkerInline, (node, cxt) => {
2812
2882
  if (node.state === void 0)
2813
2883
  return cxt.state.invalidInline(node, "bad format");
2814
- const defs = cxt.parseContext.get(notes).definitions;
2884
+ const defs = cxt.parsedDocument.context.get(notes).definitions;
2815
2885
  const note = defs.findIndex((x) => (
2816
2886
  /*x.position >= node.start &&*/
2817
2887
  x.name == node.state
2818
2888
  ));
2819
- if (note < 0)
2820
- return `<sup class='note invalid'>Not found: ${node.state}</sup>`;
2821
- return `<sup class='note' id='notemarker-id-${note}'><a href='#note-id-${note}'>${node.state}</a></sup>`;
2889
+ return /* @__PURE__ */ jsx3("sup", { class: "note", id: `notemarker-id-${note}`, children: note < 0 ? `Not found: ${node.state}` : /* @__PURE__ */ jsx3("a", { href: `#note-id-${note}`, children: node.state }) });
2890
+ }]
2891
+ ];
2892
+ var NoteBlockRenderersHTML = [
2893
+ [noteBlock, (node, cxt) => {
2894
+ if (node.state === void 0)
2895
+ return cxt.state.invalidBlock(node, "bad format");
2896
+ const defs = cxt.parsedDocument.context.get(notes);
2897
+ const system = defs.systems.get(node.state.system) ?? defs.defaultSystem;
2898
+ if (system.position != "preserve") return [];
2899
+ return makeNoteHTML(node.state, cxt);
2822
2900
  }]
2823
2901
  ];
2824
2902
  var NotesFooterPlugin = (cxt) => {
2825
- let defs = cxt.parseContext.get(notes).definitions;
2826
- if (defs.length == 0) return void 0;
2827
- return `<hr/>
2828
- <section class='notes'>
2829
- ${defs.map((x, i) => `<section class='note' id='note-id-${i}'>
2830
- <div class='note-name'><p><a href='#notemarker-id-${i}'>${x.name}</a></p></div>
2831
- <div class='note-content'>${cxt.state.render(x.content, cxt)}</div></section>`).join("\n")}
2832
- </section>`;
2903
+ const defs = cxt.parsedDocument.context.get(notes);
2904
+ const items = cxt.parsedDocument.context.get(notes).definitions.filter((x) => (defs.systems.get(x.system) ?? defs.defaultSystem).position == "global");
2905
+ if (items.length == 0) return void 0;
2906
+ return [
2907
+ /* @__PURE__ */ jsx3("hr", {}),
2908
+ /* @__PURE__ */ jsx3("section", { class: "notes-global", children: items.map((x) => makeNoteHTML(x, cxt)) })
2909
+ ];
2833
2910
  };
2834
2911
 
2835
- // src/default/code.ts
2912
+ // src/default/code.tsx
2913
+ import { jsx as jsx4 } from "minimal-jsx-runtime/jsx-runtime";
2836
2914
  var CodeBlock = new BlockModifierDefinition(
2837
2915
  "code",
2838
2916
  1 /* Preformatted */,
@@ -2843,14 +2921,17 @@ var CodeInline = new InlineModifierDefinition(
2843
2921
  1 /* Preformatted */,
2844
2922
  { roleHint: "code" }
2845
2923
  );
2846
- var CodeBlockRendererHTML = [CodeBlock, (node, cxt) => {
2847
- return `<pre><code>${cxt.state.render(node.content, cxt)}</code></pre>`;
2848
- }];
2849
- var CodeInlineRendererHTML = [CodeInline, (node, cxt) => {
2850
- return `<span><code>${cxt.state.render(node.content, cxt)}</code></span>`;
2851
- }];
2924
+ var CodeBlockRendererHTML = [
2925
+ CodeBlock,
2926
+ (node, cxt) => /* @__PURE__ */ jsx4("pre", { children: /* @__PURE__ */ jsx4("code", { children: cxt.state.render(node.content, cxt) }) })
2927
+ ];
2928
+ var CodeInlineRendererHTML = [
2929
+ CodeInline,
2930
+ (node, cxt) => /* @__PURE__ */ jsx4("span", { children: /* @__PURE__ */ jsx4("code", { children: cxt.state.render(node.content, cxt) }) })
2931
+ ];
2852
2932
 
2853
- // src/default/quotes.ts
2933
+ // src/default/quotes.tsx
2934
+ import { jsx as jsx5 } from "minimal-jsx-runtime/jsx-runtime";
2854
2935
  var quoteBlock = new BlockModifierDefinition(
2855
2936
  "quote",
2856
2937
  0 /* Normal */,
@@ -2861,6 +2942,16 @@ var epitaphBlock = new BlockModifierDefinition(
2861
2942
  0 /* Normal */,
2862
2943
  { roleHint: "quote" }
2863
2944
  );
2945
+ var calloutBlock = new BlockModifierDefinition(
2946
+ "callout",
2947
+ 0 /* Normal */,
2948
+ { roleHint: "quote" }
2949
+ );
2950
+ var detailBlock = new BlockModifierDefinition(
2951
+ "detail",
2952
+ 0 /* Normal */,
2953
+ { roleHint: "quote" }
2954
+ );
2864
2955
  var attributionBlock = new BlockModifierDefinition(
2865
2956
  "by",
2866
2957
  0 /* Normal */,
@@ -2876,23 +2967,34 @@ var attributionBlock = new BlockModifierDefinition(
2876
2967
  }
2877
2968
  }
2878
2969
  );
2879
- var QuoteBlocks = [quoteBlock, epitaphBlock, attributionBlock];
2970
+ var QuoteBlocks = [quoteBlock, epitaphBlock, calloutBlock, detailBlock, attributionBlock];
2880
2971
  var QuoteBlockRenderersHTML = [
2881
- [quoteBlock, (node, cxt) => {
2882
- return `<blockquote>${cxt.state.render(node.content, cxt)}</blockquote>`;
2883
- }],
2884
- [epitaphBlock, (node, cxt) => {
2885
- return `<blockquote class='epitaph'>${cxt.state.render(node.content, cxt)}</blockquote>`;
2886
- }],
2972
+ [
2973
+ quoteBlock,
2974
+ (node, cxt) => /* @__PURE__ */ jsx5("blockquote", { children: cxt.state.render(node.content, cxt) })
2975
+ ],
2976
+ [
2977
+ epitaphBlock,
2978
+ (node, cxt) => /* @__PURE__ */ jsx5("blockquote", { class: "epitaph", children: cxt.state.render(node.content, cxt) })
2979
+ ],
2980
+ [
2981
+ detailBlock,
2982
+ (node, cxt) => /* @__PURE__ */ jsx5("div", { class: "detail", children: cxt.state.render(node.content, cxt) })
2983
+ ],
2984
+ [
2985
+ calloutBlock,
2986
+ (node, cxt) => /* @__PURE__ */ jsx5("aside", { children: cxt.state.render(node.content, cxt) })
2987
+ ],
2887
2988
  [attributionBlock, (node, cxt) => {
2888
2989
  if (!node.state)
2889
2990
  return cxt.state.invalidBlock(node, "bad format");
2890
2991
  let para = node.content[0];
2891
- return `<p class='attribution'>${cxt.state.render(para.content, cxt)}</p>`;
2992
+ return /* @__PURE__ */ jsx5("p", { class: "attribution", children: cxt.state.render(para.content, cxt) });
2892
2993
  }]
2893
2994
  ];
2894
2995
 
2895
- // src/default/inline-styles.ts
2996
+ // src/default/inline-styles.tsx
2997
+ import { jsx as jsx6 } from "minimal-jsx-runtime/jsx-runtime";
2896
2998
  var emphasisInline = new InlineModifierDefinition(
2897
2999
  "emphasis",
2898
3000
  0 /* Normal */,
@@ -2913,23 +3015,37 @@ var commentaryInline = new InlineModifierDefinition(
2913
3015
  0 /* Normal */,
2914
3016
  { roleHint: "commentary" }
2915
3017
  );
2916
- var InlineStyles = [emphasisInline, keywordInline, highlightInline, commentaryInline];
3018
+ var sequenceInline = new InlineModifierDefinition(
3019
+ "seq",
3020
+ 0 /* Normal */,
3021
+ { roleHint: "commentary" }
3022
+ );
3023
+ var InlineStyles = [emphasisInline, keywordInline, highlightInline, commentaryInline, sequenceInline];
2917
3024
  var InlineStyleRenderersHTML = [
2918
- [emphasisInline, (node, cxt) => {
2919
- return `<em>${cxt.state.render(node.content, cxt)}</em>`;
2920
- }],
2921
- [keywordInline, (node, cxt) => {
2922
- return `<b>${cxt.state.render(node.content, cxt)}</b>`;
2923
- }],
2924
- [highlightInline, (node, cxt) => {
2925
- return `<mark>${cxt.state.render(node.content, cxt)}</mark>`;
2926
- }],
2927
- [commentaryInline, (node, cxt) => {
2928
- return `<span class='commentary'>${cxt.state.render(node.content, cxt)}</span>`;
2929
- }]
3025
+ [
3026
+ emphasisInline,
3027
+ (node, cxt) => /* @__PURE__ */ jsx6("em", { children: cxt.state.render(node.content, cxt) })
3028
+ ],
3029
+ [
3030
+ keywordInline,
3031
+ (node, cxt) => /* @__PURE__ */ jsx6("b", { children: cxt.state.render(node.content, cxt) })
3032
+ ],
3033
+ [
3034
+ highlightInline,
3035
+ (node, cxt) => /* @__PURE__ */ jsx6("mark", { children: cxt.state.render(node.content, cxt) })
3036
+ ],
3037
+ [
3038
+ commentaryInline,
3039
+ (node, cxt) => /* @__PURE__ */ jsx6("span", { class: "commentary", children: cxt.state.render(node.content, cxt) })
3040
+ ],
3041
+ [
3042
+ sequenceInline,
3043
+ (node, cxt) => /* @__PURE__ */ jsx6("span", { class: "seq", children: cxt.state.render(node.content, cxt) })
3044
+ ]
2930
3045
  ];
2931
3046
 
2932
- // src/default/misc.ts
3047
+ // src/default/misc.tsx
3048
+ import { jsx as jsx7, jsxs as jsxs2 } from "minimal-jsx-runtime/jsx-runtime";
2933
3049
  var rubyInline = new InlineModifierDefinition(
2934
3050
  "ruby",
2935
3051
  0 /* Normal */,
@@ -3005,43 +3121,46 @@ var imageBlock = new BlockModifierDefinition(
3005
3121
  var MiscInlines = [rubyInline, linkInline];
3006
3122
  var MiscBlocks = [styleBlock, breakBlock, linkBlock, imageBlock];
3007
3123
  var MiscInlineRenderersHTML = [
3008
- [rubyInline, (node, cxt) => {
3009
- if (node.state === void 0)
3010
- return cxt.state.invalidInline(node, "bad format");
3011
- return `<ruby>${cxt.state.render(node.content, cxt)}<rt>${node.state}</rt></ruby>`;
3012
- }],
3013
- [linkInline, (node, cxt) => {
3014
- if (node.state === void 0)
3015
- return cxt.state.invalidInline(node, "bad format");
3016
- return `<a href="${encodeURI(node.state)}">${cxt.state.render(node.content, cxt)}</a>`;
3017
- }]
3124
+ [
3125
+ rubyInline,
3126
+ (node, cxt) => node.state === void 0 ? cxt.state.invalidInline(node, "bad format") : /* @__PURE__ */ jsxs2("ruby", { children: [
3127
+ cxt.state.render(node.content, cxt),
3128
+ /* @__PURE__ */ jsx7("rt", { children: node.state })
3129
+ ] })
3130
+ ],
3131
+ [
3132
+ linkInline,
3133
+ (node, cxt) => node.state === void 0 ? cxt.state.invalidInline(node, "bad format") : /* @__PURE__ */ jsx7("a", { href: encodeURI(node.state), children: cxt.state.render(node.content, cxt) })
3134
+ ]
3018
3135
  ];
3019
3136
  var MiscBlockRenderersHTML = [
3020
- [styleBlock, (node, cxt) => {
3021
- if (node.state === void 0)
3022
- return cxt.state.invalidBlock(node, "bad format");
3023
- return `<div class="emmmstyle-${node.state}" style="display:contents">${cxt.state.render(node.content, cxt)}</div>`;
3024
- }],
3025
- [breakBlock, () => {
3026
- return `<hr>`;
3027
- }],
3028
- [linkBlock, (node, cxt) => {
3029
- if (node.state === void 0)
3030
- return cxt.state.invalidBlock(node, "bad format");
3031
- return `<a href="${encodeURI(node.state)}">${cxt.state.render(node.content, cxt)}</a>`;
3032
- }],
3137
+ [
3138
+ styleBlock,
3139
+ (node, cxt) => node.state === void 0 ? cxt.state.invalidBlock(node, "bad format") : /* @__PURE__ */ jsx7("div", { class: `emmmstyle-${node.state}`, style: "display:contents", children: cxt.state.render(node.content, cxt) })
3140
+ ],
3141
+ [breakBlock, () => /* @__PURE__ */ jsx7("hr", {})],
3142
+ [
3143
+ linkBlock,
3144
+ (node, cxt) => {
3145
+ if (node.state === void 0)
3146
+ return cxt.state.invalidBlock(node, "bad format");
3147
+ const content = cxt.state.render(node.content, cxt);
3148
+ return /* @__PURE__ */ jsx7("a", { href: encodeURI(node.state), children: content.childElementCount > 0 ? content : node.state });
3149
+ }
3150
+ ],
3033
3151
  [imageBlock, (node, cxt) => {
3034
- let transformed;
3035
3152
  if (node.state === void 0)
3036
3153
  return cxt.state.invalidBlock(node, "bad format");
3154
+ let transformed;
3037
3155
  try {
3038
3156
  transformed = cxt.config.options.transformAsset(node.state);
3039
3157
  } catch {
3040
3158
  return cxt.state.invalidBlock(node, "unable to transform asset");
3041
3159
  }
3042
- const img = transformed ? `<img src="${transformed}" data-original-src="${node.state}"/>` : `<img src="${node.state}"/>`;
3043
- const para = node.content.length == 0 ? "" : "\n<figcaption>" + cxt.state.render(node.content[0].content, cxt) + "</figcaption>";
3044
- return `<figure>${img}${para}</figure>`;
3160
+ return /* @__PURE__ */ jsxs2("figure", { children: [
3161
+ transformed ? /* @__PURE__ */ jsx7("img", { src: transformed, "data-original-src": node.state }) : /* @__PURE__ */ jsx7("img", { src: node.state }),
3162
+ node.content.length > 0 ? /* @__PURE__ */ jsx7("figcaption", { children: cxt.state.render(node.content[0].content, cxt) }) : []
3163
+ ] });
3045
3164
  }]
3046
3165
  ];
3047
3166
 
@@ -3096,34 +3215,45 @@ config.inlineModifiers.add(
3096
3215
  ...NoteInlines
3097
3216
  );
3098
3217
  config.systemModifiers.add(
3099
- ...VarWrappers
3218
+ ...VarWrappers,
3219
+ ...NoteSystems
3100
3220
  );
3101
3221
  var DefaultConfiguration = Object.freeze(config);
3102
3222
 
3103
- // src/default/html-renderer.ts
3223
+ // src/default/html-renderer.tsx
3224
+ import { jsx as jsx8, jsxs as jsxs3 } from "minimal-jsx-runtime/jsx-runtime";
3104
3225
  var HTMLRenderState = class {
3105
3226
  title = "";
3106
3227
  stylesheet = "";
3107
3228
  // FIXME: very unsafe!
3108
3229
  cssVariables = /* @__PURE__ */ new Map();
3109
- // https://stackoverflow.com/questions/7381974
3110
- escape(content) {
3111
- return content.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;").replaceAll("\n", "<br/>");
3112
- }
3113
3230
  invalidBlock(node, msg) {
3114
3231
  let name = NodeType[node.type];
3115
3232
  if (node.type === 7 /* BlockModifier */)
3116
3233
  name += ` (${node.mod.name})`;
3117
- return `<details class='invalid'><summary>Invalid ${this.escape(name)}</summary><i>${this.escape(msg)}</i></details>`;
3234
+ return /* @__PURE__ */ jsxs3("details", { class: "invalid", children: [
3235
+ /* @__PURE__ */ jsxs3("summary", { children: [
3236
+ "Invalid ",
3237
+ name
3238
+ ] }),
3239
+ /* @__PURE__ */ jsx8("i", { children: msg })
3240
+ ] });
3118
3241
  }
3119
3242
  invalidInline(node, msg) {
3120
3243
  let name = NodeType[node.type];
3121
3244
  if (node.type === 6 /* InlineModifier */)
3122
3245
  name += ` (${node.mod.name})`;
3123
- return `<span class='invalid'>Invalid ${this.escape(name)} \u2013 <i>${this.escape(msg)}</i></span>`;
3246
+ return /* @__PURE__ */ jsxs3("span", { class: "invalid", children: [
3247
+ "Invalid ",
3248
+ name,
3249
+ ": ",
3250
+ /* @__PURE__ */ jsx8("i", { children: msg })
3251
+ ] });
3124
3252
  }
3125
3253
  render(elems, cxt) {
3126
- return elems.map((x) => cxt.renderEntity(x)).filter((x) => x !== void 0).join("");
3254
+ let fragment = new DocumentFragment();
3255
+ elems.map((x) => cxt.renderEntity(x)).filter((x) => x !== void 0).flat().forEach((x) => fragment.appendChild(x));
3256
+ return fragment;
3127
3257
  }
3128
3258
  };
3129
3259
  var htmlConfig = new RenderConfiguration(
@@ -3131,7 +3261,8 @@ var htmlConfig = new RenderConfiguration(
3131
3261
  headPlugins: [],
3132
3262
  headerPlugins: [],
3133
3263
  footerPlugins: [NotesFooterPlugin],
3134
- transformAsset: (x) => void 0
3264
+ postprocessPlugins: [],
3265
+ transformAsset: () => void 0
3135
3266
  // postprocessPlugins: [],
3136
3267
  },
3137
3268
  (results, cxt) => {
@@ -3139,35 +3270,41 @@ var htmlConfig = new RenderConfiguration(
3139
3270
  /var\(--(.*?)\)/g,
3140
3271
  (m, c) => cxt.state.cssVariables.get(c) ?? m
3141
3272
  );
3142
- return `
3143
- <!DOCTYPE html>
3144
- <html>
3145
- <head>
3146
- <meta charset="UTF-8">
3147
- ${cxt.config.options.headPlugins.map((x) => x(cxt)).filter((x) => x !== void 0).join("\n")}
3148
- <title>${cxt.state.escape(cxt.state.title)}</title>
3149
- <style>${styles}</style>
3150
- </head>
3151
- <body>
3152
- <section class="article-container">
3153
- <section class="article-body">
3154
- ${cxt.config.options.headerPlugins.map((x) => x(cxt)).filter((x) => x !== void 0).join("\n")}
3155
- ${results.join("\n")}
3156
- ${cxt.config.options.footerPlugins.map((x) => x(cxt)).filter((x) => x !== void 0).join("\n")}
3157
- </section>
3158
- </section>
3159
- </body>
3160
- </html>`;
3273
+ let doc = document.implementation.createHTMLDocument(cxt.state.title);
3274
+ doc.head.append(
3275
+ /* @__PURE__ */ jsx8("meta", { charset: "UTF-8" }),
3276
+ /* @__PURE__ */ jsx8("style", { children: styles }),
3277
+ ...cxt.config.options.headPlugins.map((x) => x(cxt)).filter((x) => x !== void 0).flat()
3278
+ );
3279
+ doc.body.append(
3280
+ /* @__PURE__ */ jsx8("section", { class: "article-container", children: /* @__PURE__ */ jsxs3("section", { class: "article-body", children: [
3281
+ cxt.config.options.headerPlugins.map((x) => x(cxt)).filter((x) => x !== void 0),
3282
+ results,
3283
+ cxt.config.options.footerPlugins.map((x) => x(cxt)).filter((x) => x !== void 0)
3284
+ ] }) })
3285
+ );
3286
+ for (const p of cxt.config.options.postprocessPlugins) {
3287
+ p(cxt, doc);
3288
+ }
3289
+ return doc;
3161
3290
  }
3162
3291
  );
3163
- htmlConfig.paragraphRenderer = (node, cxt) => `<p>${node.content.map((x) => cxt.renderEntity(x)).filter((x) => x !== void 0).join("")}</p>`;
3292
+ htmlConfig.paragraphRenderer = (node, cxt) => /* @__PURE__ */ jsx8("p", { children: node.content.map((x) => cxt.renderEntity(x)).filter((x) => x !== void 0) });
3164
3293
  htmlConfig.textRenderer = (node, cxt) => {
3165
3294
  switch (node.type) {
3166
3295
  case 2 /* Preformatted */:
3167
- return cxt.state.escape(node.content.text);
3296
+ return new Text(node.content.text);
3168
3297
  case 3 /* Text */:
3169
3298
  case 4 /* Escaped */:
3170
- return cxt.state.escape(node.content);
3299
+ const split = node.content.split("\n");
3300
+ const result = [];
3301
+ for (let i = 0; i < split.length; i++) {
3302
+ result.push(new Text(split[i]));
3303
+ if (i < split.length - 1)
3304
+ result.push(/* @__PURE__ */ jsx8("br", {}));
3305
+ }
3306
+ console.log(result);
3307
+ return result;
3171
3308
  default:
3172
3309
  return debug.never(node);
3173
3310
  }
@@ -3183,8 +3320,8 @@ htmlConfig.addBlockRenderer(
3183
3320
  ...BulletBlockRenderersHTML,
3184
3321
  CodeBlockRendererHTML,
3185
3322
  ...QuoteBlockRenderersHTML,
3186
- ...MiscBlockRenderersHTML
3187
- // TODO: notes
3323
+ ...MiscBlockRenderersHTML,
3324
+ ...NoteBlockRenderersHTML
3188
3325
  );
3189
3326
  htmlConfig.addInlineRenderer(
3190
3327
  CodeInlineRendererHTML,
@@ -3221,6 +3358,7 @@ export {
3221
3358
  SystemModifierDefinition,
3222
3359
  debugPrint,
3223
3360
  emmmVersion,
3361
+ modifier_helper_exports as helper,
3224
3362
  messages_exports as messages,
3225
3363
  parse,
3226
3364
  setDebugLevel