{"_id":"posthtml-widows","_rev":"3-003b985fd18e9b1e7fbecfa1498dce92","name":"posthtml-widows","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"posthtml-widows","version":"1.0.0","keywords":["widows","string","typography","paragraph","html","text","email","copywriting","posthtml","posthtml-plugin"],"author":{"url":"https://github.com/cossssmin","name":"PostHTML"},"license":"MIT","_id":"posthtml-widows@1.0.0","maintainers":[{"name":"cossssmin","email":"hellocosmin@gmail.com"}],"homepage":"https://github.com/posthtml/posthtml-widows","bugs":{"url":"https://github.com/posthtml/posthtml-widows/issues"},"dist":{"shasum":"64667f19bda55337ad5183d62bf8c74f142a9560","tarball":"https://registry.npmjs.org/posthtml-widows/-/posthtml-widows-1.0.0.tgz","fileCount":5,"integrity":"sha512-V+nOmgX4ci14g8cZsChWnhLnVjTpvgj5GcevJ5IqonZRLxSFh0riZ6bmycKIk7FsBELW6tECZ0M0mfafeg6BKg==","signatures":[{"sig":"MEUCIQCd3zK7yYVHZ0vmz/Z/ma8dasQodmyQTNmWvnC8C7U+2wIgbCS4lXBWt3YVXmgRv3pXdjlRdWv8PzhqUes+fVegitE=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":9957},"main":"dist/index.cjs","type":"module","module":"./dist/index.mjs","engines":{"node":">=18.0.0"},"exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.cjs"}},"gitHead":"297720649b409bc25578940a3ac7f45695c2f642","scripts":{"dev":"vitest","lint":"biome lint ./lib","test":"vitest run --coverage","build":"unbuild","prepack":"unbuild","pretest":"npm run lint","release":"npx np"},"_npmUser":{"name":"cossssmin","email":"hellocosmin@gmail.com"},"repository":{"url":"git+https://github.com/posthtml/posthtml-widows.git","type":"git"},"_npmVersion":"10.2.4","description":"PostHTML plugin for preventing widow words in strings.","directories":{},"_nodeVersion":"20.10.0","_hasShrinkwrap":false,"devDependencies":{"vitest":"^2.1.5","unbuild":"^2.0.0","posthtml":"^0.16.6","@biomejs/biome":"1.9.4","@vitest/coverage-v8":"^2.1.5"},"_npmOperationalInternal":{"tmp":"tmp/posthtml-widows_1.0.0_1731762508790_0.024862069389754993","host":"s3://npm-registry-packages"}},"1.0.1":{"name":"posthtml-widows","version":"1.0.1","keywords":["widows","string","typography","paragraph","html","text","email","copywriting","posthtml","posthtml-plugin"],"author":{"url":"https://github.com/cossssmin","name":"PostHTML"},"license":"MIT","_id":"posthtml-widows@1.0.1","maintainers":[{"name":"cossssmin","email":"hellocosmin@gmail.com"}],"homepage":"https://github.com/posthtml/posthtml-widows","bugs":{"url":"https://github.com/posthtml/posthtml-widows/issues"},"dist":{"shasum":"90f1cd13c16d4d0175a11c4fbd3acce1f53bd9dc","tarball":"https://registry.npmjs.org/posthtml-widows/-/posthtml-widows-1.0.1.tgz","fileCount":5,"integrity":"sha512-hdLRyggl8fW4YDPC8EBaayrRFJ8O4C31bIiZlM1bomk7qn8XDnc9EiXUFobBmS3rYElW6hpqHi8fMdcAsl5SMA==","signatures":[{"sig":"MEQCIAnPZEHxvOaEdT2X754EH8Yjj6yqD7FxF4iscgQkbvekAiBUs3LUOkBjx2bDeW3VwpBzyk3z8K/xD5c0PiEbJLRPtg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":10116},"main":"dist/index.cjs","type":"module","module":"./dist/index.mjs","engines":{"node":">=18.0.0"},"exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.cjs"}},"gitHead":"cfe01c505e8f01bb79aa8775803fac9d65bebf7c","scripts":{"dev":"vitest","lint":"biome lint ./lib","test":"vitest run --coverage","build":"unbuild","prepack":"unbuild","pretest":"npm run lint","release":"npx np"},"_npmUser":{"name":"cossssmin","email":"hellocosmin@gmail.com"},"repository":{"url":"git+https://github.com/posthtml/posthtml-widows.git","type":"git"},"_npmVersion":"10.2.4","description":"PostHTML plugin for preventing widow words in strings.","directories":{},"_nodeVersion":"20.10.0","_hasShrinkwrap":false,"devDependencies":{"vitest":"^2.1.5","unbuild":"^2.0.0","posthtml":"^0.16.6","@biomejs/biome":"1.9.4","@vitest/coverage-v8":"^2.1.5"},"_npmOperationalInternal":{"tmp":"tmp/posthtml-widows_1.0.1_1731766195650_0.7686503491930399","host":"s3://npm-registry-packages"}},"1.0.2":{"name":"posthtml-widows","description":"PostHTML plugin for preventing widow words in strings.","version":"1.0.2","license":"MIT","author":{"name":"PostHTML","url":"https://github.com/cossssmin"},"bugs":{"url":"https://github.com/posthtml/posthtml-widows/issues"},"homepage":"https://github.com/posthtml/posthtml-widows","repository":{"type":"git","url":"git+https://github.com/posthtml/posthtml-widows.git"},"type":"module","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.cjs"}},"main":"dist/index.cjs","module":"./dist/index.mjs","engines":{"node":">=18.0.0"},"scripts":{"dev":"vitest","release":"npx np","build":"unbuild","prepack":"unbuild","lint":"biome lint ./lib ./test","pretest":"npm run lint","test":"vitest run --coverage"},"keywords":["widows","string","typography","paragraph","html","text","email","copywriting","posthtml","posthtml-plugin"],"devDependencies":{"@biomejs/biome":"2.0.5","@vitest/coverage-v8":"^3.0.3","posthtml":"^0.16.6","unbuild":"^2.0.0","vitest":"^3.0.2"},"_id":"posthtml-widows@1.0.2","gitHead":"fe15f2de18cd3649fa663f16a87ad4b304b73a85","_nodeVersion":"22.14.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-1uy5/iirP0HWJ6VXQMSjsei6VV9F7TBqKwh9VlF60nKdA14ik/rEdVga79Wk4a9xRWAujMEnmOH5LQgNQQjreg==","shasum":"7d3375df7f00bcc4ff571b0989266147f16cba93","tarball":"https://registry.npmjs.org/posthtml-widows/-/posthtml-widows-1.0.2.tgz","fileCount":5,"unpackedSize":10123,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIA4iAKu0za9qnAGbTyaFdy/16q7/HArV3fdRrI9M2s8yAiEAkUD14S5v1CdAO6sMe+3U+CjvyARvLpmdU54y3MOelyg="}]},"_npmUser":{"name":"cossssmin","email":"hellocosmin@gmail.com","actor":{"name":"cossssmin","email":"hellocosmin@gmail.com","type":"user"}},"directories":{},"maintainers":[{"name":"cossssmin","email":"hellocosmin@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/posthtml-widows_1.0.2_1750770935636_0.9214177150896337"},"_hasShrinkwrap":false}},"time":{"created":"2024-11-16T13:08:28.790Z","modified":"2025-06-24T13:15:36.007Z","1.0.0":"2024-11-16T13:08:28.955Z","1.0.1":"2024-11-16T14:09:55.853Z","1.0.2":"2025-06-24T13:15:35.819Z"},"bugs":{"url":"https://github.com/posthtml/posthtml-widows/issues"},"author":{"name":"PostHTML","url":"https://github.com/cossssmin"},"license":"MIT","homepage":"https://github.com/posthtml/posthtml-widows","keywords":["widows","string","typography","paragraph","html","text","email","copywriting","posthtml","posthtml-plugin"],"repository":{"type":"git","url":"git+https://github.com/posthtml/posthtml-widows.git"},"description":"PostHTML plugin for preventing widow words in strings.","maintainers":[{"name":"cossssmin","email":"hellocosmin@gmail.com"}],"readme":"<div align=\"center\">\n  <img width=\"150\" height=\"150\" alt=\"PostHTML\" src=\"https://posthtml.github.io/posthtml/logo.svg\">\n  <h1>Prevent Widows</h1>\n  <p>PostHTML plugin for preventing widow words</p>\n\n  [![Version][npm-version-shield]][npm]\n  [![Build][github-ci-shield]][github-ci]\n  [![License][license-shield]][license]\n  [![Downloads][npm-stats-shield]][npm-stats]\n</div>\n\n## Introduction\n\nThis plugin helps prevent widow words by replacing the space between the last two words in a string with a non-breaking space. By default, the string must contain at least 4 words to be processed.\n\nInput:\n\n```html\n<div prevent-widows>\n  <p>The quick brown fox</p>\n</div>\n```\n\nOutput:\n\n```html\n<div>\n  <p>The quick brown&nbsp;fox</p>\n</div>\n```\n\n- [x] configurable attribute names\n- [x] set the minimum number of words\n- [x] ignore templating logic or expressions\n- [x] reverse it: create widow words\n\n## Install\n\n```\nnpm i posthtml posthtml-widows\n```\n\n## Usage\n\n```js\nimport posthtml from 'posthtml'\nimport preventWidows from 'posthtml-widows'\n\nposthtml([\n  preventWidows()\n])\n  .process('<p prevent-widows>The quick brown fox</p>')\n  .then(result => console.log(result.html))\n```\n\nResult:\n\n```html\n<p>The quick brown&nbsp;fox</p>\n```\n\n## Attributes\n\nThe plugin will only handle strings inside elements that have one of the following attributes:\n\n- `prevent-widows`\n- `no-widows`\n\nYou may also specify custom attributes to use:\n\n```js\nposthtml([\n  preventWidows({\n    attributes: ['fix-widows']\n  })\n])\n  .process('<p fix-widows>The quick brown fox</p>')\n```\n\n## Options\n\n### `minWords`\n\nType: `number`\\\nDefault: `4`\n\nThe minimum number of words a string must contain to be processed.\n\n```js\nposthtml([\n  preventWidows({\n    minWords: 3,\n  })\n])\n  .process('<p prevent-widows>Prevent widow words</p>')\n```\n\n### `ignore`\n\nType: `Array`\\\nDefault: (array of objects)\n\nAn array of objects that specify the `start` and `end` delimiters of strings to ignore. Used to avoid processing templating logic or expressions.\n\nBy default, the following templating delimiters are ignored:\n\n- `{{ }}` -  Handlebars, Liquid, Nunjucks, Twig, Jinja2, Mustache\n- `{% %}` -  Liquid, Nunjucks, Twig, Jinja2\n- `<%= %>` - EJS, ERB\n- `<% %>` -  EJS, ERB\n- `{$ }` - Smarty\n- `<?php ?>` - PHP\n- `<?= ?>` - PHP\n- `#{ }` - Pug\n\nYou may add custom delimiters to ignore:\n\n```js\nposthtml([\n  preventWidows({\n    ignore: [\n      { start: '[[', end: ']]' },\n      // Inside MSO comments\n      { start: '<!--[', end: ']>' },\n      { start: '<![', end: ']--><' }, // <![endif]-->\n    ]\n  })\n])\n  .process(\n    `<p prevent-widows>Using the option to <!--[if mso]> ignore this MSO comment <![endif]--> is being tested here.</p>`\n  )\n```\n\nResult:\n\n```html\n<p>Using the option to <!--[if mso]> ignore this MSO comment <![endif]--> is being tested&nbsp;here.</p>\n```\n\n### `createWidows`\n\nType: `boolean`\\\nDefault: `false`\n\nYou may also use the plugin to do the opposite of preventing widow words by replacing the `&nbsp;` between the last two words with a regular space.\n\n```js\nposthtml([\n  preventWidows({\n    attributes: ['create-widows'],\n    createWidows: true,\n  })\n])\n  .process('<p create-widows>The quick brown&nbsp;fox</p>')\n```\n\nResult:\n\n```html\n<p>The quick brown fox</p>\n```\n\n## License\n\n[MIT](./LICENSE)\n\n[npm]: https://www.npmjs.com/package/posthtml-widows\n[npm-version-shield]: https://img.shields.io/npm/v/posthtml-widows.svg\n[npm-stats]: http://npm-stat.com/charts.html?package=posthtml-widows\n[npm-stats-shield]: https://img.shields.io/npm/dt/posthtml-widows.svg\n[github-ci]: https://github.com/posthtml/posthtml-widows/actions/workflows/nodejs.yml\n[github-ci-shield]: https://github.com/posthtml/posthtml-widows/actions/workflows/nodejs.yml/badge.svg\n[license]: ./LICENSE\n[license-shield]: https://img.shields.io/npm/l/posthtml-widows.svg\n","readmeFilename":"README.md"}