File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ const logger = getLogger('py-script');
9
9
10
10
export function make_PyScript ( runtime : Runtime ) {
11
11
class PyScript extends HTMLElement {
12
+ srcCode : string
13
+
12
14
async connectedCallback ( ) {
13
15
if ( this . hasAttribute ( 'output' ) ) {
14
16
const deprecationMessage = (
@@ -19,6 +21,10 @@ export function make_PyScript(runtime: Runtime) {
19
21
showWarning ( deprecationMessage )
20
22
}
21
23
ensureUniqueId ( this ) ;
24
+ // Save innerHTML information in srcCode so we can access it later
25
+ // once we clean innerHTML (which is required since we don't want
26
+ // source code to be rendered on the screen)
27
+ this . srcCode = this . innerHTML ;
22
28
const pySrc = await this . getPySrc ( ) ;
23
29
this . innerHTML = '' ;
24
30
pyExec ( runtime , pySrc , this ) ;
@@ -36,7 +42,7 @@ export function make_PyScript(runtime: Runtime) {
36
42
throw e
37
43
}
38
44
} else {
39
- return htmlDecode ( this . innerHTML ) ;
45
+ return htmlDecode ( this . srcCode ) ;
40
46
}
41
47
}
42
48
}
Original file line number Diff line number Diff line change @@ -276,3 +276,19 @@ def test_deprecated_globals(self):
276
276
"Direct usage of sys is deprecated. Please use import sys instead." ,
277
277
"Direct usage of create is deprecated. Please use pyscript.create instead." ,
278
278
]
279
+
280
+ def test_getPySrc_returns_source_code (self ):
281
+ self .pyscript_run (
282
+ """
283
+ <py-script>
284
+ print("hello world!")
285
+ </py-script>
286
+ """
287
+ )
288
+
289
+ pyscript_tag = self .page .locator ("py-script" )
290
+ assert pyscript_tag .inner_html () == ""
291
+ assert (
292
+ pyscript_tag .evaluate ("node => node.getPySrc()" )
293
+ == 'print("hello world!")\n '
294
+ )
You can’t perform that action at this time.
0 commit comments