mnater / Hyphenopoly

Hyphenation for node and Polyfill for client-side hyphenation.
http://mnater.github.io/Hyphenopoly/
MIT License
689 stars 45 forks source link

Remove added hyphenation #205

Closed Evengard closed 11 months ago

Evengard commented 1 year ago

Is there a way to trigger a removal of added by this script hyphenation? I'm using it for languages unsupported by browser hyphenation, and I have a toggle which creates a "hyphens: none !important" style for the selector. When using browser hyphenation, it just works, hyphens gets removed. When using Hyphenopoly (with a language unsupported by Edge, eg we fall back to Hyphenopoly in this case), seems like the hyphenation sticks (at least, on Edge). Is there smth I can do with that?

mnater commented 1 year ago

Hyphenopoly.js doesn't "see" the CSS-Styles. Try Hyphenopoly.unhyphenate()

Evengard commented 1 year ago

Thanks, seems to be exactly what I was searching for.

mnater commented 1 year ago

👍 I‘ll close this issue for now. Feel free to reopen if necessary.

Evengard commented 1 year ago

Unfortunately, I stumbled upon a bug with unhyphenate. When I have an element such as:

<div class="container">
first long text
<br />
second long text
<br />
third long text
</div>

Only first long text gets unhyphenated, while second long text and third long text won't.

Evengard commented 1 year ago

I've managed to implement a fast and dirty hotfix:

Replace that:

https://github.com/mnater/Hyphenopoly/blob/7ee7bbb04a6bdc3f6e7805de458436aa2fb18734/Hyphenopoly.js#L660-L665

with that:

H.res.els.list.forEach((els) => {
els.forEach((elo) => {
  elo.element.childNodes.forEach((n) => {
      try {
        n.data = n.data.replace(RegExp(C[elo.selector].hyphen, "g"), "");
      } catch {}
    })
  });
});
Evengard commented 1 year ago

For some reason, can't seem to be able to reopen the issue...

mnater commented 1 year ago

Thanks for pointing out the problem. I think in this case we could savely use innerHTML:

H.res.els.list.forEach((els) => {
    els.forEach((elo) => {
        elo.element.innerHTML = elo.element.innerHTML.replace(RegExp(C[elo.selector].hyphen, "g"), "");
    });
});