# posthtml-safe-class-names **Repository Path**: mirrors_posthtml/posthtml-safe-class-names ## Basic Information - **Project Name**: posthtml-safe-class-names - **Description**: Replace escaped characters in CSS selectors and HTML class names. - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-25 - **Last Updated**: 2025-09-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README

Safe Class Names

Replace escaped characters in class names and CSS selectors

[![Version][npm-version-shield]][npm] [![Build][github-ci-shield]][github-ci] [![License][license-shield]][license] [![Downloads][npm-stats-shield]][npm-stats]
## Introduction This plugin replaces escaped characters in class names from your `
Lorem ipsum
``` ```js import posthtml from 'posthtml' import {readFileSync, writeFileSync} from 'node:fs' import safeClassNames from 'posthtml-safe-class-names' const source = readFileSync('./example.html') posthtml([ safeClassNames() ]) .process(source) .then(result => fs.writeFileSync('./after.html', result.html)) ``` Result: ```html
Lorem ipsum
``` ## Options ### `replacements` Type: `Object`\ Default: [see list](lib/index.js#L19-L51) The plugin accepts an options object where you can define character replacement mappings: ```js { ':': '-', '\/': '-', '%': 'pc', '.': '_', // ... } ``` See the full [list of replacements](lib/index.js#L19-L51). Besides adding new mappings, you can of course override the default ones. Using the same `example.html`, let's replace `\:` in our class names with `__` instead of `-`: ```js posthtml([ safeClassNames({ replacements: { ':': '__', } }) ]) .process(source) .then(result => writeFileSync('./after.html', result.html)) ``` Result: ```html
Lorem ipsum
``` ### `ignored` Type: `Array`\ Default: `[{heads: '{{', tails: '}}'}, {heads: '{{{', tails: '}}}'}]` An array of objects each containing heads/tails strings that mark the start and end of a class name to ignore. If a class name matches a pattern defined here, it will not be processed. ```js posthtml([ safeClassNames({ ignored: [ {heads: '[[', tails: ']]'}, ] }) ]) .process('
') .then(result => console.log(result.html)) //
``` [npm]: https://www.npmjs.com/package/posthtml-safe-class-names [npm-version-shield]: https://img.shields.io/npm/v/posthtml-safe-class-names.svg [npm-stats]: http://npm-stat.com/charts.html?package=posthtml-safe-class-names [npm-stats-shield]: https://img.shields.io/npm/dt/posthtml-safe-class-names.svg [github-ci]: https://github.com/posthtml/posthtml-safe-class-names/actions [github-ci-shield]: https://github.com/posthtml/posthtml-safe-class-names/actions/workflows/nodejs.yml/badge.svg [license]: ./LICENSE [license-shield]: https://img.shields.io/npm/l/posthtml-safe-class-names.svg