@the_dissidents/libemmm 0.0.5 → 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.
Files changed (125) hide show
  1. package/README.md +28 -15
  2. package/dist/index.d.mts +124 -44
  3. package/dist/index.d.ts +124 -44
  4. package/dist/index.js +547 -227
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +544 -227
  7. package/dist/index.mjs.map +1 -1
  8. package/package.json +4 -1
  9. package/dist/src/builtin/builtin.d.ts +0 -2
  10. package/dist/src/builtin/builtin.js +0 -18
  11. package/dist/src/builtin/builtin.js.map +0 -1
  12. package/dist/src/builtin/define-modifier.d.ts +0 -12
  13. package/dist/src/builtin/define-modifier.js +0 -129
  14. package/dist/src/builtin/define-modifier.js.map +0 -1
  15. package/dist/src/builtin/define-shorthand.d.ts +0 -14
  16. package/dist/src/builtin/define-shorthand.js +0 -178
  17. package/dist/src/builtin/define-shorthand.js.map +0 -1
  18. package/dist/src/builtin/internal.d.ts +0 -41
  19. package/dist/src/builtin/internal.js +0 -106
  20. package/dist/src/builtin/internal.js.map +0 -1
  21. package/dist/src/builtin/module.d.ts +0 -16
  22. package/dist/src/builtin/module.js +0 -156
  23. package/dist/src/builtin/module.js.map +0 -1
  24. package/dist/src/builtin/slot.d.ts +0 -7
  25. package/dist/src/builtin/slot.js +0 -136
  26. package/dist/src/builtin/slot.js.map +0 -1
  27. package/dist/src/builtin/var.d.ts +0 -12
  28. package/dist/src/builtin/var.js +0 -103
  29. package/dist/src/builtin/var.js.map +0 -1
  30. package/dist/src/debug-print.d.ts +0 -14
  31. package/dist/src/debug-print.js +0 -113
  32. package/dist/src/debug-print.js.map +0 -1
  33. package/dist/src/debug.d.ts +0 -15
  34. package/dist/src/debug.js +0 -47
  35. package/dist/src/debug.js.map +0 -1
  36. package/dist/src/default/bullets.d.ts +0 -4
  37. package/dist/src/default/bullets.js +0 -39
  38. package/dist/src/default/bullets.js.map +0 -1
  39. package/dist/src/default/code.d.ts +0 -6
  40. package/dist/src/default/code.js +0 -13
  41. package/dist/src/default/code.js.map +0 -1
  42. package/dist/src/default/default.d.ts +0 -2
  43. package/dist/src/default/default.js +0 -20
  44. package/dist/src/default/default.js.map +0 -1
  45. package/dist/src/default/headings.d.ts +0 -20
  46. package/dist/src/default/headings.js +0 -125
  47. package/dist/src/default/headings.js.map +0 -1
  48. package/dist/src/default/html-renderer.d.ts +0 -26
  49. package/dist/src/default/html-renderer.js +0 -108
  50. package/dist/src/default/html-renderer.js.map +0 -1
  51. package/dist/src/default/inline-styles.d.ts +0 -4
  52. package/dist/src/default/inline-styles.js +0 -24
  53. package/dist/src/default/inline-styles.js.map +0 -1
  54. package/dist/src/default/misc.d.ts +0 -6
  55. package/dist/src/default/misc.js +0 -112
  56. package/dist/src/default/misc.js.map +0 -1
  57. package/dist/src/default/notes.d.ts +0 -28
  58. package/dist/src/default/notes.js +0 -109
  59. package/dist/src/default/notes.js.map +0 -1
  60. package/dist/src/default/quotes.d.ts +0 -4
  61. package/dist/src/default/quotes.js +0 -36
  62. package/dist/src/default/quotes.js.map +0 -1
  63. package/dist/src/default/vars.d.ts +0 -2
  64. package/dist/src/default/vars.js +0 -39
  65. package/dist/src/default/vars.js.map +0 -1
  66. package/dist/src/index.d.ts +0 -13
  67. package/dist/src/index.js +0 -58
  68. package/dist/src/index.js.map +0 -1
  69. package/dist/src/interface.d.ts +0 -174
  70. package/dist/src/interface.js +0 -93
  71. package/dist/src/interface.js.map +0 -1
  72. package/dist/src/messages.d.ts +0 -165
  73. package/dist/src/messages.js +0 -279
  74. package/dist/src/messages.js.map +0 -1
  75. package/dist/src/modifier-helper.d.ts +0 -6
  76. package/dist/src/modifier-helper.js +0 -113
  77. package/dist/src/modifier-helper.js.map +0 -1
  78. package/dist/src/parser-config.d.ts +0 -44
  79. package/dist/src/parser-config.js +0 -67
  80. package/dist/src/parser-config.js.map +0 -1
  81. package/dist/src/parser.d.ts +0 -3
  82. package/dist/src/parser.js +0 -652
  83. package/dist/src/parser.js.map +0 -1
  84. package/dist/src/renderer.d.ts +0 -49
  85. package/dist/src/renderer.js +0 -81
  86. package/dist/src/renderer.js.map +0 -1
  87. package/dist/src/scanner.d.ts +0 -22
  88. package/dist/src/scanner.js +0 -50
  89. package/dist/src/scanner.js.map +0 -1
  90. package/dist/src/temp.d.ts +0 -1
  91. package/dist/src/temp.js +0 -108
  92. package/dist/src/temp.js.map +0 -1
  93. package/dist/src/typing-helper.d.ts +0 -7
  94. package/dist/src/typing-helper.js +0 -3
  95. package/dist/src/typing-helper.js.map +0 -1
  96. package/dist/src/util.d.ts +0 -29
  97. package/dist/src/util.js +0 -177
  98. package/dist/src/util.js.map +0 -1
  99. package/dist/tests/advanced_syntax.test.d.ts +0 -1
  100. package/dist/tests/advanced_syntax.test.js +0 -180
  101. package/dist/tests/advanced_syntax.test.js.map +0 -1
  102. package/dist/tests/basic_syntax.test.d.ts +0 -1
  103. package/dist/tests/basic_syntax.test.js +0 -431
  104. package/dist/tests/basic_syntax.test.js.map +0 -1
  105. package/dist/tests/default/headings.test.d.ts +0 -1
  106. package/dist/tests/default/headings.test.js +0 -90
  107. package/dist/tests/default/headings.test.js.map +0 -1
  108. package/dist/tests/define_block.test.d.ts +0 -1
  109. package/dist/tests/define_block.test.js +0 -209
  110. package/dist/tests/define_block.test.js.map +0 -1
  111. package/dist/tests/define_inline.test.d.ts +0 -1
  112. package/dist/tests/define_inline.test.js +0 -289
  113. package/dist/tests/define_inline.test.js.map +0 -1
  114. package/dist/tests/modules.test.d.ts +0 -1
  115. package/dist/tests/modules.test.js +0 -137
  116. package/dist/tests/modules.test.js.map +0 -1
  117. package/dist/tests/shorthands.test.d.ts +0 -1
  118. package/dist/tests/shorthands.test.js +0 -79
  119. package/dist/tests/shorthands.test.js.map +0 -1
  120. package/dist/tsup.config.d.ts +0 -2
  121. package/dist/tsup.config.js +0 -12
  122. package/dist/tsup.config.js.map +0 -1
  123. package/dist/vitest.config.d.ts +0 -2
  124. package/dist/vitest.config.js +0 -17
  125. package/dist/vitest.config.js.map +0 -1
