this post was submitted on 02 Apr 2026
19 points (100.0% liked)

Programming

26351 readers
284 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] Kissaki@programming.dev 3 points 1 day ago* (last edited 1 day ago)

How does Pretext work?

  1. Segment the text; Normalize whitespace, apply Unicode line-break rules, and split the string into measurable units using the browser's own text segmentation.
  2. Measure with Canvas; Feed each segment through Canvas measureText() to get real glyph advance widths from the font engine. Results are cached.
  3. Pretext.js uses pure arithmetic; Given a container width, compute line breaks by summing segment widths. Multiply line count by line-height. Return height. No DOM, ever.

Unfortunately, that doesn't really explain the final integration. And it seems I misunderstood/-assumed at first.

Looking at the example at the top right, it renders numerous div elements?

So, presumably, you lose text wrap behavior and clean markup like <p> for a paragraph? I also can't select text from it in a normal or consistent way.

This example isn't very convincing either.

Seems like a cool visual gimmick more than practically useful and accessible for primary content.