Skip to content

Commit b8e2dde

Browse files
committed
🚸 Add some workarounds and post-processing for YAML statblocks
- Change tests to be more specific about which asterisks are disallowed - Add some workarounds for specific statblocks
1 parent 32d09e2 commit b8e2dde

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/main/java/dev/ebullient/convert/qute/QuteUtil.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,14 @@ default String render() {
105105

106106
/** Return the object rendered using its template with {@code asYamlStatblock} set to true. */
107107
default String renderAsYamlStatblock() {
108-
// Manually remove the dice roller syntax - the yaml statblocks handle dice roller syntax differently. At this
109-
// point, the parsing has already finished, so we can't use parseState to stop them from being added in the first
110-
// place. So all we can do is post-process to remove them again.
111-
return render(true).replaceAll("`dice: [^`]+` \\(`([^`]+)`\\)", "$1");
108+
return render(true)
109+
// Manually remove the dice roller syntax - the yaml statblocks handle dice roller syntax differently. At this
110+
// point, the parsing has already finished, so we can't use parseState to stop them from being added in the
111+
// first place. So all we can do is post-process to remove them again.
112+
.replaceAll("`dice: [^`]+` \\(`([^`]+)`\\)", "$1")
113+
// This usage is usually a footnote. With the Markdown rendering the asterisk is unnecessary, so just don't
114+
// add the asterisk, so this doesn't get treated as Markdown formatting.
115+
.replaceAll("\\* \\^\\[", " ^[");
112116
}
113117
}
114118
}

src/main/java/dev/ebullient/convert/tools/pf2e/qute/QuteCreature.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@ public String formattedAmount() {
362362

363363
@Override
364364
public String toString() {
365+
if (notes.size() == 1 && notes.get(0).equals("*")) {
366+
// Workaround for specific statblocks which use "*" to tag particular spells. Use a carat instead so it doesn't
367+
// get Markdown formatted.
368+
return join(" ", (spellRef == null ? name : spellRef.toString()) + "^", formattedAmount());
369+
}
365370
return join(" ", spellRef == null ? name : spellRef, formattedAmount(), formattedNotes());
366371
}
367372
}

src/test/java/dev/ebullient/convert/TestUtils.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public class TestUtils {
4848

4949
static String GENERATED_DOCS = PROJECT_PATH.resolve("docs/templates").normalize().toAbsolutePath().toString();
5050

51+
private static final Pattern ASTERISK_START_PROP_PAT = Pattern.compile(":\\s*\\*");
52+
private static final Pattern SINGLE_ASTERISK_PAT = Pattern.compile("[^*]\\*[^*]");
53+
5154
// Obnoxious regular expression because markdown links are complicated:
5255
// Matches: [link text](vaultPath "title")
5356
// - link text is optional, and may contain parentheses. Use a negative lookahead for ](
@@ -374,7 +377,14 @@ public static List<String> yamlStatblockChecker(Path p, List<String> content) {
374377
yaml = false; // end yaml block
375378
} else if (yaml) {
376379
statblock.add(l);
377-
if (l.contains("*")) {
380+
// Asterisks at the start of values indicate aliases in YAML. If we find this, it's probably not intentional.
381+
if (ASTERISK_START_PROP_PAT.matcher(l).matches()) {
382+
errors.add(String.format("Found '*' property alias in %s: %s", p, l));
383+
}
384+
// Sometimes statblock text uses asterisks. Double asterisks are usually intentional markdown, but single
385+
// asterisks are suspect and may be asterisks which have snuck in from the data source, and won't be rendered
386+
// literallywill be rendered.
387+
if (SINGLE_ASTERISK_PAT.matcher(l).matches()) {
378388
errors.add(String.format("Found '*' in %s: %s", p, l));
379389
}
380390
if (l.contains("\"desc\": \"\"")) {

0 commit comments

Comments
 (0)