diff --git a/package-lock.json b/package-lock.json index b81b30e51..a4edf5f72 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "hasInstallScript": true, "license": "SEE LICENSE IN LICENSE", "dependencies": { - "@defra/forms-model": "^3.0.580", + "@defra/forms-model": "^3.0.584", "@defra/hapi-tracing": "^1.29.0", "@elastic/ecs-pino-format": "^1.5.0", "@hapi/boom": "^10.0.1", @@ -31,6 +31,7 @@ "blankie": "^5.0.0", "blipp": "^4.0.2", "btoa": "^1.2.1", + "chokidar": "3.6.0", "convict": "^6.2.4", "date-fns": "^4.1.0", "dotenv": "^17.2.3", @@ -227,6 +228,7 @@ "integrity": "sha512-e7jT4DxYvIDLk1ZHmU/m/mB19rex9sv0c2ftBtjSBv+kVM/902eh0fINUzD7UwLLNR+jU585GxUJ8/EBfAM5fw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@babel/code-frame": "^7.27.1", "@babel/generator": "^7.28.5", @@ -2046,6 +2048,7 @@ "integrity": "sha512-eohl3hKTiVyD1ilYdw9T0OiB4hnjef89e3dMYKz+mVKDzj+5IteTseASUsOB+EU9Tf6VNTCjDePcP6wkDGmLKQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@keyv/serialize": "^1.1.1" } @@ -2138,6 +2141,7 @@ } ], "license": "MIT", + "peer": true, "engines": { "node": ">=18" }, @@ -2161,6 +2165,7 @@ } ], "license": "MIT", + "peer": true, "engines": { "node": ">=18" } @@ -2213,9 +2218,9 @@ } }, "node_modules/@defra/forms-model": { - "version": "3.0.580", - "resolved": "https://registry.npmjs.org/@defra/forms-model/-/forms-model-3.0.580.tgz", - "integrity": "sha512-t96bN6V0wmLkIHPHMf5XDEbzDl5ARj3cPqBo09h5lSzQzP6qDtME6PVx4acZNmnFUBgkRkgYsY/xuwK5Gz2Cgw==", + "version": "3.0.584", + "resolved": "https://registry.npmjs.org/@defra/forms-model/-/forms-model-3.0.584.tgz", + "integrity": "sha512-hghONjBY8ho7Z7I/QRwYT70Ot5BStPO5rbtaSsGMMhjOsiXM93+jGmclr8rw1A3w5DTiqmaagbtX1lgDojcSjg==", "license": "OGL-UK-3.0", "dependencies": { "@joi/date": "^2.1.1", @@ -5238,6 +5243,7 @@ "integrity": "sha512-R48VhmTJqplNyDxCyqqVkFSZIx1qX6PzwqgcXn1olLrzxcSBDlOsbtcnQuQhNtnNiJ4Xe5gREI1foajYaYU2Vg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@eslint-community/regexpp": "^4.10.0", "@typescript-eslint/scope-manager": "8.46.4", @@ -5268,6 +5274,7 @@ "integrity": "sha512-tK3GPFWbirvNgsNKto+UmB/cRtn6TZfyw0D6IKrW55n6Vbs7KJoZtI//kpTKzE/DUmmnAFD8/Ca46s7Obs92/w==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "8.46.4", "@typescript-eslint/types": "8.46.4", @@ -6010,6 +6017,7 @@ "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", "dev": true, "license": "MIT", + "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -6165,7 +6173,6 @@ "version": "3.1.3", "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", - "devOptional": true, "license": "ISC", "dependencies": { "normalize-path": "^3.0.0", @@ -6739,7 +6746,6 @@ "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", "integrity": "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==", "license": "MIT", - "optional": true, "engines": { "node": ">=8" }, @@ -6805,7 +6811,6 @@ "version": "3.0.3", "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", - "devOptional": true, "license": "MIT", "dependencies": { "fill-range": "^7.1.1" @@ -6834,6 +6839,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "baseline-browser-mapping": "^2.8.25", "caniuse-lite": "^1.0.30001754", @@ -6953,6 +6959,7 @@ "integrity": "sha512-eohl3hKTiVyD1ilYdw9T0OiB4hnjef89e3dMYKz+mVKDzj+5IteTseASUsOB+EU9Tf6VNTCjDePcP6wkDGmLKQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@keyv/serialize": "^1.1.1" } @@ -7092,7 +7099,7 @@ "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", "license": "MIT", - "optional": true, + "peer": true, "dependencies": { "anymatch": "~3.1.2", "braces": "~3.0.2", @@ -8594,6 +8601,7 @@ "deprecated": "This version is no longer supported. Please see https://eslint.org/version-support for other options.", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", @@ -8829,6 +8837,7 @@ "integrity": "sha512-whOE1HFo/qJDyX4SnXzP4N6zOWn79WhnCUY/iDR0mPfQZO8wcYE4JClzI2oZrhBnnMUCBCHZhO6VQyoBU95mZA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@rtsao/scc": "^1.1.0", "array-includes": "^3.1.9", @@ -9005,6 +9014,7 @@ "integrity": "sha512-6TyDmZ1HXoFQXnhCTUjVFULReoBPOAjpuiKELMkeP40yffI/1ZRO+d9ug/VC6fqISo2WkuIBk3cvuRPALaWlOQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", "builtins": "^5.0.1", @@ -9081,6 +9091,7 @@ "integrity": "sha512-57Zzfw8G6+Gq7axm2Pdo3gW/Rx3h9Yywgn61uE/3elTCOePEHVrn2i5CdfBwA1BLK0Q0WqctICIUSqXZW/VprQ==", "dev": true, "license": "ISC", + "peer": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" }, @@ -9435,7 +9446,6 @@ "version": "7.1.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", - "devOptional": true, "license": "MIT", "dependencies": { "to-regex-range": "^5.0.1" @@ -9598,7 +9608,6 @@ "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", - "dev": true, "hasInstallScript": true, "license": "MIT", "optional": true, @@ -9824,7 +9833,6 @@ "version": "5.1.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", - "devOptional": true, "license": "ISC", "dependencies": { "is-glob": "^4.0.1" @@ -10540,7 +10548,6 @@ "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", "license": "MIT", - "optional": true, "dependencies": { "binary-extensions": "^2.0.0" }, @@ -10671,7 +10678,6 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", - "devOptional": true, "license": "MIT", "engines": { "node": ">=0.10.0" @@ -10740,7 +10746,6 @@ "version": "4.0.3", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", - "devOptional": true, "license": "MIT", "dependencies": { "is-extglob": "^2.1.1" @@ -10786,7 +10791,6 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", - "devOptional": true, "license": "MIT", "engines": { "node": ">=0.12.0" @@ -11189,6 +11193,7 @@ "integrity": "sha512-F26gjC0yWN8uAA5m5Ss8ZQf5nDHWGlN/xWZIh8S5SRbsEKBovwZhxGd6LJlbZYxBgCYOtreSUyb8hpXyGC5O4A==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@jest/core": "30.2.0", "@jest/types": "30.2.0", @@ -12238,6 +12243,7 @@ "integrity": "sha512-ekilCSN1jwRvIbgeg/57YFh8qQDNbwDb9xT/qu2DAHbFFZUicIl4ygVaAvzveMhMVr3LnpSKTNnwt8PoOfmKhQ==", "dev": true, "license": "MIT", + "peer": true, "bin": { "jiti": "lib/jiti-cli.mjs" } @@ -12247,6 +12253,7 @@ "resolved": "https://registry.npmjs.org/joi/-/joi-17.13.3.tgz", "integrity": "sha512-otDA4ldcIx+ZXsKHWmp0YizCweVRZG96J10b0FevjfuncLO1oX59THoAmHkNubYJ+9gWsYsp5k8v4ib6oDv1fA==", "license": "BSD-3-Clause", + "peer": true, "dependencies": { "@hapi/hoek": "^9.3.0", "@hapi/topo": "^5.1.0", @@ -12315,6 +12322,7 @@ "integrity": "sha512-Cvc9WUhxSMEo4McES3P7oK3QaXldCfNWp7pl2NNeiIFlCoLr3kfq9kb1fxftiwk1FLV7CvpvDfonxtzUDeSOPg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "cssstyle": "^4.2.1", "data-urls": "^5.0.0", @@ -13291,7 +13299,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", - "devOptional": true, "license": "MIT", "engines": { "node": ">=0.10.0" @@ -13805,7 +13812,6 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", - "devOptional": true, "license": "MIT", "engines": { "node": ">=8.6" @@ -14121,6 +14127,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "nanoid": "^3.3.11", "picocolors": "^1.1.1", @@ -14697,6 +14704,7 @@ "integrity": "sha512-8sLjZwK0R+JlxlYcTuVnyT2v+htpdrjDOKuMcOVdYjt52Lh8hWRYpxBPoKx/Zg+bcjc3wx6fmQevMmUztS/ccA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "cssesc": "^3.0.0", "util-deprecate": "^1.0.2" @@ -14977,7 +14985,6 @@ "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", "license": "MIT", - "optional": true, "dependencies": { "picomatch": "^2.2.1" }, @@ -15950,6 +15957,7 @@ "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", @@ -16713,6 +16721,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "@csstools/css-parser-algorithms": "^3.0.5", "@csstools/css-tokenizer": "^3.0.4", @@ -17010,6 +17019,10 @@ "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", "dev": true, "license": "MIT", + "dependencies": { + "cssesc": "^3.0.0", + "util-deprecate": "^1.0.2" + }, "engines": { "node": ">=8" } @@ -17451,6 +17464,7 @@ "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=12" }, @@ -17489,7 +17503,6 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", - "devOptional": true, "license": "MIT", "dependencies": { "is-number": "^7.0.0" @@ -17595,6 +17608,7 @@ "integrity": "sha512-ytQKuwgmrrkDTFP4LjR0ToE2nqgy886GpvRSpU0JAnrdBYppuY5rLkRUYPU1yCryb24SsKBTL/hlDQAEFVwtZg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "esbuild": "~0.25.0", "get-tsconfig": "^4.7.5" @@ -17729,6 +17743,7 @@ "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "dev": true, "license": "Apache-2.0", + "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -17988,6 +18003,7 @@ "integrity": "sha512-7h/weGm9d/ywQ6qzJ+Xy+r9n/3qgp/thalBbpOi5i223dPXKi04IBtqPN9nTd+jBc7QKfvDbaBnFipYp4sJAUQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@types/eslint-scope": "^3.7.7", "@types/estree": "^1.0.8", @@ -18056,6 +18072,7 @@ "integrity": "sha512-MfwFQ6SfwinsUVi0rNJm7rHZ31GyTcpVE5pgVA3hwFRb7COD4TzjUUwhGWKfO50+xdc2MQPuEBBJoqIMGt3JDw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@discoveryjs/json-ext": "^0.6.1", "@webpack-cli/configtest": "^3.0.1", diff --git a/package.json b/package.json index 983060f37..6c7d8224d 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ }, "license": "SEE LICENSE IN LICENSE", "dependencies": { - "@defra/forms-model": "^3.0.580", + "@defra/forms-model": "^3.0.584", "@defra/hapi-tracing": "^1.29.0", "@elastic/ecs-pino-format": "^1.5.0", "@hapi/boom": "^10.0.1", @@ -91,6 +91,7 @@ "blankie": "^5.0.0", "blipp": "^4.0.2", "btoa": "^1.2.1", + "chokidar": "3.6.0", "convict": "^6.2.4", "date-fns": "^4.1.0", "dotenv": "^17.2.3", diff --git a/src/server/forms/components.json b/src/server/forms/components.json index 802e90ecf..b77878eb5 100644 --- a/src/server/forms/components.json +++ b/src/server/forms/components.json @@ -139,7 +139,7 @@ "type": "Markdown", "name": "markdown", "title": "Title", - "content": "### This is a H3 in markdown\n\n[An internal link](http://localhost:3009/fictional-page)\n\n[An external link](https://defra.gov.uk/fictional-page)", + "content": "# Markdown - This is H1\n## This is H2\n### This is H3\n#### This is H4\n##### This is H5\n###### This is H6\n\n[An internal link](http://localhost:3009/fictional-page)\n\n[An external link](https://defra.gov.uk/fictional-page)", "options": {}, "schema": {} }, @@ -147,7 +147,7 @@ "type": "DeclarationField", "name": "declaration", "title": "Declaration", - "content": "By submitting this form, I agree to:\n\n- Provide accurate and complete information\n- Comply with all applicable regulations\n- Accept responsibility for any false statements", + "content": "# H1\nBy submitting this form, I agree to:\n\n- Provide accurate and complete information\n- Comply with all applicable regulations\n- Accept responsibility for any false statements", "hint": "Please read and confirm the following terms", "options": { "required": false diff --git a/src/server/plugins/engine/components/DeclarationField.test.ts b/src/server/plugins/engine/components/DeclarationField.test.ts index cab3f77c3..5e46697b2 100644 --- a/src/server/plugins/engine/components/DeclarationField.test.ts +++ b/src/server/plugins/engine/components/DeclarationField.test.ts @@ -11,6 +11,8 @@ import { } from '~/src/server/plugins/engine/components/helpers/components.js' import { FormModel } from '~/src/server/plugins/engine/models/FormModel.js' import definition from '~/test/form/definitions/blank.js' +import declarationWithGuidance from '~/test/form/definitions/declaration-with-guidance.js' +import declarationWithoutGuidance from '~/test/form/definitions/declaration-without-guidance.js' import { getFormData, getFormState } from '~/test/helpers/component-helpers.js' describe('DeclarationField', () => { @@ -481,4 +483,26 @@ describe('DeclarationField', () => { expect(DeclarationField.isBool(true)).toBe(true) }) }) + + describe('Markdown header starting level', () => { + test('should determine startHeadingLevel is 3 some guidance', () => { + const modelDecl = new FormModel(declarationWithGuidance, { + basePath: 'test' + }) + const field = modelDecl.componentMap.get( + 'declarationField' + ) as DeclarationField + expect(field.headerStartLevel).toBe(3) + }) + + test('should determine startHeadingLevel is 2 when no guidance', () => { + const modelDecl = new FormModel(declarationWithoutGuidance, { + basePath: 'test' + }) + const field = modelDecl.componentMap.get( + 'declarationField' + ) as DeclarationField + expect(field.headerStartLevel).toBe(2) + }) + }) }) diff --git a/src/server/plugins/engine/components/DeclarationField.ts b/src/server/plugins/engine/components/DeclarationField.ts index d76fdb00d..870466792 100644 --- a/src/server/plugins/engine/components/DeclarationField.ts +++ b/src/server/plugins/engine/components/DeclarationField.ts @@ -1,4 +1,10 @@ -import { type DeclarationFieldComponent, type Item } from '@defra/forms-model' +import { + ComponentType, + hasFormComponents, + isFormType, + type DeclarationFieldComponent, + type Item +} from '@defra/forms-model' import joi, { type ArraySchema, type BooleanSchema, @@ -30,6 +36,7 @@ export class DeclarationField extends FormComponent { declare formSchema: ArraySchema declare stateSchema: BooleanSchema declare content: string + headerStartLevel: number constructor( def: DeclarationFieldComponent, @@ -64,6 +71,16 @@ export class DeclarationField extends FormComponent { this.content = content this.declarationConfirmationLabel = options.declarationConfirmationLabel ?? this.DEFAULT_DECLARATION_LABEL + const formComponents = hasFormComponents(props.page?.pageDef) + ? props.page.pageDef.components + : [] + const numOfQuestionsOnPage = formComponents.filter((q) => + isFormType(q.type) + ).length + const hasGuidance = formComponents.some( + (comp, idx) => comp.type === ComponentType.Markdown && idx === 0 + ) + this.headerStartLevel = numOfQuestionsOnPage < 2 && !hasGuidance ? 2 : 3 } getFormValueFromState(state: FormSubmissionState) { @@ -133,7 +150,8 @@ export class DeclarationField extends FormComponent { value: 'true', checked: isChecked } - ] + ], + headerStartLevel: this.headerStartLevel } } diff --git a/src/server/plugins/engine/components/Markdown.ts b/src/server/plugins/engine/components/Markdown.ts index c97208d7a..cbc3c7c01 100644 --- a/src/server/plugins/engine/components/Markdown.ts +++ b/src/server/plugins/engine/components/Markdown.ts @@ -5,6 +5,7 @@ import { ComponentBase } from '~/src/server/plugins/engine/components/ComponentB export class Markdown extends ComponentBase { declare options: MarkdownComponent['options'] content: MarkdownComponent['content'] + headerStartLevel: number constructor( def: MarkdownComponent, @@ -16,6 +17,7 @@ export class Markdown extends ComponentBase { this.content = content this.options = options + this.headerStartLevel = 2 } getViewModel() { @@ -23,7 +25,8 @@ export class Markdown extends ComponentBase { return { ...viewModel, - content + content, + headerStartLevel: this.headerStartLevel } } } diff --git a/src/server/plugins/engine/index.ts b/src/server/plugins/engine/index.ts index 2d82d69ff..c45ccbbc6 100644 --- a/src/server/plugins/engine/index.ts +++ b/src/server/plugins/engine/index.ts @@ -33,8 +33,11 @@ export const prepareNunjucksEnvironment = function ( env.addFilter(name, nunjucksFilter) } - env.addFilter('markdown', (text: string) => - markdownToHtml(text, pluginOptions.baseUrl) + env.addFilter('markdown', (text: string, startingHeaderLevel?: number) => + markdownToHtml(text, { + baseUrl: pluginOptions.baseUrl, + startingHeaderLevel + }) ) for (const [name, nunjucksGlobal] of Object.entries(globals)) { diff --git a/src/server/plugins/engine/views/components/declarationfield.html b/src/server/plugins/engine/views/components/declarationfield.html index 7f18e2383..8f503b8f1 100644 --- a/src/server/plugins/engine/views/components/declarationfield.html +++ b/src/server/plugins/engine/views/components/declarationfield.html @@ -5,7 +5,7 @@ {% macro DeclarationField(component) %} {% set content %}
- {{ component.model.content | markdown | safe }} + {{ component.model.content | markdown(component.model.headerStartLevel) | safe }}
{% endset %} {% set checkboxes = component.model | merge({ formGroup: { beforeInputs: { html: content } } }) %} diff --git a/src/server/plugins/engine/views/components/markdown.html b/src/server/plugins/engine/views/components/markdown.html index fb014fa5d..602bd5192 100644 --- a/src/server/plugins/engine/views/components/markdown.html +++ b/src/server/plugins/engine/views/components/markdown.html @@ -1,5 +1,5 @@ {% macro Markdown(component) %}
- {{ component.model.content | markdown | safe }} + {{ component.model.content | markdown(component.model.headerStartLevel) | safe }}
{% endmacro %} diff --git a/src/server/plugins/engine/views/confirmation.html b/src/server/plugins/engine/views/confirmation.html index 7c9fbb1a7..82b8c3cbf 100644 --- a/src/server/plugins/engine/views/confirmation.html +++ b/src/server/plugins/engine/views/confirmation.html @@ -12,7 +12,7 @@ }) }}

What happens next

- {{ submissionGuidance | markdown | safe }} + {{ submissionGuidance | markdown(3) | safe }}
diff --git a/test/form/definitions/declaration-with-guidance.js b/test/form/definitions/declaration-with-guidance.js new file mode 100644 index 000000000..e866ed7e7 --- /dev/null +++ b/test/form/definitions/declaration-with-guidance.js @@ -0,0 +1,54 @@ +export default /** @type {FormDefinition} */ ({ + startPage: '/page1', + pages: [ + { + path: '/page1', + components: [ + { + type: 'Markdown', + name: 'kklNow', + title: 'Some guidance', + options: { + required: true + }, + schema: {}, + content: '# H1\n## H2\n### H3\nOther content', + id: '1d1e3b2c-16ce-41bb-a817-a9ffd2e13e87' + }, + { + type: 'DeclarationField', + title: 'Declaration title', + name: 'declarationField', + shortDescription: 'Declaration', + content: + '# H1\r\n## H2\r\n### H3\r\n#### h4\r\n##### h5\r\n###### h6\r\n####### h7', + options: { + required: true + }, + schema: {}, + id: '3a71d9e2-ecab-4d43-8357-23fafbe8eb25' + } + ], + next: [ + { + path: '/summary' + } + ], + title: 'Some guidance' + }, + { + path: '/summary', + controller: 'SummaryPageController', + title: 'Summary', + components: [] + } + ], + lists: [], + sections: [], + phaseBanner: {}, + conditions: [] +}) + +/** + * @import { FormDefinition } from '@defra/forms-model' + */ diff --git a/test/form/definitions/declaration-without-guidance.js b/test/form/definitions/declaration-without-guidance.js new file mode 100644 index 000000000..35d51f5dc --- /dev/null +++ b/test/form/definitions/declaration-without-guidance.js @@ -0,0 +1,43 @@ +export default /** @type {FormDefinition} */ ({ + startPage: '/page1', + pages: [ + { + path: '/page1', + components: [ + { + type: 'DeclarationField', + title: 'Declaration title', + name: 'declarationField', + shortDescription: 'Declaration', + content: + '# H1\r\n## H2\r\n### H3\r\n#### h4\r\n##### h5\r\n###### h6\r\n####### h7', + options: { + required: true + }, + schema: {}, + id: '3a71d9e2-ecab-4d43-8357-23fafbe8eb25' + } + ], + next: [ + { + path: '/summary' + } + ], + title: 'Some guidance' + }, + { + path: '/summary', + controller: 'SummaryPageController', + title: 'Summary', + components: [] + } + ], + lists: [], + sections: [], + phaseBanner: {}, + conditions: [] +}) + +/** + * @import { FormDefinition } from '@defra/forms-model' + */