Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Text formatting. Single letters at the end of a line

Solved by Karmalakas View solution

Started by Norbert 4 years ago · 5 replies · 498 views
4 years ago

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

TXT
Lorem ipsum dolor a
dolor amot

which in Polish is a mistake.

it should be correctly:

TXT
Lorem ipsum dolor
a dolor amot

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

It currently uses JavaScript

JS
  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?

4 years ago

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
4 years ago

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).

4 years ago

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']

4 years ago

Hi @q3d !

@q3d:
I don’t know why, but it installed without the vendor directory

This should be fixed with the 0.1.1 version : https://github.com/bricebou/grav-plugin-better-typography/releases/tag/v0.1.1

@q3d:
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

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 🙂

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 82 12 hours ago
General · by pamtbaau, 17 hours ago
1 55 16 hours ago
General · by Andy Miller, 1 day ago
0 45 1 day ago
General · by Marcel, 12 months ago
6 348 5 days ago
General · by Duc , 5 days ago
3 43 5 days ago