package/dist/index.mjs CHANGED
@@ -35,24 +35,43 @@ 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
- * If true, any modifier encountered in the content of it will *not* be expanded, *unless* that modifier is `alwaysTryExpand`.
43
+ * If true, any modifier encountered inside it will *not* be expanded *during parse-content*,
44
+ * *unless* that modifier is `alwaysTryExpand`. In the vast majority of cases, you shouldn't
45
+ * be using this.
41
46
  */
42
47
  delayContentExpansion = false;
43
48
  /**
44
- * If true, such a modifier will always be expanded whenever it is encountered, *even if* contained in a modifier with `delayContentExpansion`.
49
+ * If true, such a modifier will always be expanded whenever it is encountered, *even if*
50
+ * it is contained in a modifier with `delayContentExpansion`. In the vast majority of cases,
51
+ * you shouldn't be using this.
45
52
  */
46
53
  alwaysTryExpand = false;
47
- /** Called before the modifier's content is parsed. */
54
+ /** Called before the modifier's content is parsed.
55
+ * @param immediate False when the node is inside a `delayContentExpansion` modifier, but it is `alwaysTryExpand`; otherwise true.
56
+ */
48
57
  beforeParseContent;
49
- /** Called after the modifier's content is parsed. */
58
+ /** Called after the modifier's content is parsed.
59
+ * @param immediate False when the node is inside a `delayContentExpansion` modifier, but it is `alwaysTryExpand`; otherwise true.
60
+ */
50
61
  afterParseContent;
51
- /** Called before reparsing of the expansion. */
62
+ /** Called before reparsing of the expansion.
63
+ * @param immediate False when the node is inside a `delayContentExpansion` modifier, but it is `alwaysTryExpand`; otherwise true.*/
52
64
  beforeProcessExpansion;
53
- /** Called before reparsing of the expansion. */
65
+ /** Called before reparsing of the expansion.
66
+ * @param immediate False when the node is inside a `delayContentExpansion` modifier, but it is `alwaysTryExpand`; otherwise true.*/
54
67
  afterProcessExpansion;
68
+ /**
69
+ * @param immediate False when the node is inside a `delayContentExpansion` modifier, but it is `alwaysTryExpand`; otherwise true.
70
+ */
55
71
  prepareExpand;
72
+ /**
73
+ * @param immediate False when the node is inside a `delayContentExpansion` modifier, but it is `alwaysTryExpand`; otherwise true.
74
+ */
56
75
  expand;
57
76
  };
58
77
  var BlockModifierDefinition = class extends ModifierBase {
@@ -128,14 +147,6 @@ function assert(x) {
128
147
  throw error;
129
148
  }
130
149
  }
