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 authored Aug 1, 2022
1 parent 2100ebd commit 8551f82
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/marked-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ 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 8551f82

Please sign in to comment.