File tree Expand file tree Collapse file tree 3 files changed +7
-4
lines changed Expand file tree Collapse file tree 3 files changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ interface CodeBundle {
7
7
js ?: string ;
8
8
base ?: string ;
9
9
scripts ?: string [ ] ;
10
+ instanceMode ?: boolean ;
10
11
}
11
12
12
13
/*
@@ -44,7 +45,7 @@ ${code.css || ""}
44
45
</style>
45
46
<!-- If we need an addon script, load p5 the usual way with no caching to make sure
46
47
the import order doesn't get messed up. -->
47
- ${ ( ( code . scripts ?. length ?? 0 ) > 0 ? [ cdnLibraryUrl , ...( code . scripts ?? [ ] ) ] : [ ] ) . map ( ( src ) => `<script type="text/javascript" src="${ src } "></script>` ) . join ( '\n' ) }
48
+ ${ ( code . instanceMode || ( code . scripts ?. length ?? 0 ) > 0 ? [ cdnLibraryUrl , ...( code . scripts ?? [ ] ) ] : [ ] ) . map ( ( src ) => `<script type="text/javascript" src="${ src } "></script>` ) . join ( '\n' ) }
48
49
<body>${ code . htmlBody || "" } </body>
49
50
<script id="code" type="text/javascript">${ wrapSketch ( code . js ) || "" } </script>
50
51
${ ( code . scripts ?. length ?? 0 ) > 0 ? '' : `
@@ -161,6 +162,7 @@ export const CodeFrame = (props: CodeFrameProps) => {
161
162
htmlBody : props . htmlBodyCode ,
162
163
base : props . base ,
163
164
scripts : props . scripts ,
165
+ instanceMode : props . jsCode . includes ( 'new p5' ) ,
164
166
} ) : undefined }
165
167
sandbox = "allow-scripts allow-popups allow-modals allow-forms allow-same-origin"
166
168
aria-label = "Code Preview"
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ export const CodeEmbed = (props) => {
36
36
) ;
37
37
38
38
let { previewWidth, previewHeight } = props ;
39
- const canvasMatch = / c r e a t e C a n v a s \( \s * ( \d + ) , \s * ( \d + ) \s * (?: , \s * (?: P 2 D | W E B G L ) \s * ) ? \) / m. exec ( initialCode ) ;
39
+ const canvasMatch = / c r e a t e C a n v a s \( \s * ( \d + ) , \s * ( \d + ) \s * (?: , \s * (?: \w + \. ) ? (?: P 2 D | W E B G L ) \s * ) ? \) / m. exec ( initialCode ) ;
40
40
if ( canvasMatch ) {
41
41
previewWidth = previewWidth || parseFloat ( canvasMatch [ 1 ] ) ;
42
42
previewHeight = previewHeight || parseFloat ( canvasMatch [ 2 ] ) ;
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import { setJumpToState } from "../globals/state";
21
21
import { p5Version } from " ../globals/p5-version" ;
22
22
import flask from " @src/content/ui/images/icons/flask.svg?raw" ;
23
23
import warning from " @src/content/ui/images/icons/warning.svg?raw" ;
24
+ import _ from ' lodash' ;
24
25
25
26
const { entry, relatedEntries } = Astro .props ;
26
27
const currentLocale = getCurrentLocale (Astro .url .pathname );
@@ -121,9 +122,9 @@ const descriptionParts = description.split(
121
122
)}
122
123
{ descriptionParts .map ((part ) => {
123
124
if (part .startsWith (' <pre' )) {
124
- const exampleCode = part
125
+ const exampleCode = _ . unescape ( part
125
126
.replace (/ <pre><code class="language-js example">/ , ' ' )
126
- .replace (/ <\/ code><\/ pre>/ , ' ' );
127
+ .replace (/ <\/ code><\/ pre>/ , ' ' )) ;
127
128
128
129
return (
129
130
<CodeEmbed
You can’t perform that action at this time.
0 commit comments