
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
markdown-it-govuk
Advanced tools
Plugin for markdown-it to convert Markdown into GOV.UK Frontend-compliant HTML
Plugin for markdown-it to convert Markdown into GOV.UK Frontend-compliant HTML, inspired by the govuk_markdown and govspeak Ruby gems.
If you are using the marked parser, use govuk-markdown.
Node.js v22 or later.
npm install markdown-it-govuk --save
import markdownit from 'markdown-it'
import markdownitGovuk from 'markdown-it-govuk'
const md = markdownit.use(markdownitGovuk)
The generated HTML will include the classes from GOV.UK Frontend. For example:
md.render('[A link](/foo)')
Will output:
<p class="govuk-body"><a class="govuk-link" href="/foo">A link</a></p>
Fenced code blocks can he highlighted using the supplied highlight function:
import markdownit from 'markdown-it'
import markdownitGovuk from 'markdown-it-govuk'
import highlight from 'markdown-it-govuk/highlight'
const md = markdownit({
highlight
})
md.use(markdownitGovuk)
For example:
md.render('```js\nconsole.log(\'Hello, World!\')\n```')
Will output:
<pre class="app-code app-code--block" tabindex="0">
<code class="app-code__language--js">
<span class="app-code__variable">console</span>.<span class="app-code__title">log</span>(<span class="app-code__string">'Hello, World!'</span>)
</code>
</pre>
To provide styling for inline and block code, add the following to your Sass file:
@import "markdown-it-govuk/highlight";
or using the Sass module system and pkg: importing:
@forward "pkg:markdown-it-govuk/highlight";
These styles rely on govuk-frontend, so make sure you have this installed as a dependency in your project.
| Name | Type | Description |
|---|---|---|
headingsStartWith | string | Heading size to use for the top-level heading (xl or l). Default is l. |
brand | string | Use either 'govuk' or 'nhsuk' namespaced class names. Default is 'govuk'. |
calvert | boolean | Array | Typographic improvements to enable (alongside those provided by markdown-it’s typographer option). Set this option to true to enable all improvements, or array containing individual improvement sets to include (choose from fractions, guillemets and mathematical). Default is false. |
govspeak | boolean | Array | Enable support for Govspeak extensions. Set this option to true to enable all supported extensions, or provide an array containing individual extensions to include (choose from address, blockquote, example-callout, information-callout and warning-callout). Default is false. |
Headings start with govuk-heading-l for an <h1>, govuk-heading-m for an <h2> and so on. But change it if your pages feel unbalanced – the heading class you use does not always need to correspond to the heading level.
To start pages with govuk-heading-xl for an <h1>, govuk-heading-l for an <h2>, and so on, set the headingsStartWith option to xl:
import markdownit from 'markdown-it'
import markdownitGovuk from 'markdown-it-govuk'
const md = markdownit.use(markdownitGovuk, {
headingsStartWith: 'xl'
})
md.render('# Heading\n## Heading 2')
Will output:
<h1 class="govuk-heading-xl">Heading 1</h1>
<h2 class="govuk-heading-l">Heading 2</h2>
Alongside typographic replacements provided by markdown-it’s typographer option, you can enable other glyphs present in Margaret Calvert’s GDS Transport font by using the calvert option.
For example:
import markdownit from 'markdown-it'
import markdownitGovuk from 'markdown-it-govuk'
const md = markdownit.use(markdownitGovuk, {
calvert: ['fractions', 'mathematical']
})
md.render('1/2 x 1/2 = 1/4')
Will output the following text, with the common fractions and correct multiplication symbol:
<p class="govuk-body">½ × ½ = ¼</p>
You can enable support for some Govspeak markdown extensions by using the govspeak option.
This plugin supports the following extensions:
addressblockquoteexample-calloutinformation-calloutwarning-calloutYou can enable support for all extensions by setting the option to true, or you can enable support for individual extensions by providing an array containing the names of the extensions you want to use.
import markdownit from 'markdown-it'
import markdownitGovuk from 'markdown-it-govuk'
const md = markdownit.use(markdownitGovuk, {
govspeak: true
})
To provide styling for govspeak extensions, add the following to your Sass file:
@import "markdown-it-govuk/govspeak";
or using the Sass module system and pkg: importing:
@forward "pkg:markdown-it-govuk/govspeak";
These styles rely on govuk-frontend, so make sure you have this installed as a dependency in your project.
For example:
import markdownit from 'markdown-it'
import markdownitGovuk from 'markdown-it-govuk'
const md = markdownit.use(markdownitGovuk, {
govspeak: ['address']
})
md.render(`$A
HM Revenue and Customs
Bradford
BD98 1YY
$A`)
Will output:
<div data-govspeak="address">
<p class="govuk-body">HM Revenue and Customs<br>
Bradford<br>
BD98 1YY</p>
</div>
For example:
import markdownit from 'markdown-it'
import markdownitGovuk from 'markdown-it-govuk'
const md = markdownit.use(markdownitGovuk, {
govspeak: ['blockquote']
})
md.render(`> Some text with a blockquote`)
Will output:
<blockquote data-govspeak="blockquote">
<p class="govuk-body">Some text with a blockquote</p>
</blockquote>
import markdownit from 'markdown-it'
import markdownitGovuk from 'markdown-it-govuk'
const md = markdownit.use(markdownitGovuk, {
govspeak: ['example-callout']
})
md.render(`$E
**Example callout**
Some text with an example callout
$E`)
Will output:
<div data-govspeak="example-callout">
<p class="govuk-body">
<strong>Example callout</strong>
Some text with an example callout</p>
</div>
For example:
import markdownit from 'markdown-it'
import markdownitGovuk from 'markdown-it-govuk'
const md = markdownit.use(markdownitGovuk, {
govspeak: ['information-callout']
})
md.render('^ Some text with an information callout ^')
Will output:
<div data-govspeak="information-callout" role="note" aria-label="Information">
<p class="govuk-body">Some text with an information callout</p>
</div>
For example:
import markdownit from 'markdown-it'
import markdownitGovuk from 'markdown-it-govuk'
const md = markdownit.use(markdownitGovuk, {
govspeak: ['warning-callout']
})
md.render('% Some text with a warning callout %')
Will output:
<div data-govspeak="warning-callout" role="note" aria-label="Warning">
<p class="nhsuk-body">Some text with a warning callout</p>
</div>
npm run release
This command will ask you what version you want to use. It will then publish a new version on NPM, create and push a new git tag and then generate release notes ready for posting on GitHub.
[!NOTE] Releasing a new version requires permission to publish packages to the
@x-govukorganisation.
FAQs
Plugin for markdown-it to convert Markdown into GOV.UK Frontend-compliant HTML
The npm package markdown-it-govuk receives a total of 695 weekly downloads. As such, markdown-it-govuk popularity was classified as not popular.
We found that markdown-it-govuk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.