diff --git a/src/utils/cleanApiTags.ts b/src/utils/cleanApiTags.ts new file mode 100644 index 0000000..546854d --- /dev/null +++ b/src/utils/cleanApiTags.ts @@ -0,0 +1,8 @@ +const cleanApiTags = (html: string): string => { + return html.replace( + /\[api:(.*?)\]\s/, + (_, query) => `${query} ` + ) +}; + +export default cleanApiTags; \ No newline at end of file diff --git a/src/utils/parseHTML.ts b/src/utils/parseHTML.ts index 71b65d0..0c53265 100644 --- a/src/utils/parseHTML.ts +++ b/src/utils/parseHTML.ts @@ -1,6 +1,7 @@ import parse, { DomElement } from 'html-react-parser'; import cleanChildrenTags from './cleanChildrenTags'; import cleanWhitespace from './cleanWhitespace'; +import cleanApiTags from './cleanApiTags'; import rewriteLink from './rewriteLink'; import parseChildrenOf from './parseChildrenOf'; import cleanCalloutTags from './cleanCalloutTags'; @@ -13,9 +14,11 @@ import rewriteHeader from './rewriteHeader'; * @return ReactElement | ReactElement[] | string */ const parseHTML = (html: string): ReactElement | ReactElement[] | string => { - let cleanHTML = cleanChildrenTags(html); + let cleanHTML = html; + cleanHTML = cleanChildrenTags(cleanHTML); cleanHTML = cleanCalloutTags(cleanHTML); cleanHTML = cleanWhitespace(cleanHTML); + cleanHTML = cleanApiTags(cleanHTML); const parseOptions = { replace(domNode: DomElement): ReactElement | object | undefined | false {