131
- function linePositions(src) {
132
- let result = [0];
133
- [...src].forEach((x, i) => {
134
- if (x == "\n") result.push(i + 1);
135
- });
136
- result.push(Infinity);
137
- return result;
138
- }
139
150
  var cloneArgument = (arg, options) => ({
140
151
  location: clonePosition(arg.location, options),
141
152
  content: arg.content.map((ent) => {
@@ -264,12 +275,52 @@ var debug = {
264
275
  }
265
276
  };
266
277
 
278
+ // src/source.ts
279
+ var StringSource = class {
280
+ constructor(d, src) {
281
+ this.src = src;
282
+ this.name = d.name;
283
+ this.lineMap = [0];
284
+ [...src].forEach((x, i) => {
285
+ if (x == "\n") this.lineMap.push(i + 1);
286
+ });
287
+ this.nLines = this.lineMap.length;
288
+ this.lineMap.push(Infinity);
289
+ }
290
+ name;
291
+ nLines;
292
+ lineMap;
293
+ getRowCol(pos) {
294
+ let line = -1, linepos = 0;
295
+ for (let i = 1; i < this.lineMap.length; i++) {
296
+ if (this.lineMap[i] > pos) {
297
+ line = i - 1;
298
+ linepos = this.lineMap[i - 1];
299
+ break;
300
+ }
301
+ }
302
+ return [line, pos - linepos];
303
+ }
304
+ getRowStart(n) {
305
+ assert(n >= 0);
306
+ if (n >= this.lineMap.length) return Infinity;
307
+ return this.lineMap[n];
308
+ }
309
+ getRow(n) {
310
+ const start = this.getRowStart(n);
311
+ const end = this.getRowStart(n + 1);
312
+ if (start === Infinity) return void 0;
313
+ return this.src.substring(start, end - 1);
314
+ }
315
+ };
316
+
267
317
  // src/scanner.ts
268
318
  var SimpleScanner = class {
269
- constructor(src, source = { name: "<input>" }) {
319
+ constructor(src, sourceDesc = { name: "<input>" }) {
270
320
  this.src = src;
271
- this.source = source;
321
+ this.source = new StringSource(sourceDesc, src);
272
322
  }
323
+ source;
273
324
  pos = 0;
274
325
  position() {
275
326
  return this.pos;
@@ -311,7 +362,8 @@ var debugPrint = {
311
362
  blockShorthand: (x) => x.name + x.parts.map((x2, i) => ` .. <arg${i}> .. ${x2}`).join("") + (x.mod.slotType == 2 /* None */ ? "" : ` .. <slot> .. ${x.postfix ?? "<no postfix>"}`),
312
363
  argument: (arg) => arg.content.map(debugPrintArgEntity).join(""),
313
364
  node: (...nodes) => nodes.map((x) => debugPrintNode(x)).join("\n"),
314
- message: (m, source, descriptor) => debugPrintMsg(m, descriptor, source),
365
+ message: debugPrintMsg,
366
+ range: debugPrintRange,
315
367
  document: debugDumpDocument
316
368
  };
317
369
  function debugPrintArgEntity(node) {
@@ -381,38 +433,46 @@ ${prefix}<expansion />`;
381
433
  }
382
434
  return result;
383
435
  }
384
- function debugPrintMsg(m, descriptor, source) {
385
- let pos = (pos2) => `@${pos2}`;
386
- if (source) {
387
- const lines = linePositions(source);
388
- pos = (pos2) => {
389
- let line = -1, linepos = 0;
390
- for (let i = 1; i < lines.length; i++) {
391
- if (lines[i] > pos2) {
392
- line = i;
393
- linepos = lines[i - 1];
394
- break;
395
- }
396
- }
397
- return `l${line}c${pos2 - linepos + 1}`;
398
- };
436
+ function debugPrintRange(loc, context = 1) {
437
+ const isSingleCharacter = loc.start == loc.end;
438
+ let [sr, sc] = loc.source.getRowCol(loc.start);
439
+ let [er, ec] = loc.source.getRowCol(loc.actualEnd ?? loc.end);
440
+ const rowWidth = Math.max((sr + 1).toString().length, (er + 1).toString().length);
441
+ const startLine = Math.max(0, sr - context);
442
+ const endLine = Math.min(loc.source.nLines - 1, er + context);
443
+ let lines = [];
444
+ for (let i = startLine; i <= endLine; i++) {
445
+ const line = loc.source.getRow(i);
446
+ lines.push((i + 1).toString().padStart(rowWidth) + " | " + line);
447
+ if (i >= sr && i <= er) {
448
+ const startPos = i == sr ? sc : 0;
449
+ const endPos = i == er ? ec : line.length;
450
+ lines.push(
451
+ " ".repeat(rowWidth) + " | " + " ".repeat(startPos) + (isSingleCharacter ? "^" : "~".repeat(endPos - startPos + 1))
452
+ );
453
+ }
399
454
  }
455
+ return lines.join("\n");
456
+ }
457
+ function debugPrintMsg(m) {
458
+ const poss = (loc2) => {
459
+ const [r1, c1] = loc2.source.getRowCol(loc2.start);
460
+ if (loc2.start == loc2.end) return `l${r1 + 1}c${c1 + 1}`;
461
+ const [r2, c2] = loc2.source.getRowCol(loc2.end);
462
+ return `l${r1 + 1}c${c1 + 1}-l${r2 + 1}c${c2 + 1}`;
463
+ };
400
464
  let loc = m.location;
401
- let result = `at ${pos(loc.start)}-${pos(loc.end)}: ${MessageSeverity[m.severity]}[${m.code}]: ${m.info}`;
402
- if (descriptor && m.location.source !== descriptor) {
403
- result += `
404
- warning: source descriptor mismatch: ${m.location.source.name}`;
405
- }
465
+ let result = `at ${poss(loc)}: ${MessageSeverity[m.severity]}[${m.code}]: ${m.info}`;
406
466
  while (loc = loc.original) {
407
467
  let d = loc.source !== m.location.source ? `(in ${loc.source.name}) ` : "";
408
468
  result += `
409
- ---> original at: ${d}${pos(loc.start)}-${pos(loc.end)}`;
469
+ ---> original at: ${d}${poss(loc)}`;
410
470
  }
411
471
  return result;
412
472
  }
413
- function debugDumpDocument(doc, source) {
473
+ function debugDumpDocument(doc) {
414
474
  let root = debugPrint.node(...doc.root.content);
415
- let msgs = doc.messages.map((x) => debugPrintMsg(x, doc.root.source, source)).join("\n");
475
+ let msgs = doc.messages.map((x) => debugPrintRange(x.location) + "\n" + debugPrintMsg(x)).join("\n");
416
476
  if (msgs.length > 0) msgs += "\n";
417
477
  return `Document: ${doc.root.source.name}
418
478
  ${msgs}${root}`;
@@ -424,7 +484,6 @@ __export(messages_exports, {
424
484
  ArgumentCountMismatchMessage: () => ArgumentCountMismatchMessage,
425
485
  CannotExpandArgumentMessage: () => CannotExpandArgumentMessage,
426
486
  CannotUseModuleInSelfMessage: () => CannotUseModuleInSelfMessage,
427
- ContentShouldBeOnNewlineMessage: () => ContentShouldBeOnNewlineMessage,
428
487
  EitherNormalOrPreMessage: () => EitherNormalOrPreMessage,
429
488
  EntityNotAllowedMessage: () => EntityNotAllowedMessage,
430
489
  ExpectedMessage: () => ExpectedMessage,
@@ -437,6 +496,7 @@ __export(messages_exports, {
437
496
  OverwriteDefinitionsMessage: () => OverwriteDefinitionsMessage,
438
497
  OverwriteSpecialVariableMessage: () => OverwriteSpecialVariableMessage,
439
498
  ReachedRecursionLimitMessage: () => ReachedRecursionLimitMessage,
499
+ ShouldBeOnNewlineMessage: () => ShouldBeOnNewlineMessage,
440
500
  SlotUsedOutsideDefinitionMessage: () => SlotUsedOutsideDefinitionMessage,
441
501
  UnclosedInlineModifierMessage: () => UnclosedInlineModifierMessage,
442
502
  UndefinedVariableMessage: () => UndefinedVariableMessage,
@@ -503,7 +563,7 @@ var UnknownModifierMessage = class {
503
563
  code = 2;
504
564
  severity = 2 /* Error */;
505
565
  get info() {
506
- return `unknown modifier '${this.what}'; did you forget to escape it?`;
566
+ return `unknown modifier '${this.what}'`;
507
567
  }
508
568
  // get fixes(): readonly FixSuggestion[] {
509
569
  // let [start, end] = [this.start, this.end];
@@ -673,13 +733,13 @@ var NewBlockShouldBeOnNewlineMessage = class extends AddThingMessage {
673
733
  );
674
734
  }
675
735
  };
676
- var ContentShouldBeOnNewlineMessage = class extends AddThingMessage {
736
+ var ShouldBeOnNewlineMessage = class extends AddThingMessage {
677
737
  constructor(location) {
678
738
  super(
679
739
  3,
680
740
  1 /* Warning */,
681
741
  location,
682
- "the content should begin in a new line to avoid confusion"
742
+ "the following should begin in a new line to avoid confusion"
683
743
  );
684
744
  }
685
745
  };
@@ -764,6 +824,41 @@ var Document = class _Document {
764
824
  );
765
825
  return doc;
766
826
  }
827
+ /**
828
+ * Performs a depth-first walk of the node tree.
829
+ */
830
+ walk(callback) {
831
+ let nodes = this.root.content;
832
+ let node;
833
+ while (node = nodes.shift()) {
834
+ const result = callback(node);
835
+ if (result == "break") break;
836
+ if (result == "skip") continue;
837
+ if ("arguments" in node)
838
+ nodes.push(...node.arguments.flatMap((x) => x.content));
839
+ if ("content" in node && Array.isArray(node.content))
840
+ nodes.push(...node.content);
841
+ }
842
+ }
843
+ /**
844
+ * Gets all nodes that covers the given position, from outermost to innermost (essentially a path).
845
+ */
846
+ resolvePosition(pos) {
847
+ const result = [];
848
+ let nodes = this.root.content;
849
+ let node;
850
+ while (node = nodes.shift()) {
851
+ if (node.location.start <= pos && (node.location.actualEnd ?? node.location.end) >= pos) {
852
+ result.push(node);
853
+ nodes = [];
854
+ if ("arguments" in node)
855
+ nodes.push(...node.arguments.flatMap((x) => x.content));
856
+ if ("content" in node && Array.isArray(node.content))
857
+ nodes.push(...node.content);
858
+ }
859
+ }
860
+ return result;
861
+ }
767
862
  };
768
863
  var Configuration = class _Configuration {
769
864
  initializers = [];
@@ -886,6 +981,7 @@ var Parser = class {
886
981
  end: to ?? this.scanner.position()
887
982
  };
888
983
  }
984
+ /* istanbul ignore next -- @preserve */
889
985
  #defs(type) {
890
986
  switch (type) {
891
987
  case 5 /* SystemModifier */:
@@ -1020,7 +1116,7 @@ var Parser = class {
1020
1116
  SHOULD_BE_A_NEWLINE() {
1021
1117
  this.WHITESPACES();
1022
1118
  if (!this.scanner.accept("\n")) this.emit.message(
1023
- new ContentShouldBeOnNewlineMessage(this.#loc())
1119
+ new ShouldBeOnNewlineMessage(this.#loc())
1024
1120
  );
1025
1121
  }
1026
1122
  // TODO: this is awkward and doesn't emit messages in the most appropriate way
@@ -1110,14 +1206,28 @@ var Parser = class {
1110
1206
  if (grouped) this.SHOULD_BE_A_NEWLINE();
1111
1207
  const posContentStart = this.scanner.position();
1112
1208
  let posContentEnd = this.scanner.position();
1209
+ let paragraphEnd = void 0;
1113
1210
  let string = "";
1114
1211
  while (!this.scanner.isEOF()) {
1115
1212
  if (this.scanner.accept("\n")) {
1116
1213
  let white = "\n";
1117
- let char = "";
1214
+ let char;
1118
1215
  while ((char = this.scanner.acceptWhitespaceChar()) !== null)
1119
1216
  white += char;
1120
- if (grouped && this.scanner.accept(GROUP_END) || !grouped && this.scanner.accept("\n")) break;
1217
+ if (grouped && this.scanner.accept(GROUP_END)) {
1218
+ paragraphEnd = this.scanner.position();
1219
+ if (!this.scanner.isEOF()) {
1220
+ this.SHOULD_BE_A_NEWLINE();
1221
+ this.WARN_IF_MORE_NEWLINES_THAN(1);
1222
+ }
1223
+ break;
1224
+ }
1225
+ if (!grouped && this.scanner.accept("\n")) {
1226
+ paragraphEnd = this.scanner.position() - 1;
1227
+ if (!this.scanner.isEOF())
1228
+ this.WARN_IF_MORE_NEWLINES_THAN(0);
1229
+ break;
1230
+ }
1121
1231
  if (this.scanner.isEOF()) {
1122
1232
  if (grouped) this.emit.message(
1123
1233
  new ExpectedMessage(this.#loc(), GROUP_END)
@@ -1132,7 +1242,7 @@ var Parser = class {
1132
1242
  }
1133
1243
  const node = {
1134
1244
  type: 2 /* Preformatted */,
1135
- location: this.#locFrom(posStart),
1245
+ location: this.#locFrom(posStart, paragraphEnd ?? posContentEnd),
1136
1246
  content: {
1137
1247
  start: posContentStart,
1138
1248
  end: posContentEnd,
@@ -1149,6 +1259,10 @@ var Parser = class {
1149
1259
  this.WARN_IF_MORE_NEWLINES_THAN(1);
1150
1260
  while (!this.scanner.isEOF()) {
1151
1261
  if (this.scanner.accept(GROUP_END)) {
1262
+ if (!this.scanner.isEOF()) {
1263
+ this.SHOULD_BE_A_NEWLINE();
1264
+ this.WARN_IF_MORE_NEWLINES_THAN(1);
1265
+ }
1152
1266
  this.groupDepth--;
1153
1267
  return;
1154
1268
  }
@@ -1219,6 +1333,10 @@ var Parser = class {
1219
1333
  if (node.mod.delayContentExpansion) this.delayDepth++;
1220
1334
  let ok = true;
1221
1335
  if (isMarker) {
1336
+ if (!this.scanner.isEOF() && type == 7 /* BlockModifier */) {
1337
+ this.SHOULD_BE_A_NEWLINE();
1338
+ this.WARN_IF_MORE_NEWLINES_THAN(1);
1339
+ }
1222
1340
  if (type === 6 /* InlineModifier */) this.emit.addInlineNode(node);
1223
1341
  else this.emit.addBlockNode(node);
1224
1342
  } else if (type == 6 /* InlineModifier */) {
@@ -1265,6 +1383,10 @@ var Parser = class {
1265
1383
  return this.MODIFIER(6 /* InlineModifier */);
1266
1384
  if (this.scanner.peek(MODIFIER_SYSTEM_OPEN))
1267
1385
  return false;
1386
+ if (this.scanner.peek(MODIFIER_BLOCK_OPEN)) {
1387
+ this.SHOULD_BE_A_NEWLINE();
1388
+ return false;
1389
+ }
1268
1390
  const short = this.cxt.config.inlineShorthands.find((x) => this.scanner.accept(x.name));
1269
1391
  if (short) return this.SHORTHAND(6 /* InlineModifier */, short);
1270
1392
  if (this.scanner.accept("\\")) {
@@ -1393,9 +1515,9 @@ function parse(scanner, cxt) {
1393
1515
 
1394
1516
  // src/renderer.ts
1395
1517
  var RenderContext = class {
1396
- constructor(config2, parseContext, state) {
1518
+ constructor(config2, parsedDocument, state) {
1397
1519
  this.config = config2;
1398
- this.parseContext = parseContext;
1520
+ this.parsedDocument = parsedDocument;
1399
1521
  this.state = state;
1400
1522
  }
1401
1523
  renderEntity(node) {
@@ -1433,7 +1555,7 @@ var RenderConfiguration = class _RenderConfiguration {
1433
1555
  blockRenderers = /* @__PURE__ */ new Map();
1434
1556
  inlineRenderers = /* @__PURE__ */ new Map();
1435
1557
  render(doc, state) {
1436
- let cxt = new RenderContext(this, doc.context, state);
1558
+ let cxt = new RenderContext(this, doc, state);
1437
1559
  let results = doc.toStripped().root.content.map((x) => cxt.renderEntity(x)).filter((x) => x !== void 0);
1438
1560
  return this.postprocessor(results, cxt);
1439
1561
  }
@@ -1456,6 +1578,14 @@ var RenderConfiguration = class _RenderConfiguration {
1456
1578
  };
1457
1579
 
1458
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
+ });
1459
1589
  function checkArgumentLength(node, min, max = min) {
1460
1590
  if (min !== void 0 && node.arguments.length < min || max !== void 0 && node.arguments.length > max) {
1461
1591
  return [new ArgumentCountMismatchMessage({
@@ -1499,28 +1629,33 @@ function onlyPermitPlaintextParagraph(node) {
1499
1629
  }
1500
1630
  return result;
1501
1631
  }
1632
+ function checkContent(ents) {
1633
+ if (ents.length == 0) return "";
1634
+ else if (ents.length > 1) {
1635
+ let last = ents.at(-1).location;
1636
+ return [new MultipleBlocksNotPermittedMessage({
1637
+ source: last.source,
1638
+ start: ents[1].location.start,
1639
+ end: last.actualEnd ?? last.end
1640
+ })];
1641
+ }
1642
+ return check(ents[0]);
1643
+ }
1502
1644
  function check(ent) {
1503
1645
  if (ent.type == 7 /* BlockModifier */) {
1504
1646
  if (!ent.expansion) return [new EntityNotAllowedMessage(
1505
1647
  ent.location,
1506
1648
  "it does not expand to plain text"
1507
1649
  )];
1508
- if (ent.expansion.length == 0) return "";
1509
- else if (ent.expansion.length > 1) {
1510
- let last = ent.expansion.at(-1).location;
1511
- return [new MultipleBlocksNotPermittedMessage({
1512
- source: last.source,
1513
- start: ent.expansion[1].location.start,
1514
- end: last.actualEnd ?? last.end
1515
- })];
1516
- }
1517
- return check(ent.expansion[0]);
1650
+ return checkContent(ent.expansion);
1651
+ } else if (ent.type == 2 /* Preformatted */) {
1652
+ return ent.content.text;
1518
1653
  } else if (ent.type !== 1 /* Paragraph */) {
1519
1654
  return [new OnlySimpleParagraphsPermittedMessage(ent.location)];
1520
1655
  }
1521
1656
  return checkInline(ent.content);
1522
1657
  }
1523
- return check(node);
1658
+ return checkContent(node.content);
1524
1659
  }
1525
1660
  function onlyPermitSimpleParagraphs(node) {
1526
1661
  function check(nodes) {
@@ -1600,24 +1735,20 @@ function customModifier(type, name, signature, content) {
1600
1735
  args: node.state.args,
1601
1736
  slotContent: node.content
1602
1737
  });
1738
+ debug.trace(`pushed ${NodeType[type]} slot data for`, name);
1603
1739
  debug.trace(
1604
- `pushed ${NodeType[type]} slot data for`,
1605
- name,
1606
- signature.slotName == "" ? "(unnamed)" : `= ${signature.slotName}`
1740
+ `... slotName:`,
1741
+ signature.slotName === "" ? "<unnamed>" : signature.slotName === void 0 ? "<no slot>" : `'${signature.slotName}'`
1607
1742
  );
1743
+ debug.trace(`... args:`, "{" + [...node.state.args].map(([a, b]) => `${a} => ${b}`).join(", ") + "}");
1608
1744
  return [];
1609
1745
  };
1610
1746
  mod.afterProcessExpansion = (node, cxt) => {
1611
- if (!node.state?.ok || signature.slotName === void 0) return [];
1747
+ if (!node.state?.ok) return [];
1612
1748
  const store = cxt.get(builtins);
1613
1749
  const data = isInline ? store.inlineInstantiationData : store.blockInstantiationData;
1614
- const pop = data.pop();
1615
- assert(pop !== void 0);
1616
- debug.trace(
1617
- `popped ${NodeType[type]} slot data for`,
1618
- name,
1619
- signature.slotName == "" ? "(unnamed)" : `= ${signature.slotName}`
1620
- );
1750
+ data.pop();
1751
+ debug.trace(`popped ${NodeType[type]} slot data for`, name);
1621
1752
  return [];
1622
1753
  };
1623
1754
  return mod;
@@ -1970,6 +2101,17 @@ var DefineInlineShorthandMod = new SystemModifierDefinition(
1970
2101
  }
1971
2102
  );
1972
2103
 
2104
+ // src/builtin/misc.ts
2105
+ var RawBlockMod = new BlockModifierDefinition(
2106
+ "raw",
2107
+ 1 /* Preformatted */,
2108
+ {
2109
+ expand(node) {
2110
+ return node.content;
2111
+ }
2112
+ }
2113
+ );
2114
+
1973
2115
  // src/builtin/module.ts
1974
2116
  function getDefs(cxt) {
1975
2117
  const data = cxt.get(builtins);
@@ -2266,6 +2408,27 @@ function resolveId(id, cxt) {
2266
2408
  value = cxt.variables.get(id);
2267
2409
  return value;
2268
2410
  }
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 : [];
2424
+ }
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));
2428
+ var IfdefBlockMod = ifdefBlock("ifdef", true);
2429
+ var IfndefBlockMod = ifdefBlock("ifndef", false);
2430
+ var IfdefInlineMod = ifdefInline("ifdef", true);
2431
+ var IfndefInlineMod = ifdefInline("ifndef", false);
2269
2432
  var GetVarInlineMod = new InlineModifierDefinition(
2270
2433
  "$",
2271
2434
  2 /* None */,
@@ -2361,19 +2524,25 @@ builtin.blockModifiers.add(
2361
2524
  PreSlotBlockMod,
2362
2525
  InjectPreSlotBlockMod,
2363
2526
  ModuleMod,
2364
- UseBlockMod
2527
+ UseBlockMod,
2528
+ IfdefBlockMod,
2529
+ IfndefBlockMod,
2530
+ RawBlockMod
2365
2531
  );
2366
2532
  builtin.inlineModifiers.add(
2367
2533
  SlotInlineMod,
2368
2534
  PreSlotInlineMod,
2369
2535
  InjectPreSlotInlineMod,
2370
2536
  GetVarInlineMod,
2371
- PrintInlineMod
2537
+ PrintInlineMod,
2538
+ IfdefInlineMod,
2539
+ IfndefInlineMod
2372
2540
  );
2373
2541
  builtin.argumentInterpolators.add(GetVarInterpolator);
2374
2542
  var BuiltinConfiguration = Object.freeze(builtin);
2375
2543
 
2376
- // src/default/bullets.ts
2544
+ // src/default/bullets.tsx
2545
+ import { jsx } from "minimal-jsx-runtime/jsx-runtime";
2377
2546
  var bulletItemBlock = new BlockModifierDefinition(
2378
2547
  "bullet-item",
2379
2548
  0 /* Normal */,
@@ -2404,20 +2573,22 @@ var subItemBlock = new BlockModifierDefinition(
2404
2573
  );
2405
2574
  var BulletBlocks = [bulletItemBlock, orderedListItemBlock, subItemBlock];
2406
2575
  var BulletBlockRenderersHTML = [
2407
- [bulletItemBlock, (node, cxt) => {
2408
- return `<li>${cxt.state.render(node.content, cxt)}</li>`;
2409
- }],
2410
- [subItemBlock, (node, cxt) => {
2411
- return `<div class='subitem'>${cxt.state.render(node.content, cxt)}</div>`;
2412
- }],
2413
- [orderedListItemBlock, (node, cxt) => {
2414
- if (node.state === void 0)
2415
- return cxt.state.invalidBlock(node, "bad format");
2416
- return `<li value='${node.state}'>${cxt.state.render(node.content, cxt)}</li>`;
2417
- }]
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
+ ]
2418
2588
  ];
2419
2589
 
2420
- // src/default/headings.ts
2590
+ // src/default/headings.tsx
2591
+ import { jsx as jsx2 } from "minimal-jsx-runtime/jsx-runtime";
2421
2592
  var headings = Symbol();
2422
2593
  function initHeadings(cxt) {
2423
2594
  cxt.init(headings, {
@@ -2441,9 +2612,8 @@ var headingBlock = new BlockModifierDefinition(
2441
2612
  "heading",
2442
2613
  0 /* Normal */,
2443
2614
  {
2444
- delayContentExpansion: true,
2445
2615
  roleHint: "heading",
2446
- beforeParseContent(node, cxt) {
2616
+ prepareExpand(node, cxt) {
2447
2617
  let msgs = checkArguments(node, 0, 1);
2448
2618
  if (msgs) return msgs;
2449
2619
  msgs = onlyPermitSingleBlock(node);
@@ -2471,7 +2641,7 @@ var implicitHeadingBlock = new BlockModifierDefinition(
2471
2641
  2 /* None */,
2472
2642
  {
2473
2643
  roleHint: "heading",
2474
- beforeParseContent(node, cxt) {
2644
+ prepareExpand(node, cxt) {
2475
2645
  let msgs = checkArguments(node, 0, 1);
2476
2646
  if (msgs) return msgs;
2477
2647
  node.state = {
@@ -2498,9 +2668,8 @@ var numberedHeadingBlock = new BlockModifierDefinition(
2498
2668
  "numbered-heading",
2499
2669
  0 /* Normal */,
2500
2670
  {
2501
- delayContentExpansion: true,
2502
2671
  roleHint: "heading",
2503
- beforeParseContent(node, cxt) {
2672
+ prepareExpand(node, cxt) {
2504
2673
  let msgs = checkArguments(node, 1);
2505
2674
  if (msgs) return msgs;
2506
2675
  msgs = onlyPermitSingleBlock(node);
@@ -2525,37 +2694,103 @@ var HeadingBlocks = [headingBlock, implicitHeadingBlock, numberedHeadingBlock];
2525
2694
  var HeadingBlockRenderersHTML = [
2526
2695
  [headingBlock, (node, cxt) => {
2527
2696
  if (node.state !== void 0) {
2528
- let tag = "h" + node.state.level;
2529
- let para = node.content[0];
2530
- 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;
2531
2702
  }
2532
2703
  return cxt.state.invalidBlock(node, "Bad format");
2533
2704
  }],
2534
2705
  [implicitHeadingBlock, (node, cxt) => {
2535
2706
  if (node.state !== void 0) {
2536
- let tag = "h" + node.state.level;
2537
- 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;
2538
2711
  }
2539
2712
  return cxt.state.invalidBlock(node, "Bad format");
2540
2713
  }],
2541
2714
  [numberedHeadingBlock, (node, cxt) => {
2542
2715
  if (node.state !== void 0) {
2543
- let tag = "h" + node.state.level;
2544
- let para = node.content[0];
2545
- 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;
2546
2722
  }
2547
2723
  return cxt.state.invalidBlock(node, "Bad format");
2548
2724
  }]
2549
2725
  ];
2550
2726
 
2551
- // src/default/notes.ts
2727
+ // src/default/notes.tsx
2728
+ import { jsx as jsx3, jsxs } from "minimal-jsx-runtime/jsx-runtime";
2552
2729
  var notes = Symbol();
2553
2730
  function initNotes(cxt) {
2554
2731
  cxt.init(notes, {
2555
2732
  systems: /* @__PURE__ */ new Map(),
2556
- definitions: []
2733
+ defaultSystem: {
2734
+ position: "preserve",
2735
+ autonumber: false
2736
+ },
2737
+ definitions: [],
2738
+ currentId: 0
2557
2739
  });
2558
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
+ );
2559
2794
  var noteMarkerInline = new InlineModifierDefinition(
2560
2795
  "note",
2561
2796
  2 /* None */,
@@ -2577,13 +2812,15 @@ var noteInline = new InlineModifierDefinition(
2577
2812
  prepareExpand(node) {
2578
2813
  let msgs = checkArguments(node, 0, 1);
2579
2814
  if (msgs) return msgs;
2580
- node.state = node.arguments.at(0)?.expansion ?? "";
2815
+ node.state = node.arguments.at(0)?.expansion?.trim() ?? "";
2581
2816
  return [];
2582
2817
  },
2583
2818
  afterProcessExpansion(node, cxt) {
2584
2819
  if (node.state !== void 0) {
2585
- cxt.get(notes).definitions.push({
2820
+ const defs = cxt.get(notes);
2821
+ defs.definitions.push({
2586
2822
  system: "",
2823
+ id: defs.currentId,
2587
2824
  name: node.state,
2588
2825
  location: node.location,
2589
2826
  content: [{
@@ -2596,6 +2833,7 @@ var noteInline = new InlineModifierDefinition(
2596
2833
  content: node.content
2597
2834
  }]
2598
2835
  });
2836
+ defs.currentId++;
2599
2837
  }
2600
2838
  return [];
2601
2839
  }
@@ -2606,58 +2844,73 @@ var noteBlock = new BlockModifierDefinition(
2606
2844
  0 /* Normal */,
2607
2845
  {
2608
2846
  roleHint: "quote",
2609
- prepareExpand(node) {
2610
- let msgs = checkArguments(node, 1);
2847
+ prepareExpand(node, cxt) {
2848
+ let msgs = checkArguments(node, 1, 2);
2611
2849
  if (msgs) return msgs;
2612
- node.state = node.arguments[0].expansion;
2613
- return [];
2614
- },
2615
- afterProcessExpansion(node, cxt) {
2616
- if (node.state !== void 0) {
2617
- let content = stripNode(...node.content);
2618
- debug.trace(`add note: system=<${""}> name=${node.state} @${node.location.start}`);
2619
- 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(`-->
2620
2855
  `, debugPrint.node(...content));
2621
- cxt.get(notes).definitions.push({
2622
- system: "",
2623
- name: node.state,
2624
- location: node.location,
2625
- content
2626
- });
2627
- }
2628
- 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;
2629
2867
  return [];
2630
2868
  }
2631
2869
  }
2632
2870
  );
2633
2871
  var NoteBlocks = [noteBlock];
2634
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
+ }
2635
2880
  var NoteInlineRenderersHTML = [
2636
2881
  [noteMarkerInline, (node, cxt) => {
2637
2882
  if (node.state === void 0)
2638
2883
  return cxt.state.invalidInline(node, "bad format");
2639
- const defs = cxt.parseContext.get(notes).definitions;
2884
+ const defs = cxt.parsedDocument.context.get(notes).definitions;
2640
2885
  const note = defs.findIndex((x) => (
2641
2886
  /*x.position >= node.start &&*/
2642
2887
  x.name == node.state
2643
2888
  ));
2644
- if (note < 0)
2645
- return `<sup class='note invalid'>Not found: ${node.state}</sup>`;
2646
- 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);
2647
2900
  }]
2648
2901
  ];
2649
2902
  var NotesFooterPlugin = (cxt) => {
2650
- let defs = cxt.parseContext.get(notes).definitions;
2651
- if (defs.length == 0) return void 0;
2652
- return `<hr/>
2653
- <section class='notes'>
2654
- ${defs.map((x, i) => `<section class='note' id='note-id-${i}'>
2655
- <div class='note-name'><p><a href='#notemarker-id-${i}'>${x.name}</a></p></div>
2656
- <div class='note-content'>${cxt.state.render(x.content, cxt)}</div></section>`).join("\n")}
2657
- </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
+ ];
2658
2910
  };
2659
2911
 
2660
- // src/default/code.ts
2912
+ // src/default/code.tsx
2913
+ import { jsx as jsx4 } from "minimal-jsx-runtime/jsx-runtime";
2661
2914
  var CodeBlock = new BlockModifierDefinition(
2662
2915
  "code",
2663
2916
  1 /* Preformatted */,
@@ -2668,14 +2921,17 @@ var CodeInline = new InlineModifierDefinition(
2668
2921
  1 /* Preformatted */,
2669
2922
  { roleHint: "code" }
2670
2923
  );
2671
- var CodeBlockRendererHTML = [CodeBlock, (node, cxt) => {
2672
- return `<pre><code>${cxt.state.render(node.content, cxt)}</code></pre>`;
2673
- }];
2674
- var CodeInlineRendererHTML = [CodeInline, (node, cxt) => {
2675
- return `<span><code>${cxt.state.render(node.content, cxt)}</code></span>`;
2676
- }];
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
+ ];
2677
2932
 
2678
- // src/default/quotes.ts
2933
+ // src/default/quotes.tsx
2934
+ import { jsx as jsx5 } from "minimal-jsx-runtime/jsx-runtime";
2679
2935
  var quoteBlock = new BlockModifierDefinition(
2680
2936
  "quote",
2681
2937
  0 /* Normal */,
@@ -2686,6 +2942,16 @@ var epitaphBlock = new BlockModifierDefinition(
2686
2942
  0 /* Normal */,
2687
2943
  { roleHint: "quote" }
2688
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
+ );
2689
2955
  var attributionBlock = new BlockModifierDefinition(
2690
2956
  "by",
2691
2957
  0 /* Normal */,
@@ -2701,23 +2967,34 @@ var attributionBlock = new BlockModifierDefinition(
2701
2967
  }
2702
2968
  }
2703
2969
  );
2704
- var QuoteBlocks = [quoteBlock, epitaphBlock, attributionBlock];
2970
+ var QuoteBlocks = [quoteBlock, epitaphBlock, calloutBlock, detailBlock, attributionBlock];
2705
2971
  var QuoteBlockRenderersHTML = [
2706
- [quoteBlock, (node, cxt) => {
2707
- return `<blockquote>${cxt.state.render(node.content, cxt)}</blockquote>`;
2708
- }],
2709
- [epitaphBlock, (node, cxt) => {
2710
- return `<blockquote class='epitaph'>${cxt.state.render(node.content, cxt)}</blockquote>`;
2711
- }],
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
+ ],
2712
2988
  [attributionBlock, (node, cxt) => {
2713
2989
  if (!node.state)
2714
2990
  return cxt.state.invalidBlock(node, "bad format");
2715
2991
  let para = node.content[0];
2716
- 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) });
2717
2993
  }]
2718
2994
  ];
2719
2995
 
2720
- // src/default/inline-styles.ts
2996
+ // src/default/inline-styles.tsx
2997
+ import { jsx as jsx6 } from "minimal-jsx-runtime/jsx-runtime";
2721
2998
  var emphasisInline = new InlineModifierDefinition(
2722
2999
  "emphasis",
2723
3000
  0 /* Normal */,
@@ -2738,23 +3015,37 @@ var commentaryInline = new InlineModifierDefinition(
2738
3015
  0 /* Normal */,
2739
3016
  { roleHint: "commentary" }
2740
3017
  );
2741
- 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];
2742
3024
  var InlineStyleRenderersHTML = [
2743
- [emphasisInline, (node, cxt) => {
2744
- return `<em>${cxt.state.render(node.content, cxt)}</em>`;
2745
- }],
2746
- [keywordInline, (node, cxt) => {
2747
- return `<b>${cxt.state.render(node.content, cxt)}</b>`;
2748
- }],
2749
- [highlightInline, (node, cxt) => {
2750
- return `<mark>${cxt.state.render(node.content, cxt)}</mark>`;
2751
- }],
2752
- [commentaryInline, (node, cxt) => {
2753
- return `<span class='commentary'>${cxt.state.render(node.content, cxt)}</span>`;
2754
- }]
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
+ ]
2755
3045
  ];
2756
3046
 
2757
- // src/default/misc.ts
3047
+ // src/default/misc.tsx
3048
+ import { jsx as jsx7, jsxs as jsxs2 } from "minimal-jsx-runtime/jsx-runtime";
2758
3049
  var rubyInline = new InlineModifierDefinition(
2759
3050
  "ruby",
2760
3051
  0 /* Normal */,
@@ -2830,43 +3121,46 @@ var imageBlock = new BlockModifierDefinition(
2830
3121
  var MiscInlines = [rubyInline, linkInline];
2831
3122
  var MiscBlocks = [styleBlock, breakBlock, linkBlock, imageBlock];
2832
3123
  var MiscInlineRenderersHTML = [
2833
- [rubyInline, (node, cxt) => {
2834
- if (node.state === void 0)
2835
- return cxt.state.invalidInline(node, "bad format");
2836
- return `<ruby>${cxt.state.render(node.content, cxt)}<rt>${node.state}</rt></ruby>`;
2837
- }],
2838
- [linkInline, (node, cxt) => {
2839
- if (node.state === void 0)
2840
- return cxt.state.invalidInline(node, "bad format");
2841
- return `<a href="${encodeURI(node.state)}">${cxt.state.render(node.content, cxt)}</a>`;
2842
- }]
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
+ ]
2843
3135
  ];
2844
3136
  var MiscBlockRenderersHTML = [
2845
- [styleBlock, (node, cxt) => {
2846
- if (node.state === void 0)
2847
- return cxt.state.invalidBlock(node, "bad format");
2848
- return `<div class="${node.state}" style="display:contents">${cxt.state.render(node.content, cxt)}</div>`;
2849
- }],
2850
- [breakBlock, () => {
2851
- return `<hr>`;
2852
- }],
2853
- [linkBlock, (node, cxt) => {
2854
- if (node.state === void 0)
2855
- return cxt.state.invalidBlock(node, "bad format");
2856
- return `<a href="${encodeURI(node.state)}">${cxt.state.render(node.content, cxt)}</a>`;
2857
- }],
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
+ ],
2858
3151
  [imageBlock, (node, cxt) => {
2859
- let transformed;
2860
3152
  if (node.state === void 0)
2861
3153
  return cxt.state.invalidBlock(node, "bad format");
3154
+ let transformed;
2862
3155
  try {
2863
3156
  transformed = cxt.config.options.transformAsset(node.state);
2864
3157
  } catch {
2865
3158
  return cxt.state.invalidBlock(node, "unable to transform asset");
2866
3159
  }
2867
- const img = transformed ? `<img src="${transformed}" data-original-src="${node.state}"/>` : `<img src="${node.state}"/>`;
2868
- const para = node.content.length == 0 ? "" : "\n<figcaption>" + cxt.state.render(node.content[0].content, cxt) + "</figcaption>";
2869
- 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
+ ] });
2870
3164
  }]
2871
3165
  ];
2872
3166
 
@@ -2884,6 +3178,7 @@ function createWrapper(name, varname) {
2884
3178
  if (previous)
2885
3179
  msgs = [new OverwriteSpecialVariableMessage(node.head, varname, previous)];
2886
3180
  cxt.variables.set(varname, result);
3181
+ debug.trace(varname, "->", result);
2887
3182
  return msgs ?? [];
2888
3183
  }
2889
3184
  });
@@ -2920,34 +3215,45 @@ config.inlineModifiers.add(
2920
3215
  ...NoteInlines
2921
3216
  );
2922
3217
  config.systemModifiers.add(
2923
- ...VarWrappers
3218
+ ...VarWrappers,
3219
+ ...NoteSystems
2924
3220
  );
2925
3221
  var DefaultConfiguration = Object.freeze(config);
2926
3222
 
2927
- // 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";
2928
3225
  var HTMLRenderState = class {
2929
3226
  title = "";
2930
3227
  stylesheet = "";
2931
3228
  // FIXME: very unsafe!
2932
3229
  cssVariables = /* @__PURE__ */ new Map();
2933
- // https://stackoverflow.com/questions/7381974
2934
- escape(content) {
2935
- return content.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;").replaceAll("\n", "<br/>");
2936
- }
2937
3230
  invalidBlock(node, msg) {
2938
3231
  let name = NodeType[node.type];
2939
3232
  if (node.type === 7 /* BlockModifier */)
2940
3233
  name += ` (${node.mod.name})`;
2941
- 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
+ ] });
2942
3241
  }
2943
3242
  invalidInline(node, msg) {
2944
3243
  let name = NodeType[node.type];
2945
3244
  if (node.type === 6 /* InlineModifier */)
2946
3245
  name += ` (${node.mod.name})`;
2947
- 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
+ ] });
2948
3252
  }
2949
3253
  render(elems, cxt) {
2950
- 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;
2951
3257
  }
2952
3258
  };
2953
3259
  var htmlConfig = new RenderConfiguration(
@@ -2955,7 +3261,8 @@ var htmlConfig = new RenderConfiguration(
2955
3261
  headPlugins: [],
2956
3262
  headerPlugins: [],
2957
3263
  footerPlugins: [NotesFooterPlugin],
2958
- transformAsset: (x) => void 0
3264
+ postprocessPlugins: [],
3265
+ transformAsset: () => void 0
2959
3266
  // postprocessPlugins: [],
2960
3267
  },
2961
3268
  (results, cxt) => {
@@ -2963,35 +3270,41 @@ var htmlConfig = new RenderConfiguration(
2963
3270
  /var\(--(.*?)\)/g,
2964
3271
  (m, c) => cxt.state.cssVariables.get(c) ?? m
2965
3272
  );
2966
- return `
2967
- <!DOCTYPE html>
2968
- <html>
2969
- <head>
2970
- <meta charset="UTF-8">
2971
- ${cxt.config.options.headPlugins.map((x) => x(cxt)).filter((x) => x !== void 0).join("\n")}
2972
- <title>${cxt.state.escape(cxt.state.title)}</title>
2973
- <style>${styles}</style>
2974
- </head>
2975
- <body>
2976
- <section class="article-container">
2977
- <section class="article-body">
2978
- ${cxt.config.options.headerPlugins.map((x) => x(cxt)).filter((x) => x !== void 0).join("\n")}
2979
- ${results.join("\n")}
2980
- ${cxt.config.options.footerPlugins.map((x) => x(cxt)).filter((x) => x !== void 0).join("\n")}
2981
- </section>
2982
- </section>
2983
- </body>
2984
- </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;
2985
3290
  }
2986
3291
  );
2987
- 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) });
2988
3293
  htmlConfig.textRenderer = (node, cxt) => {
2989
3294
  switch (node.type) {
2990
3295
  case 2 /* Preformatted */:
2991
- return cxt.state.escape(node.content.text);
3296
+ return new Text(node.content.text);
2992
3297
  case 3 /* Text */:
2993
3298
  case 4 /* Escaped */:
2994
- 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;
2995
3308
  default:
2996
3309
  return debug.never(node);
2997
3310
  }
@@ -3007,8 +3320,8 @@ htmlConfig.addBlockRenderer(
3007
3320
  ...BulletBlockRenderersHTML,
3008
3321
  CodeBlockRendererHTML,
3009
3322
  ...QuoteBlockRenderersHTML,
3010
- ...MiscBlockRenderersHTML
3011
- // TODO: notes
3323
+ ...MiscBlockRenderersHTML,
3324
+ ...NoteBlockRenderersHTML
3012
3325
  );
3013
3326
  htmlConfig.addInlineRenderer(
3014
3327
  CodeInlineRendererHTML,
@@ -3019,6 +3332,7 @@ htmlConfig.addInlineRenderer(
3019
3332
  var HTMLRenderConfiguration = htmlConfig;
3020
3333
 
3021
3334
  // src/index.ts
3335
+ var emmmVersion = "0.0.6";
3022
3336
  function setDebugLevel(level) {
3023
3337
  debug.level = level;
3024
3338
  }
@@ -3040,8 +3354,11 @@ export {
3040
3354
  RenderConfiguration,
3041
3355
  RenderContext,
3042
3356
  SimpleScanner,
3357
+ StringSource,
3043
3358
  SystemModifierDefinition,
3044
3359
  debugPrint,
3360
+ emmmVersion,
3361
+ modifier_helper_exports as helper,
3045
3362
  messages_exports as messages,
3046
3363
  parse,
3047
3364
  setDebugLevel