Fixed issue with printing empty lines
This commit is contained in:
parent
da3898432a
commit
09c3942f34
@ -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:
|
||||
|
@ -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`;
|
||||
|
Loading…
Reference in New Issue
Block a user