From a3e294b7c6ebc394e08c963eb8a4d39f0463a05e Mon Sep 17 00:00:00 2001 From: David Goss Date: Fri, 27 Nov 2026 08:25:31 +0000 Subject: [PATCH 1/3] Strip common indentation from descriptions --- src/components/gherkin/Description.spec.tsx | 23 +++++++++++++++++++++ src/components/gherkin/Description.tsx | 12 ++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/components/gherkin/Description.spec.tsx b/src/components/gherkin/Description.spec.tsx index dc793306..e7c50682 100644 --- a/src/components/gherkin/Description.spec.tsx +++ b/src/components/gherkin/Description.spec.tsx @@ -39,4 +39,27 @@ So that I can be happy` '

As a user
\nI want to do stuff
\nSo that I can be happy

' ) }) + + it('removes common indentation carried over from the source', () => { + const description = ` Beware that some formatters + use the _media type_. + + ## Notes` + const { container, getByRole } = render() + expect(container.querySelector('pre')).to.be.null + expect(container).to.contain.html( + '

Beware that some formatters
\nuse the media type.

' + ) + expect(getByRole('heading', { name: 'Notes' })).to.be.visible + }) + + it('preserves relative indentation within the description', () => { + const description = ` Here is some art: + + /\\_/\\ + ( o.o )` + const { container } = render() + expect(container).to.contain.html('

Here is some art:

') + expect(container.querySelector('pre')?.textContent).to.eq(' /\\_/\\\n ( o.o )\n') + }) }) diff --git a/src/components/gherkin/Description.tsx b/src/components/gherkin/Description.tsx index 8b922565..f6a7b3d2 100644 --- a/src/components/gherkin/Description.tsx +++ b/src/components/gherkin/Description.tsx @@ -9,6 +9,16 @@ import { } from '../customise/index.js' import defaultStyles from './Description.module.scss' +// Gherkin keeps the source file's indentation, which Markdown would otherwise treat as code blocks +function dedent(text: string): string { + const lines = text.split('\n') + const indents = lines + .filter((line) => line.trim() !== '') + .map((line) => line.match(/^[ \t]*/)?.[0].length ?? 0) + const common = Math.min(...indents) + return lines.map((line) => line.slice(common)).join('\n') +} + const DefaultRenderer: DefaultComponent = ({ description, styles, @@ -18,7 +28,7 @@ const DefaultRenderer: DefaultComponent = } return (
- +
) } From 051772e08b3bc43ef94f1e40521e99f851689db7 Mon Sep 17 00:00:00 2001 From: David Goss Date: Fri, 27 Nov 2026 08:25:41 +0000 Subject: [PATCH 2/3] Add changelog entry for description indentation fix --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 740a33ed..45a13ef0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Fixed +- Strip common indentation from descriptions so they don't render as code blocks ([#586](https://github.com/cucumber/react-components/pull/586)) ## [24.5.0] - 2026-09-28 ### Added From a2426069586e5b65c4d5bdd998df2101afd7445a Mon Sep 17 00:00:00 2001 From: David Goss Date: Fri, 27 Nov 2026 08:28:05 +0000 Subject: [PATCH 3/3] Tweak CHANGELOG.md wording --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45a13ef0..ba843941 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Fixed -- Strip common indentation from descriptions so they don't render as code blocks ([#586](https://github.com/cucumber/react-components/pull/586)) +- Strip common indentation from descriptions ([#586](https://github.com/cucumber/react-components/pull/586)) ## [24.5.0] - 2026-09-28 ### Added