npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

markdown-it-govuk

v0.8.0

Published

Plugin for markdown-it to convert Markdown into GOV.UK Frontend-compliant HTML

Readme

markdown-it-govuk · test

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.

Requirements

Node.js v22 or later.

Installation

npm install markdown-it-govuk --save

Usage

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>

Code highlighting

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.

Options

| 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. |

Heading sizes

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>

Typographic improvements

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>

Govspeak

You can enable support for some Govspeak markdown extensions by using the govspeak option.

This plugin supports the following extensions:

  • address
  • blockquote
  • example-callout
  • information-callout
  • warning-callout

You 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.

Address

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>

Blockquote

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>

Example callout

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>

Information callout

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>

Warning callout

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>

Releasing a new version

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-govuk organisation.