Skip to content

Commit

Permalink
Use subclass for marked renderer
Browse files Browse the repository at this point in the history
This better matches how things are done in Marked, and allows us to user `super` for cases other than images.

Co-authored-by: Oliver Byford <oliver.byford@digital.cabinet-office.gov.uk>
  • Loading branch information
domoscargin and 36degrees committed Aug 1, 2022
1 parent 2100ebd commit eb58287
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/marked-renderer.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// A custom renderer that avoids wrapping <img> tags in <p> tags
const { marked } = require('marked')

const markedRenderer = new marked.Renderer()

markedRenderer.paragraph = function (text) {
if (text.startsWith('<img')) {
return `${text}\n`
class DesignSystemRenderer extends marked.Renderer {
paragraph (text) {
if (text.startsWith('<img')) {
return `${text}\n`
}
return super.paragraph(text)
}
return `<p>${text}</p>\n`
}

module.exports = markedRenderer
module.exports = new DesignSystemRenderer()

0 comments on commit eb58287

Please sign in to comment.