@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.js CHANGED
@@ -37,8 +37,11 @@ __export(index_exports, {
37
37
  RenderConfiguration: () => RenderConfiguration,
38
38
  RenderContext: () => RenderContext,
39
39
  SimpleScanner: () => SimpleScanner,
40
+ StringSource: () => StringSource,
40
41
  SystemModifierDefinition: () => SystemModifierDefinition,
41
42
  debugPrint: () => debugPrint,
43
+ emmmVersion: () => emmmVersion,
44
+ helper: () => modifier_helper_exports,
42
45
  messages: () => messages_exports,
43
46
  parse: () => parse,
44
47
  setDebugLevel: () => setDebugLevel
@@ -76,24 +79,43 @@ var ModifierBase = class {
76
79
  this.slotType = slotType;
77
80
  if (args) Object.assign(this, args);
78
81
  }
82
+ /**
83
+ * Common values: heading, emphasis, keyword, highlight, commentary, comment, link, quote
84
+ */
79
85
  roleHint;
80
86
  /**
81
- * If true, any modifier encountered in the content of it will *not* be expanded, *unless* that modifier is `alwaysTryExpand`.
87
+ * If true, any modifier encountered inside it will *not* be expanded *during parse-content*,
88
+ * *unless* that modifier is `alwaysTryExpand`. In the vast majority of cases, you shouldn't
89
+ * be using this.
82
90
  */
83
91
  delayContentExpansion = false;
84
92
  /**
85
- * If true, such a modifier will always be expanded whenever it is encountered, *even if* contained in a modifier with `delayContentExpansion`.
93
+ * If true, such a modifier will always be expanded whenever it is encountered, *even if*
94
+ * it is contained in a modifier with `delayContentExpansion`. In the vast majority of cases,
95
+ * you shouldn't be using this.
86
96
  */
87
97
  alwaysTryExpand = false;
88
- /** Called before the modifier's content is parsed. */
98
+ /** Called before the modifier's content is parsed.
99
+ * @param immediate False when the node is inside a `delayContentExpansion` modifier, but it is `alwaysTryExpand`; otherwise true.
100
+ */
89
101
  beforeParseContent;
90
- /** Called after the modifier's content is parsed. */
102
+ /** Called after the modifier's content is parsed.
103
+ * @param immediate False when the node is inside a `delayContentExpansion` modifier, but it is `alwaysTryExpand`; otherwise true.
104
+ */
91
105
  afterParseContent;
92
- /** Called before reparsing of the expansion. */
106
+ /** Called before reparsing of the expansion.
107
+ * @param immediate False when the node is inside a `delayContentExpansion` modifier, but it is `alwaysTryExpand`; otherwise true.*/
93
108
  beforeProcessExpansion;
94
- /** Called before reparsing of the expansion. */
109
+ /** Called before reparsing of the expansion.
110
+ * @param immediate False when the node is inside a `delayContentExpansion` modifier, but it is `alwaysTryExpand`; otherwise true.*/
95
111
  afterProcessExpansion;
112
+ /**
113
+ * @param immediate False when the node is inside a `delayContentExpansion` modifier, but it is `alwaysTryExpand`; otherwise true.
114
+ */
96
115
  prepareExpand;
116
+ /**
117
+ * @param immediate False when the node is inside a `delayContentExpansion` modifier, but it is `alwaysTryExpand`; otherwise true.
118
+ */
97
119
  expand;
98
120
  };
99
121
  var BlockModifierDefinition = class extends ModifierBase {
@@ -169,14 +191,6 @@ function assert(x) {
169
191
  throw error;
170
192
  }
171
193
  }
172
- function linePositions(src) {
173
- let result = [0];
174
- [...src].forEach((x, i) => {
175
- if (x == "\n") result.push(i + 1);
176
- });
177
- result.push(Infinity);
178
- return result;
179
- }
180
194
  var cloneArgument = (arg, options) => ({
181
195
  location: clonePosition(arg.location, options),
182
196
  content: arg.content.map((ent) => {
@@ -305,12 +319,52 @@ var debug = {
305
319
  }
306
320
  };
307
321
 
322
+ // src/source.ts
323
+ var StringSource = class {
324
+ constructor(d, src) {
325
+ this.src = src;
326
+ this.name = d.name;
327
+ this.lineMap = [0];
328
+ [...src].forEach((x, i) => {
329
+ if (x == "\n") this.lineMap.push(i + 1);
330
+ });
331
+ this.nLines = this.lineMap.length;
332
+ this.lineMap.push(Infinity);
333
+ }
334
+ name;
335
+ nLines;
336
+ lineMap;
337
+ getRowCol(pos) {
338
+ let line = -1, linepos = 0;
339
+ for (let i = 1; i < this.lineMap.length; i++) {
340
+ if (this.lineMap[i] > pos) {
341
+ line = i - 1;
342
+ linepos = this.lineMap[i - 1];
343
+ break;
344
+ }
345
+ }
346
+ return [line, pos - linepos];
347
+ }
348
+ getRowStart(n) {
349
+ assert(n >= 0);
350
+ if (n >= this.lineMap.length) return Infinity;
351
+ return this.lineMap[n];
352
+ }
353
+ getRow(n) {
354
+ const start = this.getRowStart(n);
355
+ const end = this.getRowStart(n + 1);
356
+ if (start === Infinity) return void 0;
357
+ return this.src.substring(start, end - 1);
358
+ }
359
+ };
360
+
308
361
  // src/scanner.ts
309
362
  var SimpleScanner = class {
310
- constructor(src, source = { name: "<input>" }) {
363
+ constructor(src, sourceDesc = { name: "<input>" }) {
311
364
  this.src = src;
312
- this.source = source;
365
+ this.source = new StringSource(sourceDesc, src);
313
366
  }
367
+ source;
314
368
  pos = 0;
315
369
  position() {
316
370
  return this.pos;
@@ -352,7 +406,8 @@ var debugPrint = {
352
406
  blockShorthand: (x) => x.name + x.parts.map((x2, i) => ` .. <arg${i}> .. ${x2}`).join("") + (x.mod.slotType == 2 /* None */ ? "" : ` .. <slot> .. ${x.postfix ?? "<no postfix>"}`),
353
407
  argument: (arg) => arg.content.map(debugPrintArgEntity).join(""),
354
408
  node: (...nodes) => nodes.map((x) => debugPrintNode(x)).join("\n"),
355
- message: (m, source, descriptor) => debugPrintMsg(m, descriptor, source),
409
+ message: debugPrintMsg,
410
+ range: debugPrintRange,
356
411
  document: debugDumpDocument
357
412
  };
358
413
  function debugPrintArgEntity(node) {
@@ -422,38 +477,46 @@ ${prefix}<expansion />`;
422
477
  }
423
478
  return result;
424
479
  }
425
- function debugPrintMsg(m, descriptor, source) {
426
- let pos = (pos2) => `@${pos2}`;
427
- if (source) {
428
- const lines = linePositions(source);
429
- pos = (pos2) => {
430
- let line = -1, linepos = 0;
431
- for (let i = 1; i < lines.length; i++) {
432
- if (lines[i] > pos2) {
433
- line = i;
434
- linepos = lines[i - 1];
435
- break;
436
- }
437
- }
438
- return `l${line}c${pos2 - linepos + 1}`;
439
- };
480
+ function debugPrintRange(loc, context = 1) {
481
+ const isSingleCharacter = loc.start == loc.end;
482
+ let [sr, sc] = loc.source.getRowCol(loc.start);
483
+ let [er, ec] = loc.source.getRowCol(loc.actualEnd ?? loc.end);
484
+ const rowWidth = Math.max((sr + 1).toString().length, (er + 1).toString().length);
485
+ const startLine = Math.max(0, sr - context);
486
+ const endLine = Math.min(loc.source.nLines - 1, er + context);
487
+ let lines = [];
488
+ for (let i = startLine; i <= endLine; i++) {
489
+ const line = loc.source.getRow(i);
490
+ lines.push((i + 1).toString().padStart(rowWidth) + " | " + line);
491
+ if (i >= sr && i <= er) {
492
+ const startPos = i == sr ? sc : 0;
493
+ const endPos = i == er ? ec : line.length;
494
+ lines.push(
495
+ " ".repeat(rowWidth) + " | " + " ".repeat(startPos) + (isSingleCharacter ? "^" : "~".repeat(endPos - startPos + 1))
496
+ );
497
+ }
440
498
  }
499
+ return lines.join("\n");
500
+ }
501
+ function debugPrintMsg(m) {
502
+ const poss = (loc2) => {
503
+ const [r1, c1] = loc2.source.getRowCol(loc2.start);
504
+ if (loc2.start == loc2.end) return `l${r1 + 1}c${c1 + 1}`;
505
+ const [r2, c2] = loc2.source.getRowCol(loc2.end);
506
+ return `l${r1 + 1}c${c1 + 1}-l${r2 + 1}c${c2 + 1}`;
507
+ };
441
508
  let loc = m.location;
442
- let result = `at ${pos(loc.start)}-${pos(loc.end)}: ${MessageSeverity[m.severity]}[${m.code}]: ${m.info}`;
443
- if (descriptor && m.location.source !== descriptor) {
444
- result += `
445
- warning: source descriptor mismatch: ${m.location.source.name}`;
446
- }
509
+ let result = `at ${poss(loc)}: ${MessageSeverity[m.severity]}[${m.code}]: ${m.info}`;
447
510
  while (loc = loc.original) {
448
511
  let d = loc.source !== m.location.source ? `(in ${loc.source.name}) ` : "";
449
512
  result += `
450
- ---> original at: ${d}${pos(loc.start)}-${pos(loc.end)}`;
513
+ ---> original at: ${d}${poss(loc)}`;
451
514
  }
452
515
  return result;
453
516
  }
454
- function debugDumpDocument(doc, source) {
517
+ function debugDumpDocument(doc) {
455
518
  let root = debugPrint.node(...doc.root.content);
456
- let msgs = doc.messages.map((x) => debugPrintMsg(x, doc.root.source, source)).join("\n");
519
+ let msgs = doc.messages.map((x) => debugPrintRange(x.location) + "\n" + debugPrintMsg(x)).join("\n");
457
520
  if (msgs.length > 0) msgs += "\n";
458
521
  return `Document: ${doc.root.source.name}
459
522
  ${msgs}${root}`;
@@ -465,7 +528,6 @@ __export(messages_exports, {
465
528
  ArgumentCountMismatchMessage: () => ArgumentCountMismatchMessage,
466
529
  CannotExpandArgumentMessage: () => CannotExpandArgumentMessage,
467
530
  CannotUseModuleInSelfMessage: () => CannotUseModuleInSelfMessage,
468
- ContentShouldBeOnNewlineMessage: () => ContentShouldBeOnNewlineMessage,
469
531
  EitherNormalOrPreMessage: () => EitherNormalOrPreMessage,
470
532
  EntityNotAllowedMessage: () => EntityNotAllowedMessage,
471
533
  ExpectedMessage: () => ExpectedMessage,
@@ -478,6 +540,7 @@ __export(messages_exports, {
478
540
  OverwriteDefinitionsMessage: () => OverwriteDefinitionsMessage,
479
541
  OverwriteSpecialVariableMessage: () => OverwriteSpecialVariableMessage,
480
542
  ReachedRecursionLimitMessage: () => ReachedRecursionLimitMessage,
543
+ ShouldBeOnNewlineMessage: () => ShouldBeOnNewlineMessage,
481
544
  SlotUsedOutsideDefinitionMessage: () => SlotUsedOutsideDefinitionMessage,
482
545
  UnclosedInlineModifierMessage: () => UnclosedInlineModifierMessage,
483
546
  UndefinedVariableMessage: () => UndefinedVariableMessage,
@@ -544,7 +607,7 @@ var UnknownModifierMessage = class {
544
607
  code = 2;
545
608
  severity = 2 /* Error */;
546
609
  get info() {
547
- return `unknown modifier '${this.what}'; did you forget to escape it?`;
610
+ return `unknown modifier '${this.what}'`;
548
611
  }
549
612
  // get fixes(): readonly FixSuggestion[] {
550
613
  // let [start, end] = [this.start, this.end];
@@ -714,13 +777,13 @@ var NewBlockShouldBeOnNewlineMessage = class extends AddThingMessage {
714
777
  );
715
778
  }
716
779
  };
717
- var ContentShouldBeOnNewlineMessage = class extends AddThingMessage {
780
+ var ShouldBeOnNewlineMessage = class extends AddThingMessage {
718
781
  constructor(location) {
719
782
  super(
720
783
  3,
721
784
  1 /* Warning */,
722
785
  location,
723
- "the content should begin in a new line to avoid confusion"
786
+ "the following should begin in a new line to avoid confusion"
724
787
  );
725
788
  }
726
789
  };
@@ -805,6 +868,41 @@ var Document = class _Document {
805
868
  );
806
869
  return doc;
807
870
  }
871
+ /**
872
+ * Performs a depth-first walk of the node tree.
873
+ */
874
+ walk(callback) {
875
+ let nodes = this.root.content;
876
+ let node;
877
+ while (node = nodes.shift()) {
878
+ const result = callback(node);
879
+ if (result == "break") break;
880
+ if (result == "skip") continue;
881
+ if ("arguments" in node)
882
+ nodes.push(...node.arguments.flatMap((x) => x.content));
883
+ if ("content" in node && Array.isArray(node.content))
884
+ nodes.push(...node.content);
885
+ }
886
+ }
887
+ /**
888
+ * Gets all nodes that covers the given position, from outermost to innermost (essentially a path).
889
+ */
890
+ resolvePosition(pos) {
891
+ const result = [];
892
+ let nodes = this.root.content;
893
+ let node;
894
+ while (node = nodes.shift()) {
895
+ if (node.location.start <= pos && (node.location.actualEnd ?? node.location.end) >= pos) {
896
+ result.push(node);
897
+ nodes = [];
898
+ if ("arguments" in node)
899
+ nodes.push(...node.arguments.flatMap((x) => x.content));
900
+ if ("content" in node && Array.isArray(node.content))
901
+ nodes.push(...node.content);
902
+ }
903
+ }
904
+ return result;
905
+ }
808
906
  };
809
907
  var Configuration = class _Configuration {
810
908
  initializers = [];
@@ -927,6 +1025,7 @@ var Parser = class {
927
1025
  end: to ?? this.scanner.position()
928
1026
  };
929
1027
  }
1028
+ /* istanbul ignore next -- @preserve */
930
1029
  #defs(type) {
931
1030
  switch (type) {
932
1031
  case 5 /* SystemModifier */:
@@ -1061,7 +1160,7 @@ var Parser = class {
1061
1160
  SHOULD_BE_A_NEWLINE() {
1062
1161
  this.WHITESPACES();
1063
1162
  if (!this.scanner.accept("\n")) this.emit.message(
1064
- new ContentShouldBeOnNewlineMessage(this.#loc())
1163
+ new ShouldBeOnNewlineMessage(this.#loc())
1065
1164
  );
1066
1165
  }
1067
1166
  // TODO: this is awkward and doesn't emit messages in the most appropriate way
@@ -1151,14 +1250,28 @@ var Parser = class {
1151
1250
  if (grouped) this.SHOULD_BE_A_NEWLINE();
1152
1251
  const posContentStart = this.scanner.position();
1153
1252
  let posContentEnd = this.scanner.position();
1253
+ let paragraphEnd = void 0;
1154
1254
  let string = "";
1155
1255
  while (!this.scanner.isEOF()) {
1156
1256
  if (this.scanner.accept("\n")) {
1157
1257
  let white = "\n";
1158
- let char = "";
1258
+ let char;
1159
1259
  while ((char = this.scanner.acceptWhitespaceChar()) !== null)
1160
1260
  white += char;
1161
- if (grouped && this.scanner.accept(GROUP_END) || !grouped && this.scanner.accept("\n")) break;
1261
+ if (grouped && this.scanner.accept(GROUP_END)) {
1262
+ paragraphEnd = this.scanner.position();
1263
+ if (!this.scanner.isEOF()) {
1264
+ this.SHOULD_BE_A_NEWLINE();
1265
+ this.WARN_IF_MORE_NEWLINES_THAN(1);
1266
+ }
1267
+ break;
1268
+ }
1269
+ if (!grouped && this.scanner.accept("\n")) {
1270
+ paragraphEnd = this.scanner.position() - 1;
1271
+ if (!this.scanner.isEOF())
1272
+ this.WARN_IF_MORE_NEWLINES_THAN(0);
1273
+ break;
1274
+ }
1162
1275
  if (this.scanner.isEOF()) {
1163
1276
  if (grouped) this.emit.message(
1164
1277
  new ExpectedMessage(this.#loc(), GROUP_END)
@@ -1173,7 +1286,7 @@ var Parser = class {
1173
1286
  }
1174
1287
  const node = {
1175
1288
  type: 2 /* Preformatted */,
1176
- location: this.#locFrom(posStart),
1289
+ location: this.#locFrom(posStart, paragraphEnd ?? posContentEnd),
1177
1290
  content: {
1178
1291
  start: posContentStart,
1179
1292
  end: posContentEnd,
@@ -1190,6 +1303,10 @@ var Parser = class {
1190
1303
  this.WARN_IF_MORE_NEWLINES_THAN(1);
1191
1304
  while (!this.scanner.isEOF()) {
1192
1305
  if (this.scanner.accept(GROUP_END)) {
1306
+ if (!this.scanner.isEOF()) {
1307
+ this.SHOULD_BE_A_NEWLINE();
1308
+ this.WARN_IF_MORE_NEWLINES_THAN(1);
1309
+ }
1193
1310
  this.groupDepth--;
1194
1311
  return;
1195
1312
  }
@@ -1260,6 +1377,10 @@ var Parser = class {
1260
1377
  if (node.mod.delayContentExpansion) this.delayDepth++;
1261
1378
  let ok = true;
1262
1379
  if (isMarker) {
1380
+ if (!this.scanner.isEOF() && type == 7 /* BlockModifier */) {
1381
+ this.SHOULD_BE_A_NEWLINE();
1382
+ this.WARN_IF_MORE_NEWLINES_THAN(1);
1383
+ }
1263
1384
  if (type === 6 /* InlineModifier */) this.emit.addInlineNode(node);
1264
1385
  else this.emit.addBlockNode(node);
1265
1386
  } else if (type == 6 /* InlineModifier */) {
@@ -1306,6 +1427,10 @@ var Parser = class {
1306
1427
  return this.MODIFIER(6 /* InlineModifier */);
1307
1428
  if (this.scanner.peek(MODIFIER_SYSTEM_OPEN))
1308
1429
  return false;
1430
+ if (this.scanner.peek(MODIFIER_BLOCK_OPEN)) {
1431
+ this.SHOULD_BE_A_NEWLINE();
1432
+ return false;
1433
+ }
1309
1434
  const short = this.cxt.config.inlineShorthands.find((x) => this.scanner.accept(x.name));
1310
1435
  if (short) return this.SHORTHAND(6 /* InlineModifier */, short);
1311
1436
  if (this.scanner.accept("\\")) {
@@ -1434,9 +1559,9 @@ function parse(scanner, cxt) {
1434
1559
 
1435
1560
  // src/renderer.ts
1436
1561
  var RenderContext = class {
1437
- constructor(config2, parseContext, state) {
1562
+ constructor(config2, parsedDocument, state) {
1438
1563
  this.config = config2;
1439
- this.parseContext = parseContext;
1564
+ this.parsedDocument = parsedDocument;
1440
1565
  this.state = state;
1441
1566
  }
1442
1567
  renderEntity(node) {
@@ -1474,7 +1599,7 @@ var RenderConfiguration = class _RenderConfiguration {
1474
1599
  blockRenderers = /* @__PURE__ */ new Map();
1475
1600
  inlineRenderers = /* @__PURE__ */ new Map();
1476
1601
  render(doc, state) {
1477
- let cxt = new RenderContext(this, doc.context, state);
1602
+ let cxt = new RenderContext(this, doc, state);
1478
1603
  let results = doc.toStripped().root.content.map((x) => cxt.renderEntity(x)).filter((x) => x !== void 0);
1479
1604
  return this.postprocessor(results, cxt);
1480
1605
  }
@@ -1497,6 +1622,14 @@ var RenderConfiguration = class _RenderConfiguration {
1497
1622
  };
1498
1623
 
1499
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
+ });
1500
1633
  function checkArgumentLength(node, min, max = min) {
1501
1634
  if (min !== void 0 && node.arguments.length < min || max !== void 0 && node.arguments.length > max) {
1502
1635
  return [new ArgumentCountMismatchMessage({
@@ -1540,28 +1673,33 @@ function onlyPermitPlaintextParagraph(node) {
1540
1673
  }
1541
1674
  return result;
1542
1675
  }
1676
+ function checkContent(ents) {
1677
+ if (ents.length == 0) return "";
1678
+ else if (ents.length > 1) {
1679
+ let last = ents.at(-1).location;
1680
+ return [new MultipleBlocksNotPermittedMessage({
1681
+ source: last.source,
1682
+ start: ents[1].location.start,
1683
+ end: last.actualEnd ?? last.end
1684
+ })];
1685
+ }
1686
+ return check(ents[0]);
1687
+ }
1543
1688
  function check(ent) {
1544
1689
  if (ent.type == 7 /* BlockModifier */) {
1545
1690
  if (!ent.expansion) return [new EntityNotAllowedMessage(
1546
1691
  ent.location,
1547
1692
  "it does not expand to plain text"
1548
1693
  )];
1549
- if (ent.expansion.length == 0) return "";
1550
- else if (ent.expansion.length > 1) {
1551
- let last = ent.expansion.at(-1).location;
1552
- return [new MultipleBlocksNotPermittedMessage({
1553
- source: last.source,
1554
- start: ent.expansion[1].location.start,
1555
- end: last.actualEnd ?? last.end
1556
- })];
1557
- }
1558
- return check(ent.expansion[0]);
1694
+ return checkContent(ent.expansion);
1695
+ } else if (ent.type == 2 /* Preformatted */) {
1696
+ return ent.content.text;
1559
1697
  } else if (ent.type !== 1 /* Paragraph */) {
1560
1698
  return [new OnlySimpleParagraphsPermittedMessage(ent.location)];
1561
1699
  }
1562
1700
  return checkInline(ent.content);
1563
1701
  }
1564
- return check(node);
1702
+ return checkContent(node.content);
1565
1703
  }
1566
1704
  function onlyPermitSimpleParagraphs(node) {
1567
1705
  function check(nodes) {
@@ -1641,24 +1779,20 @@ function customModifier(type, name, signature, content) {
1641
1779
  args: node.state.args,
1642
1780
  slotContent: node.content
1643
1781
  });
1782
+ debug.trace(`pushed ${NodeType[type]} slot data for`, name);
1644
1783
  debug.trace(
1645
- `pushed ${NodeType[type]} slot data for`,
1646
- name,
1647
- signature.slotName == "" ? "(unnamed)" : `= ${signature.slotName}`
1784
+ `... slotName:`,
1785
+ signature.slotName === "" ? "<unnamed>" : signature.slotName === void 0 ? "<no slot>" : `'${signature.slotName}'`
1648
1786
  );
1787
+ debug.trace(`... args:`, "{" + [...node.state.args].map(([a, b]) => `${a} => ${b}`).join(", ") + "}");
1649
1788
  return [];
1650
1789
  };
1651
1790
  mod.afterProcessExpansion = (node, cxt) => {
1652
- if (!node.state?.ok || signature.slotName === void 0) return [];
1791
+ if (!node.state?.ok) return [];
1653
1792
  const store = cxt.get(builtins);
1654
1793
  const data = isInline ? store.inlineInstantiationData : store.blockInstantiationData;
1655
- const pop = data.pop();
1656
- assert(pop !== void 0);
1657
- debug.trace(
1658
- `popped ${NodeType[type]} slot data for`,
1659
- name,
1660
- signature.slotName == "" ? "(unnamed)" : `= ${signature.slotName}`
1661
- );
1794
+ data.pop();
1795
+ debug.trace(`popped ${NodeType[type]} slot data for`, name);
1662
1796
  return [];
1663
1797
  };
1664
1798
  return mod;
@@ -2011,6 +2145,17 @@ var DefineInlineShorthandMod = new SystemModifierDefinition(
2011
2145
  }
2012
2146
  );
2013
2147
 
2148
+ // src/builtin/misc.ts
2149
+ var RawBlockMod = new BlockModifierDefinition(
2150
+ "raw",
2151
+ 1 /* Preformatted */,
2152
+ {
2153
+ expand(node) {
2154
+ return node.content;
2155
+ }
2156
+ }
2157
+ );
2158
+
2014
2159
  // src/builtin/module.ts
2015
2160
  function getDefs(cxt) {
2016
2161
  const data = cxt.get(builtins);
@@ -2307,6 +2452,27 @@ function resolveId(id, cxt) {
2307
2452
  value = cxt.variables.get(id);
2308
2453
  return value;
2309
2454
  }
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 : [];
2468
+ }
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));
2472
+ var IfdefBlockMod = ifdefBlock("ifdef", true);
2473
+ var IfndefBlockMod = ifdefBlock("ifndef", false);
2474
+ var IfdefInlineMod = ifdefInline("ifdef", true);
2475
+ var IfndefInlineMod = ifdefInline("ifndef", false);
2310
2476
  var GetVarInlineMod = new InlineModifierDefinition(
2311
2477
  "$",
2312
2478
  2 /* None */,
@@ -2402,19 +2568,25 @@ builtin.blockModifiers.add(
2402
2568
  PreSlotBlockMod,
2403
2569
  InjectPreSlotBlockMod,
2404
2570
  ModuleMod,
2405
- UseBlockMod
2571
+ UseBlockMod,
2572
+ IfdefBlockMod,
2573
+ IfndefBlockMod,
2574
+ RawBlockMod
2406
2575
  );
2407
2576
  builtin.inlineModifiers.add(
2408
2577
  SlotInlineMod,
2409
2578
  PreSlotInlineMod,
2410
2579
  InjectPreSlotInlineMod,
2411
2580
  GetVarInlineMod,
2412
- PrintInlineMod
2581
+ PrintInlineMod,
2582
+ IfdefInlineMod,
2583
+ IfndefInlineMod
2413
2584
  );
2414
2585
  builtin.argumentInterpolators.add(GetVarInterpolator);
2415
2586
  var BuiltinConfiguration = Object.freeze(builtin);
2416
2587
 
2417
- // src/default/bullets.ts
2588
+ // src/default/bullets.tsx
2589
+ var import_jsx_runtime = require("minimal-jsx-runtime/jsx-runtime");
2418
2590
  var bulletItemBlock = new BlockModifierDefinition(
2419
2591
  "bullet-item",
2420
2592
  0 /* Normal */,
@@ -2445,20 +2617,22 @@ var subItemBlock = new BlockModifierDefinition(
2445
2617
  );
2446
2618
  var BulletBlocks = [bulletItemBlock, orderedListItemBlock, subItemBlock];
2447
2619
  var BulletBlockRenderersHTML = [
2448
- [bulletItemBlock, (node, cxt) => {
2449
- return `<li>${cxt.state.render(node.content, cxt)}</li>`;
2450
- }],
2451
- [subItemBlock, (node, cxt) => {
2452
- return `<div class='subitem'>${cxt.state.render(node.content, cxt)}</div>`;
2453
- }],
2454
- [orderedListItemBlock, (node, cxt) => {
2455
- if (node.state === void 0)
2456
- return cxt.state.invalidBlock(node, "bad format");
2457
- return `<li value='${node.state}'>${cxt.state.render(node.content, cxt)}</li>`;
2458
- }]
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
+ ]
2459
2632
  ];
2460
2633
 
2461
- // src/default/headings.ts
2634
+ // src/default/headings.tsx
2635
+ var import_jsx_runtime2 = require("minimal-jsx-runtime/jsx-runtime");
2462
2636
  var headings = Symbol();
2463
2637
  function initHeadings(cxt) {
2464
2638
  cxt.init(headings, {
@@ -2482,9 +2656,8 @@ var headingBlock = new BlockModifierDefinition(
2482
2656
  "heading",
2483
2657
  0 /* Normal */,
2484
2658
  {
2485
- delayContentExpansion: true,
2486
2659
  roleHint: "heading",
2487
- beforeParseContent(node, cxt) {
2660
+ prepareExpand(node, cxt) {
2488
2661
  let msgs = checkArguments(node, 0, 1);
2489
2662
  if (msgs) return msgs;
2490
2663
  msgs = onlyPermitSingleBlock(node);
@@ -2512,7 +2685,7 @@ var implicitHeadingBlock = new BlockModifierDefinition(
2512
2685
  2 /* None */,
2513
2686
  {
2514
2687
  roleHint: "heading",
2515
- beforeParseContent(node, cxt) {
2688
+ prepareExpand(node, cxt) {
2516
2689
  let msgs = checkArguments(node, 0, 1);
2517
2690
  if (msgs) return msgs;
2518
2691
  node.state = {
@@ -2539,9 +2712,8 @@ var numberedHeadingBlock = new BlockModifierDefinition(
2539
2712
  "numbered-heading",
2540
2713
  0 /* Normal */,
2541
2714
  {
2542
- delayContentExpansion: true,
2543
2715
  roleHint: "heading",
2544
- beforeParseContent(node, cxt) {
2716
+ prepareExpand(node, cxt) {
2545
2717
  let msgs = checkArguments(node, 1);
2546
2718
  if (msgs) return msgs;
2547
2719
  msgs = onlyPermitSingleBlock(node);
@@ -2566,37 +2738,103 @@ var HeadingBlocks = [headingBlock, implicitHeadingBlock, numberedHeadingBlock];
2566
2738
  var HeadingBlockRenderersHTML = [
2567
2739
  [headingBlock, (node, cxt) => {
2568
2740
  if (node.state !== void 0) {
2569
- let tag = "h" + node.state.level;
2570
- let para = node.content[0];
2571
- 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;
2572
2746
  }
2573
2747
  return cxt.state.invalidBlock(node, "Bad format");
2574
2748
  }],
2575
2749
  [implicitHeadingBlock, (node, cxt) => {
2576
2750
  if (node.state !== void 0) {
2577
- let tag = "h" + node.state.level;
2578
- 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;
2579
2755
  }
2580
2756
  return cxt.state.invalidBlock(node, "Bad format");
2581
2757
  }],
2582
2758
  [numberedHeadingBlock, (node, cxt) => {
2583
2759
  if (node.state !== void 0) {
2584
- let tag = "h" + node.state.level;
2585
- let para = node.content[0];
2586
- 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;
2587
2766
  }
2588
2767
  return cxt.state.invalidBlock(node, "Bad format");
2589
2768
  }]
2590
2769
  ];
2591
2770
 
2592
- // src/default/notes.ts
2771
+ // src/default/notes.tsx
2772
+ var import_jsx_runtime3 = require("minimal-jsx-runtime/jsx-runtime");
2593
2773
  var notes = Symbol();
2594
2774
  function initNotes(cxt) {
2595
2775
  cxt.init(notes, {
2596
2776
  systems: /* @__PURE__ */ new Map(),
2597
- definitions: []
2777
+ defaultSystem: {
2778
+ position: "preserve",
2779
+ autonumber: false
2780
+ },
2781
+ definitions: [],
2782
+ currentId: 0
2598
2783
  });
2599
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
+ );
2600
2838
  var noteMarkerInline = new InlineModifierDefinition(
2601
2839
  "note",
2602
2840
  2 /* None */,
@@ -2618,13 +2856,15 @@ var noteInline = new InlineModifierDefinition(
2618
2856
  prepareExpand(node) {
2619
2857
  let msgs = checkArguments(node, 0, 1);
2620
2858
  if (msgs) return msgs;
2621
- node.state = node.arguments.at(0)?.expansion ?? "";
2859
+ node.state = node.arguments.at(0)?.expansion?.trim() ?? "";
2622
2860
  return [];
2623
2861
  },
2624
2862
  afterProcessExpansion(node, cxt) {
2625
2863
  if (node.state !== void 0) {
2626
- cxt.get(notes).definitions.push({
2864
+ const defs = cxt.get(notes);
2865
+ defs.definitions.push({
2627
2866
  system: "",
2867
+ id: defs.currentId,
2628
2868
  name: node.state,
2629
2869
  location: node.location,
2630
2870
  content: [{
@@ -2637,6 +2877,7 @@ var noteInline = new InlineModifierDefinition(
2637
2877
  content: node.content
2638
2878
  }]
2639
2879
  });
2880
+ defs.currentId++;
2640
2881
  }
2641
2882
  return [];
2642
2883
  }
@@ -2647,58 +2888,73 @@ var noteBlock = new BlockModifierDefinition(
2647
2888
  0 /* Normal */,
2648
2889
  {
2649
2890
  roleHint: "quote",
2650
- prepareExpand(node) {
2651
- let msgs = checkArguments(node, 1);
2891
+ prepareExpand(node, cxt) {
2892
+ let msgs = checkArguments(node, 1, 2);
2652
2893
  if (msgs) return msgs;
2653
- node.state = node.arguments[0].expansion;
2654
- return [];
2655
- },
2656
- afterProcessExpansion(node, cxt) {
2657
- if (node.state !== void 0) {
2658
- let content = stripNode(...node.content);
2659
- debug.trace(`add note: system=<${""}> name=${node.state} @${node.location.start}`);
2660
- 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(`-->
2661
2899
  `, debugPrint.node(...content));
2662
- cxt.get(notes).definitions.push({
2663
- system: "",
2664
- name: node.state,
2665
- location: node.location,
2666
- content
2667
- });
2668
- }
2669
- 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;
2670
2911
  return [];
2671
2912
  }
2672
2913
  }
2673
2914
  );
2674
2915
  var NoteBlocks = [noteBlock];
2675
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
+ }
2676
2924
  var NoteInlineRenderersHTML = [
2677
2925
  [noteMarkerInline, (node, cxt) => {
2678
2926
  if (node.state === void 0)
2679
2927
  return cxt.state.invalidInline(node, "bad format");
2680
- const defs = cxt.parseContext.get(notes).definitions;
2928
+ const defs = cxt.parsedDocument.context.get(notes).definitions;
2681
2929
  const note = defs.findIndex((x) => (
2682
2930
  /*x.position >= node.start &&*/
2683
2931
  x.name == node.state
2684
2932
  ));
2685
- if (note < 0)
2686
- return `<sup class='note invalid'>Not found: ${node.state}</sup>`;
2687
- 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);
2688
2944
  }]
2689
2945
  ];
2690
2946
  var NotesFooterPlugin = (cxt) => {
2691
- let defs = cxt.parseContext.get(notes).definitions;
2692
- if (defs.length == 0) return void 0;
2693
- return `<hr/>
2694
- <section class='notes'>
2695
- ${defs.map((x, i) => `<section class='note' id='note-id-${i}'>
2696
- <div class='note-name'><p><a href='#notemarker-id-${i}'>${x.name}</a></p></div>
2697
- <div class='note-content'>${cxt.state.render(x.content, cxt)}</div></section>`).join("\n")}
2698
- </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
+ ];
2699
2954
  };
2700
2955
 
2701
- // src/default/code.ts
2956
+ // src/default/code.tsx
2957
+ var import_jsx_runtime4 = require("minimal-jsx-runtime/jsx-runtime");
2702
2958
  var CodeBlock = new BlockModifierDefinition(
2703
2959
  "code",
2704
2960
  1 /* Preformatted */,
@@ -2709,14 +2965,17 @@ var CodeInline = new InlineModifierDefinition(
2709
2965
  1 /* Preformatted */,
2710
2966
  { roleHint: "code" }
2711
2967
  );
2712
- var CodeBlockRendererHTML = [CodeBlock, (node, cxt) => {
2713
- return `<pre><code>${cxt.state.render(node.content, cxt)}</code></pre>`;
2714
- }];
2715
- var CodeInlineRendererHTML = [CodeInline, (node, cxt) => {
2716
- return `<span><code>${cxt.state.render(node.content, cxt)}</code></span>`;
2717
- }];
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
+ ];
2718
2976
 
2719
- // src/default/quotes.ts
2977
+ // src/default/quotes.tsx
2978
+ var import_jsx_runtime5 = require("minimal-jsx-runtime/jsx-runtime");
2720
2979
  var quoteBlock = new BlockModifierDefinition(
2721
2980
  "quote",
2722
2981
  0 /* Normal */,
@@ -2727,6 +2986,16 @@ var epitaphBlock = new BlockModifierDefinition(
2727
2986
  0 /* Normal */,
2728
2987
  { roleHint: "quote" }
2729
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
+ );
2730
2999
  var attributionBlock = new BlockModifierDefinition(
2731
3000
  "by",
2732
3001
  0 /* Normal */,
@@ -2742,23 +3011,34 @@ var attributionBlock = new BlockModifierDefinition(
2742
3011
  }
2743
3012
  }
2744
3013
  );
2745
- var QuoteBlocks = [quoteBlock, epitaphBlock, attributionBlock];
3014
+ var QuoteBlocks = [quoteBlock, epitaphBlock, calloutBlock, detailBlock, attributionBlock];
2746
3015
  var QuoteBlockRenderersHTML = [
2747
- [quoteBlock, (node, cxt) => {
2748
- return `<blockquote>${cxt.state.render(node.content, cxt)}</blockquote>`;
2749
- }],
2750
- [epitaphBlock, (node, cxt) => {
2751
- return `<blockquote class='epitaph'>${cxt.state.render(node.content, cxt)}</blockquote>`;
2752
- }],
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
+ ],
2753
3032
  [attributionBlock, (node, cxt) => {
2754
3033
  if (!node.state)
2755
3034
  return cxt.state.invalidBlock(node, "bad format");
2756
3035
  let para = node.content[0];
2757
- 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) });
2758
3037
  }]
2759
3038
  ];
2760
3039
 
2761
- // src/default/inline-styles.ts
3040
+ // src/default/inline-styles.tsx
3041
+ var import_jsx_runtime6 = require("minimal-jsx-runtime/jsx-runtime");
2762
3042
  var emphasisInline = new InlineModifierDefinition(
2763
3043
  "emphasis",
2764
3044
  0 /* Normal */,
@@ -2779,23 +3059,37 @@ var commentaryInline = new InlineModifierDefinition(
2779
3059
  0 /* Normal */,
2780
3060
  { roleHint: "commentary" }
2781
3061
  );
2782
- 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];
2783
3068
  var InlineStyleRenderersHTML = [
2784
- [emphasisInline, (node, cxt) => {
2785
- return `<em>${cxt.state.render(node.content, cxt)}</em>`;
2786
- }],
2787
- [keywordInline, (node, cxt) => {
2788
- return `<b>${cxt.state.render(node.content, cxt)}</b>`;
2789
- }],
2790
- [highlightInline, (node, cxt) => {
2791
- return `<mark>${cxt.state.render(node.content, cxt)}</mark>`;
2792
- }],
2793
- [commentaryInline, (node, cxt) => {
2794
- return `<span class='commentary'>${cxt.state.render(node.content, cxt)}</span>`;
2795
- }]
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
+ ]
2796
3089
  ];
2797
3090
 
2798
- // src/default/misc.ts
3091
+ // src/default/misc.tsx
3092
+ var import_jsx_runtime7 = require("minimal-jsx-runtime/jsx-runtime");
2799
3093
  var rubyInline = new InlineModifierDefinition(
2800
3094
  "ruby",
2801
3095
  0 /* Normal */,
@@ -2871,43 +3165,46 @@ var imageBlock = new BlockModifierDefinition(
2871
3165
  var MiscInlines = [rubyInline, linkInline];
2872
3166
  var MiscBlocks = [styleBlock, breakBlock, linkBlock, imageBlock];
2873
3167
  var MiscInlineRenderersHTML = [
2874
- [rubyInline, (node, cxt) => {
2875
- if (node.state === void 0)
2876
- return cxt.state.invalidInline(node, "bad format");
2877
- return `<ruby>${cxt.state.render(node.content, cxt)}<rt>${node.state}</rt></ruby>`;
2878
- }],
2879
- [linkInline, (node, cxt) => {
2880
- if (node.state === void 0)
2881
- return cxt.state.invalidInline(node, "bad format");
2882
- return `<a href="${encodeURI(node.state)}">${cxt.state.render(node.content, cxt)}</a>`;
2883
- }]
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
+ ]
2884
3179
  ];
2885
3180
  var MiscBlockRenderersHTML = [
2886
- [styleBlock, (node, cxt) => {
2887
- if (node.state === void 0)
2888
- return cxt.state.invalidBlock(node, "bad format");
2889
- return `<div class="${node.state}" style="display:contents">${cxt.state.render(node.content, cxt)}</div>`;
2890
- }],
2891
- [breakBlock, () => {
2892
- return `<hr>`;
2893
- }],
2894
- [linkBlock, (node, cxt) => {
2895
- if (node.state === void 0)
2896
- return cxt.state.invalidBlock(node, "bad format");
2897
- return `<a href="${encodeURI(node.state)}">${cxt.state.render(node.content, cxt)}</a>`;
2898
- }],
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
+ ],
2899
3195
  [imageBlock, (node, cxt) => {
2900
- let transformed;
2901
3196
  if (node.state === void 0)
2902
3197
  return cxt.state.invalidBlock(node, "bad format");
3198
+ let transformed;
2903
3199
  try {
2904
3200
  transformed = cxt.config.options.transformAsset(node.state);
2905
3201
  } catch {
2906
3202
  return cxt.state.invalidBlock(node, "unable to transform asset");
2907
3203
  }
2908
- const img = transformed ? `<img src="${transformed}" data-original-src="${node.state}"/>` : `<img src="${node.state}"/>`;
2909
- const para = node.content.length == 0 ? "" : "\n<figcaption>" + cxt.state.render(node.content[0].content, cxt) + "</figcaption>";
2910
- 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
+ ] });
2911
3208
  }]
2912
3209
  ];
2913
3210
 
@@ -2925,6 +3222,7 @@ function createWrapper(name, varname) {
2925
3222
  if (previous)
2926
3223
  msgs = [new OverwriteSpecialVariableMessage(node.head, varname, previous)];
2927
3224
  cxt.variables.set(varname, result);
3225
+ debug.trace(varname, "->", result);
2928
3226
  return msgs ?? [];
2929
3227
  }
2930
3228
  });
@@ -2961,34 +3259,45 @@ config.inlineModifiers.add(
2961
3259
  ...NoteInlines
2962
3260
  );
2963
3261
  config.systemModifiers.add(
2964
- ...VarWrappers
3262
+ ...VarWrappers,
3263
+ ...NoteSystems
2965
3264
  );
2966
3265
  var DefaultConfiguration = Object.freeze(config);
2967
3266
 
2968
- // src/default/html-renderer.ts
3267
+ // src/default/html-renderer.tsx
3268
+ var import_jsx_runtime8 = require("minimal-jsx-runtime/jsx-runtime");
2969
3269
  var HTMLRenderState = class {
2970
3270
  title = "";
2971
3271
  stylesheet = "";
2972
3272
  // FIXME: very unsafe!
2973
3273
  cssVariables = /* @__PURE__ */ new Map();
2974
- // https://stackoverflow.com/questions/7381974
2975
- escape(content) {
2976
- return content.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;").replaceAll("\n", "<br/>");
2977
- }
2978
3274
  invalidBlock(node, msg) {
2979
3275
  let name = NodeType[node.type];
2980
3276
  if (node.type === 7 /* BlockModifier */)
2981
3277
  name += ` (${node.mod.name})`;
2982
- 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
+ ] });
2983
3285
  }
2984
3286
  invalidInline(node, msg) {
2985
3287
  let name = NodeType[node.type];
2986
3288
  if (node.type === 6 /* InlineModifier */)
2987
3289
  name += ` (${node.mod.name})`;
2988
- 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
+ ] });
2989
3296
  }
2990
3297
  render(elems, cxt) {
2991
- 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;
2992
3301
  }
2993
3302
  };
2994
3303
  var htmlConfig = new RenderConfiguration(
@@ -2996,7 +3305,8 @@ var htmlConfig = new RenderConfiguration(
2996
3305
  headPlugins: [],
2997
3306
  headerPlugins: [],
2998
3307
  footerPlugins: [NotesFooterPlugin],
2999
- transformAsset: (x) => void 0
3308
+ postprocessPlugins: [],
3309
+ transformAsset: () => void 0
3000
3310
  // postprocessPlugins: [],
3001
3311
  },
3002
3312
  (results, cxt) => {
@@ -3004,35 +3314,41 @@ var htmlConfig = new RenderConfiguration(
3004
3314
  /var\(--(.*?)\)/g,
3005
3315
  (m, c) => cxt.state.cssVariables.get(c) ?? m
3006
3316
  );
3007
- return `
3008
- <!DOCTYPE html>
3009
- <html>
3010
- <head>
3011
- <meta charset="UTF-8">
3012
- ${cxt.config.options.headPlugins.map((x) => x(cxt)).filter((x) => x !== void 0).join("\n")}
3013
- <title>${cxt.state.escape(cxt.state.title)}</title>
3014
- <style>${styles}</style>
3015
- </head>
3016
- <body>
3017
- <section class="article-container">
3018
- <section class="article-body">
3019
- ${cxt.config.options.headerPlugins.map((x) => x(cxt)).filter((x) => x !== void 0).join("\n")}
3020
- ${results.join("\n")}
3021
- ${cxt.config.options.footerPlugins.map((x) => x(cxt)).filter((x) => x !== void 0).join("\n")}
3022
- </section>
3023
- </section>
3024
- </body>
3025
- </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;
3026
3334
  }
3027
3335
  );
3028
- 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) });
3029
3337
  htmlConfig.textRenderer = (node, cxt) => {
3030
3338
  switch (node.type) {
3031
3339
  case 2 /* Preformatted */:
3032
- return cxt.state.escape(node.content.text);
3340
+ return new Text(node.content.text);
3033
3341
  case 3 /* Text */:
3034
3342
  case 4 /* Escaped */:
3035
- 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;
3036
3352
  default:
3037
3353
  return debug.never(node);
3038
3354
  }
@@ -3048,8 +3364,8 @@ htmlConfig.addBlockRenderer(
3048
3364
  ...BulletBlockRenderersHTML,
3049
3365
  CodeBlockRendererHTML,
3050
3366
  ...QuoteBlockRenderersHTML,
3051
- ...MiscBlockRenderersHTML
3052
- // TODO: notes
3367
+ ...MiscBlockRenderersHTML,
3368
+ ...NoteBlockRenderersHTML
3053
3369
  );
3054
3370
  htmlConfig.addInlineRenderer(
3055
3371
  CodeInlineRendererHTML,
@@ -3060,6 +3376,7 @@ htmlConfig.addInlineRenderer(
3060
3376
  var HTMLRenderConfiguration = htmlConfig;
3061
3377
 
3062
3378
  // src/index.ts
3379
+ var emmmVersion = "0.0.6";
3063
3380
  function setDebugLevel(level) {
3064
3381
  debug.level = level;
3065
3382
  }
@@ -3082,8 +3399,11 @@ function setDebugLevel(level) {
3082
3399
  RenderConfiguration,
3083
3400
  RenderContext,
3084
3401
  SimpleScanner,
3402
+ StringSource,
3085
3403
  SystemModifierDefinition,
3086
3404
  debugPrint,
3405
+ emmmVersion,
3406
+ helper,
3087
3407
  messages,
3088
3408
  parse,
3089
3409
  setDebugLevel