Skip to content

Commit

Permalink
website: highlight code (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrixx authored Nov 20, 2024
1 parent 1370b54 commit 78a1c0c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions website/public/js/wasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ const main = () => {
main();

const update = async (fixers, locale, content, resultElt, phpCodeElt, resultContentElt) => {
resultElt.classList.remove('u-d(none)');
const phpCode = buildPhpCode(fixers, locale, content);
phpCodeElt.textContent = phpCode
const phpCode = buildPhpFixerCode(fixers, locale, content);
const phpHighlighCode = buildPhpHighlighCode(phpCode);
phpCodeElt.innerHTML = await runPhpCode(phpHighlighCode);
resultContentElt.textContent = await runPhpCode(phpCode);
resultElt.classList.remove('u-d(none)');
}

const buildPhpCode = (fixers, locale, content) => {
const buildPhpFixerCode = (fixers, locale, content) => {
return `<?php
require_once '/app/vendor/autoload.php';
Expand All @@ -68,6 +69,13 @@ $fixer->setLocale(${JSON.stringify(locale)});
echo $fixer->fix(${JSON.stringify(content)});`;
};

const buildPhpHighlighCode = (phpCode) => {
return `<?php
echo nl2br(highlight_string(<<<'PHP'
${phpCode}
PHP, true));`;
};

const runPhpCode = async (phpCode) => {
FS.unlink('/app/src/index.php')
FS.writeFile('/app/src/index.php', phpCode);
Expand Down

0 comments on commit 78a1c0c

Please sign in to comment.