Skip to content

Commit

Permalink
Lint JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Nov 14, 2024
1 parent 7aa718b commit 8a4ae17
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 10 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ const highlightJs = require('highlight.js')

/**
* Add GOV.UK typography classes to blockquotes, headings, paragraphs, links,
* lists, section breaks and tables.
* @param {object} [options] Options for the extension
* lists, section breaks and tables
*
* @param {object} [options] - Options for the extension
* @returns {object} A MarkedExtension to be passed to `marked.use()`
*/
module.exports = function (options = {}) {
Expand Down Expand Up @@ -45,9 +46,9 @@ module.exports = function (options = {}) {
const FIGURE_RE = /(<a([^>]+)>)?<figure/
if (FIGURE_RE.test(text)) {
return text
} else {
return `<p class="govuk-body">${text}</p>\n`
}

return `<p class="govuk-body">${text}</p>\n`
},

// Links
Expand All @@ -56,9 +57,9 @@ module.exports = function (options = {}) {

if (title) {
return `<a class="govuk-link" href="${href}" title="${title}">${text}</a>`
} else {
return `<a class="govuk-link" href="${href}">${text}</a>`
}

return `<a class="govuk-link" href="${href}">${text}</a>`
},

// Lists
Expand Down Expand Up @@ -142,10 +143,10 @@ module.exports = function (options = {}) {
code = highlightJs.highlightAuto(text).value
}
return `<pre class="x-govuk-code x-govuk-code--block x-govuk-code__language--${language}" tabindex="0"><code>${code}</code></pre>\n`
} else {
// No language found, so render as plain text
return `<pre class="x-govuk-code x-govuk-code--block" tabindex="0">${text}</pre>\n`
}

// No language found, so render as plain text
return `<pre class="x-govuk-code x-govuk-code--block" tabindex="0">${text}</pre>\n`
},

// Inline code
Expand Down
2 changes: 2 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const assert = require('node:assert/strict')
const test = require('node:test')

const { marked } = require('marked')

const govukMarkdown = require('../index.js')

marked.use(govukMarkdown())
Expand Down

0 comments on commit 8a4ae17

Please sign in to comment.