-
Notifications
You must be signed in to change notification settings - Fork 18
chore: mdxish cleanup #1353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
chore: mdxish cleanup #1353
Changes from 9 commits
91918ee
8953da4
037833c
b99ea83
d70d1a1
6bdea11
4849cf6
45d1c46
159f335
5e47943
9912224
0cc9888
5f0397d
f3fbea3
5ee167e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,8 +1,54 @@ | ||||||
| import type { Element, Root, RootContent } from 'hast'; | ||||||
|
|
||||||
| import * as rdmd from '@readme/markdown-legacy'; | ||||||
|
|
||||||
| import { vi } from 'vitest'; | ||||||
|
|
||||||
| import { run, compile, migrate as baseMigrate, mdastV6 } from '../index'; | ||||||
| import { type RMDXModule } from '../types'; | ||||||
|
|
||||||
| export function findElementByTagName(node: Root | RootContent, tagName: string): Element | null { | ||||||
| if ('type' in node && node.type === 'element' && 'tagName' in node && node.tagName === tagName) { | ||||||
| return node; | ||||||
| } | ||||||
|
|
||||||
| if ('children' in node && Array.isArray(node.children)) { | ||||||
| return node.children.reduce<Element | null>((found, child) => { | ||||||
| if (found) return found; | ||||||
| return findElementByTagName(child, tagName); | ||||||
| }, null); | ||||||
| } | ||||||
|
|
||||||
| return null; | ||||||
| } | ||||||
|
|
||||||
| export function findElementsByTagName(node: Root | RootContent, tagName: string): Element[] { | ||||||
| const results: Element[] = []; | ||||||
|
|
||||||
| if ('type' in node && node.type === 'element' && 'tagName' in node && node.tagName === tagName) { | ||||||
| results.push(node); | ||||||
| } | ||||||
|
|
||||||
| if ('children' in node && Array.isArray(node.children)) { | ||||||
| node.children.forEach(child => { | ||||||
| results.push(...findElementsByTagName(child, tagName)); | ||||||
| }); | ||||||
| } | ||||||
|
|
||||||
| return results; | ||||||
| } | ||||||
|
Comment on lines
+10
to
+41
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ty for moving these into shared helpers, cleans up so much repetetive code! |
||||||
|
|
||||||
| export const stubModule = { | ||||||
| default: () => null, | ||||||
| Toc: null, | ||||||
| toc: [], | ||||||
| } as unknown as RMDXModule; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor detail but is it possible to avoid casting with an assertion here?
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay yea this makes sense but requires us to change this basically adding the |
||||||
|
|
||||||
| export const makeComponents = (...names: string[]) => | ||||||
| names.reduce<Record<string, RMDXModule>>((acc, name) => { | ||||||
| acc[name] = stubModule; | ||||||
| return acc; | ||||||
| }, {}); | ||||||
|
|
||||||
| export const silenceConsole = | ||||||
| (prop: keyof Console = 'error', impl = () => {}) => | ||||||
|
|
||||||
This file was deleted.
This file was deleted.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.