34
34
import dev .ebullient .convert .tools .dnd5e .qute .QuteSubclass ;
35
35
36
36
public class Json2QuteClass extends Json2QuteCommon {
37
+ final static Pattern footnotePattern = Pattern .compile ("\\ ^\\ [([^\\ ]]+)\\ ]" );
37
38
38
39
final static Map <String , ClassFeature > keyToClassFeature = new HashMap <>();
39
40
@@ -358,6 +359,7 @@ Multiclassing buildMulticlassing() {
358
359
List <String > buildProgressionTable (List <ClassFeature > features , JsonNode sourceNode , ClassFields field ) {
359
360
List <String > headings = new ArrayList <>();
360
361
List <String > spellCasting = new ArrayList <>();
362
+ List <String > footnotes = new ArrayList <>();
361
363
362
364
Map <Integer , LevelProgression > levels = new HashMap <>();
363
365
for (int i = 1 ; i < 21 ; i ++) {
@@ -375,7 +377,7 @@ List<String> buildProgressionTable(List<ClassFeature> features, JsonNode sourceN
375
377
if (ClassFields .rows .existsIn (tableNode )) {
376
378
// headings for other/middle columns
377
379
for (JsonNode label : ClassFields .colLabels .iterateArrayFrom (tableNode )) {
378
- headings .add (markdownLinkToHtml ( replaceText ( label ) ));
380
+ headings .add (stripTableMarkdown ( label , footnotes ));
379
381
}
380
382
381
383
// values for other/middle columns
@@ -403,12 +405,26 @@ List<String> buildProgressionTable(List<ClassFeature> features, JsonNode sourceN
403
405
}
404
406
}
405
407
406
- return progressionAsTable (headings , spellCasting , levels );
408
+ return progressionAsTable (headings , spellCasting , levels , footnotes );
409
+ }
410
+
411
+ private String stripTableMarkdown (JsonNode label , List <String > footnotes ) {
412
+ String text = markdownLinkToHtml (replaceText (label ));
413
+
414
+ // Extract footnotes and replace with markers
415
+ Matcher matcher = footnotePattern .matcher (text );
416
+
417
+ return matcher .replaceAll (matchResult -> {
418
+ String footnoteContent = matchResult .group (1 );
419
+ footnotes .add (footnoteContent );
420
+ return " <sup>‡" + footnotes .size () + "</sup>" ;
421
+ });
407
422
}
408
423
409
424
List <String > progressionAsTable (List <String > headings ,
410
425
List <String > spellCasting ,
411
- Map <Integer , LevelProgression > levels ) {
426
+ Map <Integer , LevelProgression > levels ,
427
+ List <String > footnotes ) {
412
428
List <String > text = new ArrayList <>();
413
429
text .add ("[!tldr] Class and Feature Progression" );
414
430
text .add ("" );
@@ -455,6 +471,13 @@ List<String> progressionAsTable(List<String> headings,
455
471
}
456
472
457
473
text .add ("</tbody></table>" );
474
+ if (!footnotes .isEmpty ()) {
475
+ text .add ("<section class=\" footnotes\" ><ul>" );
476
+ for (var i = 0 ; i < footnotes .size (); i ++) {
477
+ text .add ("<li>‡" + (i + 1 ) + ": " + footnotes .get (i ) + "</li>" );
478
+ }
479
+ text .add ("</ul></section>" );
480
+ }
458
481
459
482
// Move everything into a callout box
460
483
text .replaceAll (s -> "> " + s );
0 commit comments