1
1
import phpBinary from "/js/php-web.mjs" ;
2
2
3
+ function generateExampleOutputTitle ( phpVersion ) {
4
+ return "Output of the above example in PHP " + phpVersion + ":" ;
5
+ }
6
+
3
7
function createOutput ( output ) {
4
8
const container = document . createElement ( "div" ) ;
5
9
container . classList . add ( "screen" , "example-contents" ) ;
6
10
const title = document . createElement ( "p" ) ;
7
- title . innerText = "Output (PHP " + PHP . version + "):" ;
11
+ title . innerText = generateExampleOutputTitle ( PHP . version ) ;
8
12
container . appendChild ( title ) ;
9
13
const div = document . createElement ( "div" ) ;
10
14
div . classList . add ( "examplescode" ) ;
@@ -56,6 +60,15 @@ async function main() {
56
60
return ;
57
61
}
58
62
63
+ const exampleTitleContainer = example . nextElementSibling ;
64
+ let exampleTitleParagraphElement = null ;
65
+ let exampleScreenPreElement = null ;
66
+ if ( exampleTitleContainer !== null ) {
67
+ exampleTitleParagraphElement = exampleTitleContainer . querySelector ( "p" )
68
+ const exampleScreenContainer = exampleTitleContainer . nextElementSibling ;
69
+ exampleScreenPreElement = exampleScreenContainer . querySelector ( "pre" ) ;
70
+ }
71
+
59
72
const code = phpcode . querySelector ( "code" ) ;
60
73
code . spellcheck = false ;
61
74
code . setAttribute ( "contentEditable" , true ) ;
@@ -68,8 +81,13 @@ async function main() {
68
81
69
82
const runPhp = await PHP . loadPhp ( ) ;
70
83
runPhp ( phpcode . innerText ) ;
71
- lastOutput = createOutput ( PHP . buffer . join ( "" ) ) ;
72
- phpcode . parentNode . appendChild ( lastOutput ) ;
84
+ if ( exampleScreenPreElement !== null ) {
85
+ exampleTitleParagraphElement . innerText = generateExampleOutputTitle ( PHP . version ) ;
86
+ exampleScreenPreElement . innerText = PHP . buffer . join ( "" ) ;
87
+ } else {
88
+ lastOutput = createOutput ( PHP . buffer . join ( "" ) ) ;
89
+ phpcode . parentNode . appendChild ( lastOutput ) ;
90
+ }
73
91
PHP . buffer . length = 0 ;
74
92
} ;
75
93
0 commit comments