{"id":24983636,"url":"https://github.com/posthtml/posthtml-widows","last_synced_at":"2025-04-11T20:51:21.015Z","repository":{"id":263132706,"uuid":"889271466","full_name":"posthtml/posthtml-widows","owner":"posthtml","description":"Prevent widow words","archived":false,"fork":false,"pushed_at":"2025-04-01T21:45:43.000Z","size":519,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-10T08:33:59.997Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/posthtml.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":"posthtml","open_collective":"posthtml","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":"mailviews.com"}},"created_at":"2024-11-16T00:25:26.000Z","updated_at":"2025-04-01T21:44:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"9770fb83-e9ca-4d8a-a306-606c52bb85e5","html_url":"https://github.com/posthtml/posthtml-widows","commit_stats":{"total_commits":25,"total_committers":2,"mean_commits":12.5,"dds":0.07999999999999996,"last_synced_commit":"d0fa2a0008795daa46cc3fca0b212dc093ee4ee2"},"previous_names":["posthtml/posthtml-widows"],"tags_count":2,"template":false,"template_full_name":"posthtml/posthtml-plugin-starter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-widows","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-widows/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-widows/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-widows/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/posthtml","download_url":"https://codeload.github.com/posthtml/posthtml-widows/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248480512,"owners_count":21110936,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-04T09:19:56.515Z","updated_at":"2025-04-11T20:51:20.990Z","avatar_url":"https://github.com/posthtml.png","language":"JavaScript","readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg width=\"150\" height=\"150\" alt=\"PostHTML\" src=\"https://posthtml.github.io/posthtml/logo.svg\"\u003e\n  \u003ch1\u003ePrevent Widows\u003c/h1\u003e\n  \u003cp\u003ePostHTML plugin for preventing widow words\u003c/p\u003e\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\u003c/div\u003e\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\u003cdiv prevent-widows\u003e\n  \u003cp\u003eThe quick brown fox\u003c/p\u003e\n\u003c/div\u003e\n```\n\nOutput:\n\n```html\n\u003cdiv\u003e\n  \u003cp\u003eThe quick brown\u0026nbsp;fox\u003c/p\u003e\n\u003c/div\u003e\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('\u003cp prevent-widows\u003eThe quick brown fox\u003c/p\u003e')\n  .then(result =\u003e console.log(result.html))\n```\n\nResult:\n\n```html\n\u003cp\u003eThe quick brown\u0026nbsp;fox\u003c/p\u003e\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('\u003cp fix-widows\u003eThe quick brown fox\u003c/p\u003e')\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('\u003cp prevent-widows\u003ePrevent widow words\u003c/p\u003e')\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- `\u003c%= %\u003e` - EJS, ERB\n- `\u003c% %\u003e` -  EJS, ERB\n- `{$ }` - Smarty\n- `\u003c?php ?\u003e` - PHP\n- `\u003c?= ?\u003e` - 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: '\u003c!--[', end: ']\u003e' },\n      { start: '\u003c![', end: ']--\u003e\u003c' }, // \u003c![endif]--\u003e\n    ]\n  })\n])\n  .process(\n    `\u003cp prevent-widows\u003eUsing the option to \u003c!--[if mso]\u003e ignore this MSO comment \u003c![endif]--\u003e is being tested here.\u003c/p\u003e`\n  )\n```\n\nResult:\n\n```html\n\u003cp\u003eUsing the option to \u003c!--[if mso]\u003e ignore this MSO comment \u003c![endif]--\u003e is being tested\u0026nbsp;here.\u003c/p\u003e\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 `\u0026nbsp;` 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('\u003cp create-widows\u003eThe quick brown\u0026nbsp;fox\u003c/p\u003e')\n```\n\nResult:\n\n```html\n\u003cp\u003eThe quick brown fox\u003c/p\u003e\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","funding_links":["https://patreon.com/posthtml","https://opencollective.com/posthtml","mailviews.com"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthtml%2Fposthtml-widows","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fposthtml%2Fposthtml-widows","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthtml%2Fposthtml-widows/lists"}