-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: run content tests on all MDX files inside
./puzzles
- Loading branch information
1 parent
43d1502
commit d240f46
Showing
5 changed files
with
247 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// ----------------------------------------------------------------------------- | ||
// Constants | ||
// ----------------------------------------------------------------------------- | ||
|
||
const P1 = /(_jsxs|_jsx)\(_components.[a-zA-Z-_0-9]+/g; | ||
const P2 = /(_jsxs|_jsx)\("[a-zA-Z-_0-9]+"/g; | ||
const P3 = /(_jsxs|_jsx)\([a-zA-Z-_0-9]+/g; | ||
export const JSX_ELEMENTS_PATTERN = new RegExp(`${P1.source}|${P2.source}|${P3.source}`, 'g'); | ||
|
||
// ----------------------------------------------------------------------------- | ||
// Function | ||
// ----------------------------------------------------------------------------- | ||
|
||
const getUniqueElementsFromMDXSource = (mdxSource: string): string[] => { | ||
const elements = mdxSource.match(JSX_ELEMENTS_PATTERN) ?? []; | ||
|
||
return [ | ||
...new Set( | ||
[...new Set(elements)].map((e) => { | ||
let e_ = e; | ||
// Remove `_jsxs(` and `_jsx(` from the beginning of the string. | ||
if (e.startsWith('_jsxs(')) e_ = e.substring(6); | ||
else if (e.startsWith('_jsx(')) e_ = e.substring(5); | ||
|
||
// Remove `"` from the beginning and end of the string or remove | ||
// `_components.` from the beginning of the string. | ||
if (e_.startsWith('"') && e_.endsWith('"')) e_ = e_.substring(1, e_.length - 1); | ||
else if (e_.startsWith('_components.')) e_ = e_.substring(12); | ||
|
||
return e_; | ||
}), | ||
), | ||
]; | ||
}; | ||
|
||
export default getUniqueElementsFromMDXSource; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import getUniqueElementsFromMDXSource from './get-unique-elements-from-mdx-source'; | ||
import readFile from './read-file'; | ||
import serializeToMDXSource from './serialize-to-mdx-source'; | ||
|
||
export { readFile, serializeToMDXSource }; | ||
export { getUniqueElementsFromMDXSource, readFile, serializeToMDXSource }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.