[PHP-WEBMASTER] [web-php] master: don't render before/after whitespace in interactive examples

Author: Jordi Kroon (jordikroon)
Committer: Derick Rethans (derickr)
Date: 2026-06-10T19:07:26+01:00

Commit: don't render before/after whitespace in interactive examples · php/web-php@f5020dd · GitHub
Raw diff: https://github.com/php/web-php/commit/f5020dd5855f787314d77a67643180d3cbfe29bf.diff

don't render before/after whitespace in interactive examples

Changed paths:
  M js/interactive-examples.js

Diff:

diff --git a/js/interactive-examples.js b/js/interactive-examples.js
index 7f2d41e90c..eb296c94df 100644
--- a/js/interactive-examples.js
+++ b/js/interactive-examples.js
@@ -94,11 +94,13 @@ async function main() {

       const runPhp = await PHP.loadPhp();
       runPhp(phpcode.innerText);
+ const output = PHP.buffer.join("").replace(/^\n+|\n+$/g, "");
+
       if (exampleScreenPreElement !== null) {
         exampleTitleParagraphElement.innerText = generateExampleOutputTitle(PHP.version);
- exampleScreenPreElement.innerText = PHP.buffer.join("");
+ exampleScreenPreElement.innerText = output;
       } else {
- lastOutput = createOutput(PHP.buffer.join(""));
+ lastOutput = createOutput(output);
         phpcode.parentNode.appendChild(lastOutput);
       }
       PHP.buffer.length = 0;