rehype-class-names
Advanced tools
Comparing version 1.0.1 to 1.0.2
28
index.js
@@ -1,18 +0,16 @@ | ||
import { selectAll } from "hast-util-select"; | ||
export default (additions) => { | ||
const adders = Object.entries(additions).map(adder); | ||
return (node) => adders.forEach((a) => a(node)); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const hast_util_select_1 = require("hast-util-select"); | ||
exports.default = (additions) => { | ||
const adders = Object.entries(additions).map((property) => adder(property)); | ||
return (node) => adders.forEach((a) => a(node)); | ||
}; | ||
const adder = ([selector, className]) => { | ||
const writer = write(className); | ||
return (node) => selectAll(selector, node).forEach(writer); | ||
return (node) => (0, hast_util_select_1.selectAll)(selector, node).forEach((elem) => { | ||
var _a; | ||
if (!((_a = elem === null || elem === void 0 ? void 0 : elem.properties) === null || _a === void 0 ? void 0 : _a.className)) | ||
elem.properties = { className }; | ||
else | ||
elem.properties.className += ` ${className}`; | ||
}); | ||
}; | ||
const write = | ||
(className) => | ||
({ properties }) => { | ||
if (!properties.className) properties.className = className; | ||
else properties.className += ` ${className}`; | ||
}; |
{ | ||
"name": "rehype-class-names", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "A utility plugin to use with rehype that adds class names to HAST (html tree)", | ||
@@ -27,3 +27,6 @@ "main": "index.js", | ||
"hast-util-select": "^5.0.5" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^4.9.4" | ||
} | ||
} |
# Rehype Class Names | ||
Adding classes to elements with rehype. All credit goes to [rehype-add-classes](https://github.com/martypdx/rehype-add-classes) but with fixed dependencies plus I wanted to make an npm package :shrug:. | ||
Adding classes to elements with rehype. All credit goes to [rehype-add-classes](https://github.com/martypdx/rehype-add-classes) but with fixed dependencies, added typescript support, plus I wanted to make an npm package :shrug:. | ||
@@ -5,0 +5,0 @@ ## Installation |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15252
5
134
1