Skip to content

Commit

Permalink
[ASL-4495] Add markdown paragraph props
Browse files Browse the repository at this point in the history
Provide mechanism to apply e.g. hint text class to paragraphs generated by ReactMarkdown. Use case: when hints rendered as markdown have multiple paragraphs the external wrapper + unwrap single line stragegy doesn't work and the styling isn't applied correctly in the pdf
  • Loading branch information
jeff-horton-ho-sas committed Aug 14, 2024
1 parent 51a14e9 commit f9303a6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
36 changes: 20 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ukhomeoffice/asl-components",
"version": "13.5.1",
"version": "13.5.2",
"description": "React components for ASL layouts and elements",
"main": "src/index.jsx",
"styles": "styles/index.scss",
Expand Down
8 changes: 5 additions & 3 deletions src/markdown/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,28 @@ const components = {
};

// eslint-disable-next-line no-unused-vars
const wrapInSpanIfOnlyChild = enabled => ({ node, siblingCount, index, ...props }) => {
const wrapInSpanIfOnlyChild = (enabled, paragraphProps) => ({ node, siblingCount, index, ...props }) => {
if (enabled && siblingCount === 1) {
return <span {...props} />;
}
return <p {...props} />;

return <p {...paragraphProps} {...props} />;
};

export default function Markdown({
children,
links = false,
unwrapSingleLine = false,
significantLineBreaks = false,
paragraphProps = {},
source,
...props
}) {
return <ReactMarkdown
includeElementIndex={true}
components={{
...(!links && components),
p: wrapInSpanIfOnlyChild(unwrapSingleLine)
p: wrapInSpanIfOnlyChild(unwrapSingleLine, paragraphProps)
}}
remarkPlugins={significantLineBreaks ? [remarkBreaks] : []}
{...props}
Expand Down

0 comments on commit f9303a6

Please sign in to comment.