From 69232395fd90de67babb0663b85287608c264df3 Mon Sep 17 00:00:00 2001 From: Aaron Carlino Date: Wed, 13 Nov 2019 11:14:12 +1300 Subject: [PATCH] Clean up partial API tags' --- src/utils/cleanApiTags.ts | 8 ++++++++ src/utils/parseHTML.ts | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/utils/cleanApiTags.ts 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 {