ronkok / Hurmet

Rich text editor on the web, featuring live calculations.
https://hurmet.org/
146 stars 1 forks source link

JS error if navigator.language does not contain a hyphen #39

Closed oliver closed 1 week ago

oliver commented 1 week ago

After loading https://hurmet.org/sample , I cannot use any calculation cells: I can create a new calculation cell, but when entering e.g. 1+4=? and pressing Enter the box just remains.

In the JS console I see this error when loading the page:

Uncaught TypeError: parts is null
    <anonymous> https://hurmet.org/prosemirror.min.js:3
prosemirror.min.js:3:94255
    <anonym> https://hurmet.org/prosemirror.min.js:3

This is the code that is shown in debugger for this code location:

const userLanguage=parts[1];

In my browser the preferred language for websites is set to de (i.e. a single word without hyphens, rather than something like de-de). Not sure why this is set (maybe I fiddled with the settings some day), but it's doable in the normal Firefox settings dialog.

As result, the navigator.language JS value is set to de, and apparently this breaks the regex for extracting browser language from userLanguageTag, in https://github.com/ronkok/Hurmet/blob/8280bb855e0f01593f0c21ed8292dca0484d4de1/src/index.js#L90 .

When changing the preferred language in Firefox settings to de-de, Hurmet loads correctly, and calculation cells work (and actually the calculation cells look much nicer now, rather than just showing text content).

FTR: I found Hurmet via https://lobste.rs/s/glk9rk/hurmet_notebook_for_calculations .

ronkok commented 1 week ago

@oliver Thank you for raising this issue. I've fixed the regular expression and uploaded the patch. You'll get the improved version the next time you navigate to Hurmet.org after being away for 4 hours.

Keep me posted on how Hurmet works for you. I believe that the internationalization aspects of Hurmet are where its testing is weakest and I would like to make it more robust.

By the way, for a number's thousands separator, do you prefer dots or spaces?

oliver commented 1 week ago

Thanks for the fast solution; it works well for me now!

To be honest, I'm probably not the core target audience for Hurmet :-) . I'm not a mechanical engineer but a software developer and therefore rather use Jupyter or Marimo. Still, it's fun to play with Hurmet and see what it can do (and experiment with math on the way).

Regarding thousands separators, I think spaces look prettier and less obtrusive; but for scientific results maybe explicit dots/commas would reduce reading errors?

ronkok commented 1 week ago

I'm glad it works for you now. I plan to change the default thousands separator from dots to commas. I'll probably have it up later today.