Fixed issue with printing empty lines

This commit is contained in:
Ben Ashton 2022-09-03 01:09:58 -06:00
parent da3898432a
commit 09c3942f34
2 changed files with 3 additions and 3 deletions

View File

@ -48,12 +48,10 @@ printf '%s' "$title" | jq -Rrj @html;
printf '%s\n' '</h1>';
printf '%s\n' ' <p>From the following restaurants:</p>';
printf '%s\n' ' <ul>';
printf '%s' '';
while read restaurant; do
printf '%s' ' <li>';
printf '%s' "$restaurant" | jq -Rrj @html;
printf '%s\n' '</li>';
printf '%s' '';
done <restaurants.txt
printf '%s\n' ' </ul>';
printf '%s\n' ' <p>';
@ -64,7 +62,6 @@ printf '%s\n' '</strong>';
printf '%s\n' ' </p>';
printf '%s\n' ' </body>';
printf '%s\n' '</html>';
printf '%s' '';
```
Which when executed might produce the following HTML:

View File

@ -72,6 +72,9 @@ export class TemplateEngine {
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
const isLastLine = i === lines.length - 1;
if (isLastLine && !line.length) break;
const formatString = isLastLine ? '%s' : '%s\\n';
buffer += `printf '${formatString}' '${line.replace("'", "'\\''")}';\n`;