File tree Expand file tree Collapse file tree
packages/docusaurus-theme-live-codeblock/src
website/docs/guides/markdown-features Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55 * LICENSE file in the root directory of this source tree.
66 */
77
8+ /// <reference types="@docusaurus/theme-classic" />
9+ /// <reference types="@docusaurus/module-type-aliases" />
10+
811declare module '@docusaurus/theme-live-codeblock' {
912 export type ThemeConfig = {
1013 liveCodeBlock : {
@@ -14,9 +17,12 @@ declare module '@docusaurus/theme-live-codeblock' {
1417}
1518
1619declare module '@theme/Playground' {
20+ import type { Props as BaseProps } from '@theme/CodeBlock' ;
1721 import type { LiveProviderProps } from 'react-live' ;
1822
19- export interface Props extends LiveProviderProps {
23+ type CodeBlockProps = Omit < BaseProps , 'className' | 'language' | 'title' > ;
24+
25+ export interface Props extends CodeBlockProps , LiveProviderProps {
2026 children : string ;
2127 }
2228 export default function Playground ( props : LiveProviderProps ) : JSX . Element ;
Original file line number Diff line number Diff line change @@ -93,11 +93,14 @@ export default function Playground({
9393 } = themeConfig as ThemeConfig ;
9494 const prismTheme = usePrismTheme ( ) ;
9595
96+ const noInline = props . metastring ?. includes ( 'noInline' ) ?? false ;
97+
9698 return (
9799 < div className = { styles . playgroundContainer } >
98100 { /* @ts -expect-error: type incompatibility with refs */ }
99101 < LiveProvider
100102 code = { children . replace ( / \n $ / , '' ) }
103+ noInline = { noInline }
101104 transformCode = { transformCode ?? ( ( code ) => `${ code } ;` ) }
102105 theme = { prismTheme }
103106 { ...props } >
Original file line number Diff line number Diff line change @@ -569,6 +569,42 @@ function MyPlayground(props) {
569569</BrowserWindow>
570570```
571571
572+ ### Imperative Rendering (noInline)
573+
574+ The ` noInline ` option should be used to avoid errors when your code spans multiple components or variables.
575+
576+ ```` md
577+ ``` jsx live noInline
578+ const project = ' Docusaurus' ;
579+
580+ const Greeting = () => < p> Hello {project}! < / p> ;
581+
582+ render (< Greeting / > );
583+ ```
584+ ````
585+
586+ Unlike an ordinary interactive code block, when using ` noInline ` React Live won't wrap your code in an inline function to render it.
587+
588+ You will need to explicitly call ` render() ` at the end of your code to display the output.
589+
590+ ```` mdx-code-block
591+ <BrowserWindow>
592+
593+ ```jsx live noInline
594+ const project = "Docusaurus";
595+
596+ const Greeting = () => (
597+ <p>Hello {project}!</p>
598+ );
599+
600+ render(
601+ <Greeting />
602+ );
603+ ```
604+
605+ </BrowserWindow>
606+ ````
607+
572608## Using JSX markup in code blocks { #using - jsx - markup }
573609
574610Code block in Markdown always preserves its content as plain text, meaning you can't do something like:
You can’t perform that action at this time.
0 commit comments