Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/_plugins/empty-p.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const cheerio = require('cheerio');

/**
* @param {import('@11ty/eleventy/src/UserConfig')} eleventyConfig
*/
module.exports = function(eleventyConfig) {
eleventyConfig.addTransform('delete-empty-p', async function(rawContent, outputPath) {
if (!outputPath || !outputPath.endsWith('.html')) {
return rawContent;
} else {
const $ = cheerio.load(rawContent);
$('p:empty').each(function() {
if (!this.attributes.length) {
$(this).remove();
}
});
return $.html();
}
});
};
4 changes: 4 additions & 0 deletions docs/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ main.blog {
transition: opacity 0.2s ease;
}

p:empty {
display: none;
}

.sr-only {
position: absolute;
width: 1px;
Expand Down
4 changes: 4 additions & 0 deletions eleventy.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const SyntaxHighlightPlugin = require('@11ty/eleventy-plugin-syntaxhighlight');
const DirectoryOutputPlugin = require('@11ty/eleventy-plugin-directory-output');

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

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

/** Strip empty paragraphs */
eleventyConfig.addPlugin(EmptyParagraphPlugin);

/** Add IDs to heading elements */
eleventyConfig.addPlugin(AnchorsPlugin, {
exclude: /\/components\/.*\/demo\//,
Expand Down