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 {
77 js ?: string ;
88 base ?: string ;
99 scripts ?: string [ ] ;
10+ instanceMode ?: boolean ;
1011}
1112
1213/*
@@ -44,7 +45,7 @@ ${code.css || ""}
4445</style>
4546<!-- If we need an addon script, load p5 the usual way with no caching to make sure
4647the 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' ) }
4849<body>${ code . htmlBody || "" } </body>
4950<script id="code" type="text/javascript">${ wrapSketch ( code . js ) || "" } </script>
5051${ ( code . scripts ?. length ?? 0 ) > 0 ? '' : `
@@ -161,6 +162,7 @@ export const CodeFrame = (props: CodeFrameProps) => {
161162 htmlBody : props . htmlBodyCode ,
162163 base : props . base ,
163164 scripts : props . scripts ,
165+ instanceMode : props . jsCode . includes ( 'new p5' ) ,
164166 } ) : undefined }
165167 sandbox = "allow-scripts allow-popups allow-modals allow-forms allow-same-origin"
166168 aria-label = "Code Preview"
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ export const CodeEmbed = (props) => {
3636 ) ;
3737
3838 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 ) ;
4040 if ( canvasMatch ) {
4141 previewWidth = previewWidth || parseFloat ( canvasMatch [ 1 ] ) ;
4242 previewHeight = previewHeight || parseFloat ( canvasMatch [ 2 ] ) ;
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import { setJumpToState } from "../globals/state";
2121import { p5Version } from " ../globals/p5-version" ;
2222import flask from " @src/content/ui/images/icons/flask.svg?raw" ;
2323import warning from " @src/content/ui/images/icons/warning.svg?raw" ;
24+ import _ from ' lodash' ;
2425
2526const { entry, relatedEntries } = Astro .props ;
2627const currentLocale = getCurrentLocale (Astro .url .pathname );
@@ -121,9 +122,9 @@ const descriptionParts = description.split(
121122 )}
122123 { descriptionParts .map ((part ) => {
123124 if (part .startsWith (' <pre' )) {
124- const exampleCode = part
125+ const exampleCode = _ . unescape ( part
125126 .replace (/ <pre><code class="language-js example">/ , ' ' )
126- .replace (/ <\/ code><\/ pre>/ , ' ' );
127+ .replace (/ <\/ code><\/ pre>/ , ' ' )) ;
127128
128129 return (
129130 <CodeEmbed
You can’t perform that action at this time.
0 commit comments