Skip to content

Commit 0822045

Browse files
committed
docs: strip empty ps
1 parent f441318 commit 0822045

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

eleventy.config.cjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const SyntaxHighlightPlugin = require('@11ty/eleventy-plugin-syntaxhighlight');
33
const DirectoryOutputPlugin = require('@11ty/eleventy-plugin-directory-output');
44

55
const PfeAssetsPlugin = require('./docs/_plugins/pfe-assets.cjs');
6+
const EmptyParagraphPlugin = require('./docs/_plugins/empty-p.cjs');
67

78
const AnchorsPlugin = require('@patternfly/pfe-tools/11ty/plugins/anchors.cjs');
89
const CustomElementsManifestPlugin = require('@patternfly/pfe-tools/11ty/plugins/custom-elements-manifest.cjs');
@@ -50,6 +51,9 @@ module.exports = function(eleventyConfig) {
5051
/** fancy syntax highlighting with diff support */
5152
eleventyConfig.addPlugin(SyntaxHighlightPlugin);
5253

54+
/** Strip empty paragraphs */
55+
eleventyConfig.addPlugin(EmptyParagraphPlugin);
56+
5357
/** Add IDs to heading elements */
5458
eleventyConfig.addPlugin(AnchorsPlugin, {
5559
exclude: /\/components\/.*\/demo\//,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const cheerio = require('cheerio');
2+
3+
/**
4+
* @param {import('@11ty/eleventy/src/UserConfig')} eleventyConfig
5+
*/
6+
module.exports = function(eleventyConfig) {
7+
eleventyConfig.addTransform('delete-empty-p', async function(rawContent, outputPath) {
8+
if (!outputPath || !outputPath.endsWith('.html')) {
9+
return rawContent;
10+
} else {
11+
const $ = cheerio.load(rawContent);
12+
$('p:empty').each(function() {
13+
if (!this.attributes.length) {
14+
$(this).remove();
15+
}
16+
});
17+
return $.html();
18+
}
19+
});
20+
};

0 commit comments

Comments
 (0)