Browse Source

Fixed issue with printing empty lines

master
Ben Ashton 2 years ago
parent
commit
09c3942f34
  1. 3
      README.md
  2. 3
      src/template_engine.js

3
README.md

@ -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:

3
src/template_engine.js

@ -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…
Cancel
Save