Skip to content

Commit

Permalink
Lint JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Dec 15, 2023
1 parent 4308e86 commit bea4a14
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 59 deletions.
10 changes: 6 additions & 4 deletions lib/extensions/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ module.exports = function (options) {

level: 'block',

start (src) {
start(src) {
return src.match(/\$A\n(?!\s)/)?.index
},

tokenizer (src) {
tokenizer(src) {
return blockTokenizer(this.lexer, src, 'govspeak-address', '$A')
},

renderer ({ tokens }) {
renderer({ tokens }) {
const className = classGenerator('address', options)
return `<address class="${className}">\n ${this.parser.parse(tokens)}\n</address>`
return `<address class="${className}">\n ${this.parser.parse(
tokens
)}\n</address>`
}
}
}
6 changes: 3 additions & 3 deletions lib/extensions/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ module.exports = function (options) {

level: 'inline',

start (src) {
start(src) {
return src.match(/{button(?!\s)/)?.index
},

tokenizer (src) {
tokenizer(src) {
if (!src.startsWith('{button')) {
return
}
Expand Down Expand Up @@ -38,7 +38,7 @@ module.exports = function (options) {
}
},

renderer ({ isStartButton, tokens }) {
renderer({ isStartButton, tokens }) {
if (isStartButton) {
const className = classGenerator('button--start', options)
return `<a class="${className}" href="${tokens[0].href}" role="button">${tokens[0].text}<svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewBox="0 0 33 40" aria-hidden="true" focusable="false"><path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"/></svg></a>`
Expand Down
10 changes: 6 additions & 4 deletions lib/extensions/call-to-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ module.exports = function (options) {

level: 'block',

start (src) {
start(src) {
return src.match(/\$CTA(?!\s)/)?.index
},

tokenizer (src) {
tokenizer(src) {
return blockTokenizer(this.lexer, src, 'govspeak-call-to-action', '$CTA')
},

renderer ({ tokens }) {
renderer({ tokens }) {
const className = classGenerator('call-to-action', options)
return `<div class="${className}">\n ${this.parser.parse(tokens)}\n</div>`
return `<div class="${className}">\n ${this.parser.parse(
tokens
)}\n</div>`
}
}
}
10 changes: 6 additions & 4 deletions lib/extensions/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ module.exports = function (options) {

level: 'block',

start (src) {
start(src) {
return src.match(/\$C\n(?!\s)/)?.index
},

tokenizer (src) {
tokenizer(src) {
return blockTokenizer(this.lexer, src, 'govspeak-contact', '$C')
},

renderer ({ tokens }) {
renderer({ tokens }) {
const className = classGenerator('contact', options)
return `<div class="${className}">\n ${this.parser.parse(tokens)}\n</div>`
return `<div class="${className}">\n ${this.parser.parse(
tokens
)}\n</div>`
}
}
}
10 changes: 6 additions & 4 deletions lib/extensions/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ module.exports = function (options) {

level: 'block',

start (src) {
start(src) {
return src.match(/\$E\n(?!\s)/)?.index
},

tokenizer (src) {
tokenizer(src) {
return blockTokenizer(this.lexer, src, 'govspeak-example', '$E')
},

renderer ({ tokens }) {
renderer({ tokens }) {
const className = classGenerator('example', options)
return `<div class="${className}">\n ${this.parser.parse(tokens)}\n</div>`
return `<div class="${className}">\n ${this.parser.parse(
tokens
)}\n</div>`
}
}
}
10 changes: 6 additions & 4 deletions lib/extensions/form-download.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ module.exports = function (options) {

level: 'block',

start (src) {
start(src) {
return src.match(/\$D\n(?!\s)/)?.index
},

tokenizer (src) {
tokenizer(src) {
return blockTokenizer(this.lexer, src, 'govspeak-form-download', '$D')
},

renderer ({ tokens }) {
renderer({ tokens }) {
const className = classGenerator('form-download', options)
return `<div class="${className}">\n ${this.parser.parse(tokens)}\n</div>`
return `<div class="${className}">\n ${this.parser.parse(
tokens
)}\n</div>`
}
}
}
10 changes: 6 additions & 4 deletions lib/extensions/information-callout.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ module.exports = function (options) {

level: 'block',

start (src) {
start(src) {
return src.match(/\^(?!\s)/)?.index
},

tokenizer (src) {
tokenizer(src) {
if (!src.startsWith('^')) {
return
}
Expand All @@ -25,9 +25,11 @@ module.exports = function (options) {
}
},

renderer ({ text }) {
renderer({ text }) {
const className = classGenerator('information-callout', options)
return `<div class="${className}" role="note" aria-label="Information">\n <p>${this.parser.parseInline(text)}</p>\n</div>`
return `<div class="${className}" role="note" aria-label="Information">\n <p>${this.parser.parseInline(
text
)}</p>\n</div>`
}
}
}
10 changes: 6 additions & 4 deletions lib/extensions/information.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ module.exports = function (options) {

level: 'block',

start (src) {
start(src) {
return src.match(/\$I\n(?!\s)/)?.index
},

tokenizer (src) {
tokenizer(src) {
return blockTokenizer(this.lexer, src, 'govspeak-information', '$I')
},

renderer ({ tokens }) {
renderer({ tokens }) {
const className = classGenerator('information', options)
return `<div class="${className}">\n ${this.parser.parse(tokens)}\n</div>`
return `<div class="${className}">\n ${this.parser.parse(
tokens
)}\n</div>`
}
}
}
10 changes: 6 additions & 4 deletions lib/extensions/place.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ module.exports = function (options) {

level: 'block',

start (src) {
start(src) {
return src.match(/\$C\n(?!\s)/)?.index
},

tokenizer (src) {
tokenizer(src) {
return blockTokenizer(this.lexer, src, 'govspeak-place', '$P')
},

renderer ({ tokens }) {
renderer({ tokens }) {
const className = classGenerator('place', options)
return `<div class="${className}">\n ${this.parser.parse(tokens)}\n</div>`
return `<div class="${className}">\n ${this.parser.parse(
tokens
)}\n</div>`
}
}
}
18 changes: 13 additions & 5 deletions lib/extensions/stat-headline.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,25 @@ module.exports = function (options) {

level: 'block',

start (src) {
start(src) {
return src.match(/{stat(?!\s)/)?.index
},

tokenizer (src) {
return blockTokenizer(this.lexer, src, 'govspeak-stat-headline', '{stat-headline}', '{/stat-headline}')
tokenizer(src) {
return blockTokenizer(
this.lexer,
src,
'govspeak-stat-headline',
'{stat-headline}',
'{/stat-headline}'
)
},

renderer ({ tokens }) {
renderer({ tokens }) {
const className = classGenerator('stat-headline', options)
return `<div class="${className}">\n ${this.parser.parse(tokens)}\n</div>`
return `<div class="${className}">\n ${this.parser.parse(
tokens
)}\n</div>`
}
}
}
16 changes: 9 additions & 7 deletions lib/extensions/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ module.exports.steps = function (options) {

level: 'block',

start (src) {
start(src) {
return src.match(/\s*(?:s\d+\.\s.*(?:\n|$))+/)?.index
},

tokenizer (src) {
tokenizer(src) {
const rule = /^\s*(?:s\d+\.\s.*(?:\n|$))+/
const match = rule.exec(src)
if (match) {
Expand All @@ -26,9 +26,11 @@ module.exports.steps = function (options) {
}
},

renderer ({ tokens }) {
renderer({ tokens }) {
const className = classGenerator('steps', options)
return `<ol class="${className}">${this.parser.parseInline(tokens)}\n</ol>`
return `<ol class="${className}">${this.parser.parseInline(
tokens
)}\n</ol>`
}
}
}
Expand All @@ -39,11 +41,11 @@ module.exports.step = function (_options) {

level: 'inline',

start (src) {
start(src) {
return src.match(/s(\d+)\./)?.index
},

tokenizer (src) {
tokenizer(src) {
const rule = /s(\d+)\.\s(.*)(?:\n|$)/
const match = rule.exec(src)

Expand All @@ -58,7 +60,7 @@ module.exports.step = function (_options) {
}
},

renderer ({ li }) {
renderer({ li }) {
return `\n <li>${this.parser.parseInline(li)}</li>`
},

Expand Down
10 changes: 6 additions & 4 deletions lib/extensions/warning-callout.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ module.exports = function (options) {

level: 'block',

start (src) {
start(src) {
return src.match(/%(?!\s)/)?.index
},

tokenizer (src) {
tokenizer(src) {
if (!src.startsWith('%')) {
return
}
Expand All @@ -25,9 +25,11 @@ module.exports = function (options) {
}
},

renderer ({ text }) {
renderer({ text }) {
const className = classGenerator('warning-callout', options)
return `<div class="${className}" role="note" aria-label="Warning">\n <p>${this.parser.parseInline(text)}</p>\n</div>`
return `<div class="${className}" role="note" aria-label="Warning">\n <p>${this.parser.parseInline(
text
)}</p>\n</div>`
}
}
}
15 changes: 10 additions & 5 deletions test/compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ const { marked } = require('marked')
const govspeak = require('../index.js')

describe('Govspeak with RubyGem compatibility', () => {
marked.use(govspeak({
govspeakGemCompatibility: true
}))
marked.use(
govspeak({
govspeakGemCompatibility: true
})
)

it('Renders address', () => {
assert.equal(
Expand All @@ -32,7 +34,8 @@ describe('Govspeak with RubyGem compatibility', () => {
it('Renders call to action', () => {
assert.equal(
marked('$CTA\nCall to action\n$CTA'),
'<div class="call-to-action">\n <p>Call to action</p>\n\n</div>')
'<div class="call-to-action">\n <p>Call to action</p>\n\n</div>'
)
})

it('Renders contact', () => {
Expand Down Expand Up @@ -79,7 +82,9 @@ describe('Govspeak with RubyGem compatibility', () => {

it('Renders stat headline', () => {
assert.equal(
marked('{stat-headline}\n*13.8bn* years since the big bang{/stat-headline}'),
marked(
'{stat-headline}\n*13.8bn* years since the big bang{/stat-headline}'
),
'<div class="stat-headline">\n <p><em>13.8bn</em> years since the big bang</p>\n\n</div>'
)
})
Expand Down
10 changes: 7 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ describe('Govspeak', () => {
it('Renders example', () => {
assert.equal(
marked('$E\nExample\n$E'),
'<div class="govspeak-example">\n <p>Example</p>\n\n</div>')
'<div class="govspeak-example">\n <p>Example</p>\n\n</div>'
)
})

it('Renders information callout', () => {
Expand All @@ -77,7 +78,9 @@ describe('Govspeak', () => {

it('Renders stat headline', () => {
assert.equal(
marked('{stat-headline}\n*13.8bn* years since the big bang{/stat-headline}'),
marked(
'{stat-headline}\n*13.8bn* years since the big bang{/stat-headline}'
),
'<div class="govspeak-stat-headline">\n <p><em>13.8bn</em> years since the big bang</p>\n\n</div>'
)
})
Expand All @@ -92,6 +95,7 @@ describe('Govspeak', () => {
it('Renders warning callout', () => {
assert.equal(
marked('%warning%'),
'<div class="govspeak-warning-callout" role="note" aria-label="Warning">\n <p>warning</p>\n</div>')
'<div class="govspeak-warning-callout" role="note" aria-label="Warning">\n <p>warning</p>\n</div>'
)
})
})

0 comments on commit bea4a14

Please sign in to comment.