mzte-nv: tsn-actions: don't try typst math toggle with multiple lines

This commit is contained in:
LordMZTE 2024-11-01 13:07:40 +01:00
parent 65ff33b213
commit 7ab1832bd8
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6

View file

@ -66,20 +66,19 @@ class PTSNActions implements IPlugin {
}); });
}].toTable(), }].toTable(),
java: { java: {
hex_integer_literal: Table.create( hex_integer_literal: Table.create([
[ Table.create(
Table.create( [(node) -> MZTENv.tsn_actions.intToDec(this.tsna_helpers[untyped "node_text"](node))],
[(node) -> MZTENv.tsn_actions.intToDec(this.tsna_helpers[untyped "node_text"](node))], {
{ name: "Convert to Decimal",
name: "Convert to Decimal", }
} )
) ]),
] decimal_integer_literal: Table.create([
), Table.create([(node) -> MZTENv.tsn_actions.intToHex(this.tsna_helpers[untyped "node_text"](node))], {
decimal_integer_literal: Table.create([Table.create([(node) -> name: "Convert to Hexadecimal",
MZTENv.tsn_actions.intToHex(this.tsna_helpers[untyped "node_text"](node))], { })
name: "Convert to Hexadecimal", ]),
})]),
}, },
c: { c: {
number_literal: toggle_int_action, number_literal: toggle_int_action,
@ -109,14 +108,16 @@ class PTSNActions implements IPlugin {
} }
private function toggleTypstMath(node:Dynamic):String { private function toggleTypstMath(node:Dynamic):String {
final text:String = this.tsna_helpers[untyped "node_text"](node); final nodetext = this.tsna_helpers[untyped "node_text"](node);
final text = Std.isOfType(nodetext, AnyTable) ? return nodetext : (cast nodetext : String);
final sub1 = text.gsub("^%$%s+(.*)%s+%$$", "%$%1%$"); var sub = text.gsub("^%$%s+(.*)%s+%$$", "%$%1%$");
if (sub1 == text) { if (sub == text) {
// This assignment is necessary because haxe doesn't realize that gsub is a multireturn. // haxe doesn't realize that gsub is a multireturn.
// TODO: open issue about this // TODO: open issue about this
final sub2 = text.gsub("^%$", "%$ ").gsub("%$$", " %$"); sub = text.gsub("^%$", "%$ ").gsub("%$$", " %$");
return sub2; }
} else return sub1;
return sub;
} }
} }