alphagov / govuk-prototype-kit-docs

Site for the GOV.UK Prototype Kit
https://prototype-kit.service.gov.uk/docs
MIT License
3 stars 2 forks source link

Generate and implement heading captions #37

Closed domoscargin closed 2 years ago

domoscargin commented 2 years ago

Done when

Captions will be added to this spreadsheet: https://docs.google.com/spreadsheets/d/1Y-c8e_syvu2hT8jLr0yNKigNAGpf1yU7WJlal3iLSIs/edit#gid=573269404

Detail

On some documentation pages, we have a caption frontmatter property. This defines the h1's caption content.

There are two easy ways that I can see to generate this caption (and one slightly more involved way):

  1. hardcode the span in the markdown like such:

<span class="govuk-caption-xl">govuk-caption-xl</span>

This creates a problem: marked wraps <span> elements in a paragraph. So we could either add an empty wrapping <div>, or use a custom renderer for <p> elements in marked.

  1. Insert the caption into the HTML string.

Once we have our generated HTML string, we could find the <h1> and insert the caption before it. I don't think there should be any case where we need to caption an <h2> or higher, and the <h1> should be quite early in the HTML string, so hopefully it wouldn't be a particularly large performance hit.

  1. A custom marked extension for <span> elements https://marked.js.org/using_pro#extensions

We could potentially do some extra logic here to cover the captions.

Other issues to consider

We may potentially have to define the heading/caption size in the frontmatter if we want to use different sizes on different pages.

lfdebrux commented 2 years ago

Chatted to @domoscargin about this to get more context, as it's not immediately clear where the captions come from.

The captions were added in PR alphagov/govuk-prototype-kit#1186, as part of the content review of the prototype kit pages. The idea of the caption was that it would be the same as the sections on the docs index page, to help the user see where they are in the documentation; for instance, all the pages in the make-first-prototype folder have the same caption, 'Build a basic prototype', except for start.md, which has the title 'Build a basic prototype', and starts the journey.

We might decide that actually this feature isn't needed, and close this PR, but at least now what we might be missing out on 😁

trang-erskine commented 2 years ago

Blocked until @NoraGDS is back from leave

Izabela-16 commented 2 years ago

@NoraGDS please have a look and if you will have any questions then please shout.

NoraGDS commented 2 years ago

Captions in column G: https://docs.google.com/spreadsheets/d/1Y-c8e_syvu2hT8jLr0yNKigNAGpf1yU7WJlal3iLSIs/edit#gid=573269404

lfdebrux commented 2 years ago

This work needs to be moved to the alphagov/govuk-prototype-kit-docs repo.