Skip to content

Commit

Permalink
Merge pull request #2276 from alphagov/bk-spike-tagcleaner-replacement
Browse files Browse the repository at this point in the history
Replace metalsmith-tagcleaner with a custom marked renderer
  • Loading branch information
domoscargin authored Aug 1, 2022
2 parents c223dd0 + eb58287 commit 78989ed
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 200 deletions.
13 changes: 13 additions & 0 deletions lib/marked-renderer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// A custom renderer that avoids wrapping <img> tags in <p> tags
const { marked } = require('marked')

class DesignSystemRenderer extends marked.Renderer {
paragraph (text) {
if (text.startsWith('<img')) {
return `${text}\n`
}
return super.paragraph(text)
}
}

module.exports = new DesignSystemRenderer()
6 changes: 2 additions & 4 deletions lib/metalsmith.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ const metalsmith = require('metalsmith') // static site generator
const assets = require('metalsmith-assets') // copy static assets
const brokenLinkChecker = require('metalsmith-broken-link-checker')
const titleChecker = require('./metalsmith-title-checker.js')
const markedRenderer = require('./marked-renderer.js')
const env = require('metalsmith-env') // environment vars plugin
const hashAssets = require('metalsmith-fingerprint-ignore') // add hash to specified files and ignores files that match a pattern
const inplace = require('@metalsmith/in-place') // render templating syntax in your source files
const layouts = require('@metalsmith/layouts') // apply layouts to source files
const tagcleaner = require('metalsmith-tagcleaner') // Use tag cleaner to remove <p> tags around images
const permalinks = require('@metalsmith/permalinks') // apply a permalink pattern to files
const canonical = require('metalsmith-canonical') // add a canonical url property to pages

Expand Down Expand Up @@ -233,13 +233,11 @@ module.exports = metalsmith(__dirname) // __dirname defined by node.js: name of
gfm: true,
tables: true,
pedantic: true,
renderer: markedRenderer,
highlight: highlighter
}
}))

// use tag cleaner to remove <p> tags around images
.use(tagcleaner())

// apply a permalink pattern to files
.use(permalinks({
relative: false
Expand Down
Loading

0 comments on commit 78989ed

Please sign in to comment.