Prevent Widow Words

Add a prevent-widows attribute on any HTML tag and the last space in every text node inside it will be replaced with a  .

src/templates/example.html
<extends src="src/layouts/main.html">
  <block name="template">
    <div prevent-widows>
      <p>The quick brown fox jumped over the lazy dog.</p>
    </div>
  </block>
</extends>

That will output:

<div>
  <p>The quick brown fox jumped over the lazy&nbsp;dog.</p>
</div>

Enable globally

Enable prevent-widows globally by adding it to your Layout's <body> tag.

src/layouts/example.html
<!DOCTYPE html>
<html>
  <head></head>
  <body prevent-widows>
    <block name="template"></block>
  </body>
</html>

API

app.js
const {preventWidows} = require('@maizzle/framework')

const html = await preventWidows('html string')

Copyright © 2022 Maizzle Edit this page on GitHub