FIX correctly parse links inside callout blocks

This commit is contained in:
Guy Sartorelli 2024-02-02 12:23:33 +13:00
parent f619b4ba19
commit 7dd05e61c5
No known key found for this signature in database
GPG Key ID: F313E3B9504D496A
2 changed files with 7 additions and 3 deletions

View File

@ -1,12 +1,16 @@
import { ReactElement, createElement } from 'react'; import { ReactElement, createElement } from 'react';
import { DomElement, HTMLReactParserOptions, domToReact } from "html-react-parser";
import CalloutBlock from '../components/CalloutBlock'; import CalloutBlock from '../components/CalloutBlock';
/** /**
* Turn [hint] and other callouts into a proper React component. * Turn [hint] and other callouts into a proper React component.
* @param data * @param data
*/ */
const parseCalloutTags = (type: string, content: any): ReactElement|false => { const parseCalloutTags = (type: string, domChildren: DomElement[], parseOptions: HTMLReactParserOptions): ReactElement|false => {
return createElement(CalloutBlock, { type, content }); return createElement(CalloutBlock, {
type,
content: domToReact(domChildren, parseOptions),
});
}; };
export default parseCalloutTags; export default parseCalloutTags;

View File

@ -55,7 +55,7 @@ const parseHTML = (html: string): ReactElement | ReactElement[] | string => {
} }
// Remove the type marker and render the component // Remove the type marker and render the component
firstTextNode.data = firstTextNode.data.replace(calloutTypeRegex, ''); firstTextNode.data = firstTextNode.data.replace(calloutTypeRegex, '');
return parseCalloutTags(matches[1], domToReact(children)); return parseCalloutTags(matches[1], children, parseOptions);
} }
} }
} }