Skip to content

Commit

Permalink
[Examples] Fix shader code indentation (#5811)
Browse files Browse the repository at this point in the history
  • Loading branch information
kungfooman authored Nov 9, 2023
1 parent 1bae963 commit 395c97a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions examples/src/app/helpers/strings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,17 @@ function countLeadingSpaces(str) {
* @returns {string} Same code, but removed reduddant spaces.
*/
function removeRedundantSpaces(code) {
const n = Math.min(...code.split('\n').filter(Boolean).map(countLeadingSpaces));
const lines = code
.split('\n')
.slice(0, -1) // ignore last line - it's just used for nice template-string indentation
.filter(_ => Boolean(_.trim())) // ignore spaces-only lines
.map(countLeadingSpaces);
if (!lines.length) {
return code;
}
const n = Math.min(...lines);
const removeSpacesRegExp = new RegExp(' '.repeat(n), 'g');
const prettyCode = code.replace(removeSpacesRegExp, '');
const prettyCode = code.replace(removeSpacesRegExp, '').trim() + '\n';
return prettyCode;
}

Expand Down

0 comments on commit 395c97a

Please sign in to comment.