@carrotsearch/gatsby-transformer-html
Version:
A Gatsby transformer plugin for authoring content in HTML. Supports ToC generation, responsive images, section anchors and HighlightJS code highlighting.
31 lines (23 loc) • 748 B
JavaScript
const cheerio = require("cheerio");
const { generateElementId } = require("./generate-element-id.js");
require("must/register");
describe("generateElementId must", function () {
it("prefix generated id with existing parent id", function () {
const $ = cheerio.load(`
<div id="section">
<p>paragraph</p>
</div>
`);
generateElementId($("p"), t => t, new Set());
$("p").eq(0).attr("id").must.equal("section:32a97fa2");
});
it("not fail if there is no parent with id", function () {
const $ = cheerio.load(`
<div id="section">
<p>paragraph</p>
</div>
`);
generateElementId($("p"), t => t, new Set());
$("p").eq(0).attr("id").must.equal("section:32a97fa2");
});
});