Skip to content

Commit

Permalink
Format macro options with "smart" typographic punctuation
Browse files Browse the repository at this point in the history
The marked option `{ smartypants: true }` has been deprecated so we must use `marked-smartypants` here instead

Note: Metalsmith’s `jstransformer-marked` still uses `marked@4.3.0` so we can’t migrate to `marked-smartypants`

markedjs/marked#2766
  • Loading branch information
colinrotherham committed Aug 15, 2023
1 parent 5aec229 commit e549b9d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/get-macro-options/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
const { dirname, join } = require('path')

const { marked } = require('marked')
const { Marked, Renderer } = require('marked')
const { markedSmartypants } = require('marked-smartypants')

const { kebabCase, slugify } = require('../nunjucks/filters')

// Get reference to marked.js
const renderer = new marked.Renderer()
const renderer = new Renderer()
// Override marking up paragraphs
renderer.paragraph = (text) => text

// Custom Marked instance with "smart" typographic punctuation
const marked = new Marked().setOptions({ renderer }).use(markedSmartypants())

function getMacroOptionsJson(componentName) {
const optionsFilePath = join(
dirname(require.resolve('govuk-frontend')),
Expand Down Expand Up @@ -45,7 +49,7 @@ function renderNameWithBreaks(option) {

function renderDescriptionsAsMarkdown(option) {
if (option.description) {
option.description = marked(option.description, { renderer })
option.description = marked.parse(option.description)
}
if (option.params) {
option.params = option.params.map(renderDescriptionsAsMarkdown)
Expand Down

0 comments on commit e549b9d

Please sign in to comment.