Skip to content

Commit

Permalink
FIX Resolve final callout block issues (#285)
Browse files Browse the repository at this point in the history
* FIX Remove unnecessary space at the end of callout blocks

* FIX correctly parse links inside callout blocks
  • Loading branch information
GuySartorelli authored Feb 2, 2024
1 parent fc34b76 commit 8ce02bc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/theme/assets/scss/theme/_docs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@
font-size: 1rem;
}

.content p:last-of-type {
// Don't add unnecessary space at the end of a callout block
.content > :last-child {
margin-bottom: 0;
}

Expand Down
8 changes: 6 additions & 2 deletions src/utils/parseCalloutTags.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { ReactElement, createElement } from 'react';
import { DomElement, HTMLReactParserOptions, domToReact } from "html-react-parser";
import CalloutBlock from '../components/CalloutBlock';

/**
* Turn [hint] and other callouts into a proper React component.
* @param data
*/
const parseCalloutTags = (type: string, content: any): ReactElement|false => {
return createElement(CalloutBlock, { type, content });
const parseCalloutTags = (type: string, domChildren: DomElement[], parseOptions: HTMLReactParserOptions): ReactElement|false => {
return createElement(CalloutBlock, {
type,
content: domToReact(domChildren, parseOptions),
});
};

export default parseCalloutTags;
2 changes: 1 addition & 1 deletion src/utils/parseHTML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const parseHTML = (html: string): ReactElement | ReactElement[] | string => {
}
// Remove the type marker and render the component
firstTextNode.data = firstTextNode.data.replace(calloutTypeRegex, '');
return parseCalloutTags(matches[1], domToReact(children));
return parseCalloutTags(matches[1], children, parseOptions);
}
}
}
Expand Down

0 comments on commit 8ce02bc

Please sign in to comment.