Text formatting. Single letters at the end of a line

In the text on the page, I see single letters at the end of the text line, for example:

Lorem ipsum dolor a
dolor amot

which in Polish is a mistake.

it should be correctly:

Lorem ipsum dolor
a dolor amot

How could he have eliminated this other than by inserting   after each single letter?

It currently uses JavaScript

  orphans: () => {
    const paragraphs = document.querySelectorAll('.content p');
    const list = document.querySelectorAll('.content li');

    const elements = [...paragraphs, ...list];
    if (elements) {
      [...elements].forEach(e => {
        if (e) {
          let content = e.innerHTML.replace(/(\s)([\S])[\s]+/g, '$1$2 ');

          e.innerHTML = '';
          e.insertAdjacentHTML('afterbegin', content);
        }
      });
    }
  },

but it should probably be done once on the backend side?

Maybe @bricebou could jump in here and help :thinking: He’s got a Better typography plugin (discussed here)

1 Like

Hi,

I’m not sure the PHP-Typography library – which is used in the Better Typography Grav plugin – deals with this case… But I kind of remember that the library can be extended with new locales and rules.

2 Likes

Thx! Better Typography Grav plugin have a class to handle single character words.
(I don’t know why, but it installed without the vendor directory).

It would be ideal if the plugin would allow you to create a list of words that should not appear at the end of the line (in Polish these are some two or even three letter words).

For example: [‘na’, ‘że’, ‘się’, ‘lub’]

Hi @q3d !

This should be fixed with the 0.1.1 version : Release 0.1.1 · bricebou/grav-plugin-better-typography · GitHub

I’m not using Grav for any project at this time so I don’t know if I could work on that ; but if you have any idea on how to implement this, feel free to write a PR :slight_smile: