naturalcrit / homebrewery

Create authentic looking D&D homebrews using only markdown
https://homebrewery.naturalcrit.com
MIT License
1.05k stars 319 forks source link

Math symbols in variable names should not allow variable assignment #3377

Open calculuschild opened 4 months ago

calculuschild commented 4 months ago

A variable with a name like this [ref-01] contains a math symbol (-) and so is actually treated as two variable names ref and 01.

However, math is only checked during variable expression when a $ prefix is attached. This can lead to weird shenanigans:

$[label-with+math]: url  // Assign variable

[label-with+math]     // Output as link

$[label-with+math]   // Fails because math is attempted

This will assign url to label-with+math and even express it as a link. However $[label-with+math] will not be able to access that variable because math is attempted first. For consistency, checking for math should be done in the variable assignment step as well.

Consideration

One thing to consider, is if we want to allow hyphenated var names, which has already come up naturally a few times. We could potentially restrict math to require spaces between operators which may be less confusing to users:

$[hyphenated-name] vs $[math - expression]

Test Cases

@ericscheid tested a range of other edge cases, some of which show related symptoms: image

dbolack-ab commented 3 months ago

I prefer no hyphens in variables.

ericscheid commented 3 months ago

Reflinks accept hyphens .. they are human readable labels that appear in the text. They could be all manner of things (e.g. [D&E Mag '94] or [A+B], [Schuster et al, 93], [PHB p.23-28]).

calculuschild commented 3 months ago

@ericscheid Does it seem reasonable to enforce spaces between math symbols then to allow for math symbols in variable names? Or do you foresee any new edge cases that would cause? Your examples above have both spaces and math symbols, but never spaces between math symbols so those would all be interpreted as valid variable names.

[A+B + PHB p.23-28 / Shuster et al, 93] would be a valid math expression assuming numbers were assigned to each of those.

ericscheid commented 3 months ago

Seems a reasonable hack, I don't see any other way with how we've set up [expressions].