Skip to content

Demotes H1 in markdown if required#1197

Merged
jbarnsley10 merged 4 commits intomainfrom
feat/DF-480-demote-h1
Nov 24, 2025
Merged

Demotes H1 in markdown if required#1197
jbarnsley10 merged 4 commits intomainfrom
feat/DF-480-demote-h1

Conversation

@jbarnsley10
Copy link
Copy Markdown
Contributor

@jbarnsley10 jbarnsley10 commented Nov 13, 2025

Ticket DF-480

Demotes any H1-6 from the starting level supplied. For example, if the starting level is 2, any H1's will become H2's, H2's will become H3's etc. If the starting level is 3, any H1's will become H3's and so on.
This is to ensure there is only one H1 on the page (either the page/component title, or an H1 from within the markdown), and that the rest of the page's heading flow down in order.

In tandem with forms-engine-plugin PR DEFRA/forms-engine-plugin#246

@sonarqubecloud
Copy link
Copy Markdown

@jbarnsley10 jbarnsley10 marked this pull request as ready for review November 14, 2025 13:39
Copy link
Copy Markdown
Contributor

@alexluckett alexluckett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed - agreed to move this towards a contextual rendering where the entire hierarchy is demoted.

<div class="govuk-form-group">
<div class="{{ model.declaration.classes }}">
{{ model.declaration.text | markdown | safe }}
{{ model.declaration.text | markdown({ startingHeaderLevel: 2 }) | safe }}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this for the guidance/markdown component too?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nailed it, otherwise 👌

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. It's been a while so I've forgotten what was going on. I'll check 😀

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guidance/markdown is covered in the changes to file markdown.js in this PR. I tested the preview and it's all fine.

@jbarnsley10 jbarnsley10 merged commit 2bf705d into main Nov 24, 2025
18 of 20 checks passed
@jbarnsley10 jbarnsley10 deleted the feat/DF-480-demote-h1 branch November 24, 2025 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants