docusaurus-live-brython 3.0.0-beta.26 → 3.0.0-beta.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/theme/CodeBlock/index.tsx"],"names":[],"mappings":";;AACA,OAAkB,EAAE,KAAK,KAAK,IAAI,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAOtD,KAAK,KAAK,GAAG,YAAY,CAAC,OAAO,aAAa,CAAC,CAAC;AAsChD,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,GAAG,CAAC,OAAO,CA2BlE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/theme/CodeBlock/index.tsx"],"names":[],"mappings":";;AACA,OAAkB,EAAE,KAAK,KAAK,IAAI,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAOtD,KAAK,KAAK,GAAG,YAAY,CAAC,OAAO,aAAa,CAAC,CAAC;AAsChD,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,GAAG,CAAC,OAAO,CA0BlE"}
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import CodeBlock from '@theme-init/CodeBlock';
3
- import ContextEditor from '@theme/CodeEditor/ContextEditor';
3
+ import ContextEditor, { splitCode } from '@theme/CodeEditor/ContextEditor';
4
4
  import BrowserOnly from '@docusaurus/BrowserOnly';
5
5
  const sanitizedTitle = (id) => {
6
6
  if (!id) {
@@ -44,8 +44,8 @@ export default function CodeBlockWrapper(props) {
44
44
  // }
45
45
  if (metaProps.live_py) {
46
46
  const title = props.title || metaProps.title;
47
- const rawcode = (props.children || '').replace(/\s*\n$/, '');
48
- return (<BrowserOnly fallback={<CodeBlock {...props}/>}>
47
+ const { code } = splitCode(props.children || '');
48
+ return (<BrowserOnly fallback={<CodeBlock language={lang}>{code}</CodeBlock>}>
49
49
  {() => {
50
50
  return (<ContextEditor {...props} {...metaProps} title={sanitizedTitle(title) || lang}>
51
51
  {props.children}
@@ -6,6 +6,11 @@ interface Props extends MetaProps {
6
6
  children: string | React.ReactNode;
7
7
  onChange?: (code: string) => void;
8
8
  }
9
+ export declare const splitCode: (rawCode: string) => {
10
+ pre: string;
11
+ code: string;
12
+ post: string;
13
+ };
9
14
  /**
10
15
  * Use this component when you want a working CodeEditor.
11
16
  * The CodeEditor must be wrapped in a ScriptContext - this component does that.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/ContextEditor/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAmB,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAI/D,UAAU,KAAM,SAAQ,SAAS;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC;IACnC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC;AAYD;;;;;GAKG;AACH,QAAA,MAAM,aAAa,UAAW,KAAK,sBA0ClC,CAAC;AAEF,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/theme/CodeEditor/ContextEditor/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAmB,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAI/D,UAAU,KAAM,SAAQ,SAAS;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC;IACnC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC;AAGD,eAAO,MAAM,SAAS,YAAa,MAAM;;;;CAOxC,CAAC;AAEF;;;;;GAKG;AACH,QAAA,MAAM,aAAa,UAAW,KAAK,sBA0ClC,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -4,7 +4,7 @@ import CodeEditor from '@theme/CodeEditor';
4
4
  import ScriptContext from '@theme/CodeEditor/WithScript/ScriptContext';
5
5
  import CodeBlock from '@theme/CodeBlock';
6
6
  const SPLIT_CODE_REGEX = /^(?:(?<pre>.*?)\n###\s*PRE\s*)?(?<code>.*?)(?:\n###\s*POST\s*(?<post>.*))?$/s;
7
- const splitCode = (rawCode) => {
7
+ export const splitCode = (rawCode) => {
8
8
  const { pre, code, post } = rawCode.replace(/\s*\n$/, '').match(SPLIT_CODE_REGEX).groups || {};
9
9
  return {
10
10
  pre: pre || '',
@@ -18,7 +18,7 @@ const ScriptContext = (props) => {
18
18
  return (<BrowserOnly fallback={<CodeBlock language={props.lang}>{props.code}</CodeBlock>}>
19
19
  {() => {
20
20
  if (!store) {
21
- return <div>Load</div>;
21
+ return <CodeBlock language={props.lang}>{props.code}</CodeBlock>;
22
22
  }
23
23
  return <Context.Provider value={store}>{props.children}</Context.Provider>;
24
24
  }}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docusaurus-live-brython",
3
- "version": "3.0.0-beta.26",
3
+ "version": "3.0.0-beta.27",
4
4
  "description": "Docusaurus live code block component for python.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -4,7 +4,7 @@ import type { WrapperProps } from '@docusaurus/types';
4
4
  import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
5
5
  import { type MetaProps } from '@theme/CodeEditor';
6
6
 
7
- import ContextEditor from '@theme/CodeEditor/ContextEditor';
7
+ import ContextEditor, { splitCode } from '@theme/CodeEditor/ContextEditor';
8
8
  import BrowserOnly from '@docusaurus/BrowserOnly';
9
9
 
10
10
  type Props = WrapperProps<typeof CodeBlockType>;
@@ -57,10 +57,9 @@ export default function CodeBlockWrapper(props: Props): JSX.Element {
57
57
  // }
58
58
  if (metaProps.live_py) {
59
59
  const title = props.title || metaProps.title;
60
-
61
- const rawcode: string = ((props.children as string) || '').replace(/\s*\n$/, '');
60
+ const { code } = splitCode((props.children as string) || '');
62
61
  return (
63
- <BrowserOnly fallback={<CodeBlock {...props} />}>
62
+ <BrowserOnly fallback={<CodeBlock language={lang}>{code}</CodeBlock>}>
64
63
  {() => {
65
64
  return (
66
65
  <ContextEditor {...props} {...metaProps} title={sanitizedTitle(title) || lang}>
@@ -12,7 +12,7 @@ interface Props extends MetaProps {
12
12
  }
13
13
 
14
14
  const SPLIT_CODE_REGEX = /^(?:(?<pre>.*?)\n###\s*PRE\s*)?(?<code>.*?)(?:\n###\s*POST\s*(?<post>.*))?$/s;
15
- const splitCode = (rawCode: string) => {
15
+ export const splitCode = (rawCode: string) => {
16
16
  const { pre, code, post } = rawCode.replace(/\s*\n$/, '').match(SPLIT_CODE_REGEX).groups || {};
17
17
  return {
18
18
  pre: pre || '',
@@ -25,7 +25,7 @@ const ScriptContext = (props: InitState & { children: React.ReactNode }) => {
25
25
  <BrowserOnly fallback={<CodeBlock language={props.lang}>{props.code}</CodeBlock>}>
26
26
  {() => {
27
27
  if (!store) {
28
- return <div>Load</div>;
28
+ return <CodeBlock language={props.lang}>{props.code}</CodeBlock>;
29
29
  }
30
30
  return <Context.Provider value={store}>{props.children}</Context.Provider>;
31
31
  }}