-
Notifications
You must be signed in to change notification settings - Fork 26
[docs-infra] Add CodeHighlighter component for loading demos and codeblocks #379
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: master
Are you sure you want to change the base?
Conversation
This reverts commit 4a91028.
I added When I added |
…ed usages in CodeHighlighterClient
…oved readability and prop handling
…dd support for sourceParser and sourceTransformers in loader checks
Is that a bug in Next.js? If so, can you open a ticket with them? |
// Set hash in URL and state | ||
const setHash = React.useCallback( | ||
(value: string | null, replace: boolean = true) => { | ||
if (typeof window === 'undefined') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe this will ever be called in a server context
if (typeof window === 'undefined') { |
/** | ||
* Hook for managing URL hash state with SSR support | ||
*/ | ||
export function useUrlHashState(options: UseUrlHashStateOptions = {}): UseUrlHashStateResult { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep these publicly exported hooks simple and to the point. The options are unnecessary, and same for anything else than hash
and setHash
. What's the point of hasUserInteraction
? It's doing nothing beyond wrapping React.useState
filename = 'file.ts', | ||
prettierConfig: PrettierOptions | boolean = true, | ||
): Promise<string> { | ||
// Babel collapses newlines all over the place, which messes with the formatting of almost any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why care about preserving formatting at all cost if we're going to run prettier over it anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is largely the code from the original https://github.com/ember-cli/babel-remove-types/blob/main/src/index.ts
I think the idea was that it would remove extra newlines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, advocate of the devil here, why are we forking this code then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mainly JSX support
Adds an isomorphic (server and client loading/parsing) and build-optimizable (via a loader) code highlighting component.
Notable Features
init
(no defer),stream
,hydration
, andidle
.js
file in the repo.Adds 947 unit tests, covering 70% of statements, 85% of branches, runs in 3 seconds on my machine
Note
The docs are added in a separate PR: #431
Install instructions with variants (remembers preference in local storage)
A demo of a codeblock
A demo within a demo
A demo of a demo with multiple variants
Linking to Demo Title Consistent with File Linking
Note
See the address bar
Read the docs for this component
Precompute Loader Docs
Read the rest of the added docs
Notes
We use ESM only packages for some things (https://www.npmjs.com/package/unified, https://www.npmjs.com/package/jsondiffpatch, etc) so CJS publishing is disabled (at least for now)