File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
tools/pfe-tools/11ty/plugins Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ const SyntaxHighlightPlugin = require('@11ty/eleventy-plugin-syntaxhighlight');
33const DirectoryOutputPlugin = require ( '@11ty/eleventy-plugin-directory-output' ) ;
44
55const PfeAssetsPlugin = require ( './docs/_plugins/pfe-assets.cjs' ) ;
6+ const EmptyParagraphPlugin = require ( './docs/_plugins/empty-p.cjs' ) ;
67
78const AnchorsPlugin = require ( '@patternfly/pfe-tools/11ty/plugins/anchors.cjs' ) ;
89const 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 : / \/ c o m p o n e n t s \/ .* \/ d e m o \/ / ,
Original file line number Diff line number Diff line change 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+ } ;
You can’t perform that action at this time.
0 commit comments