💾 Archived View for midnight.pub › replies › 46 captured on 2022-06-11 at 23:26:28. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2022-04-28)

➡️ Next capture (2024-08-18)

-=-=-=-=-=-=-

< Script fiddling

Parent

~inquiry

Okay, trying it one more time, this time with a bit more attention to lines beginning with whitespace:

y1:

<pre><code>#! /usr/bin/env lua<br>local lines = {}<br>for line in io.stdin:lines() do<br>&nbsp;&nbsp;table.insert(lines, line)<br>end<br>local url = ''<br>if arg[1] then<br>&nbsp;&nbsp;url = ' ' .. arg[1]<br>end<br>local handle = io.popen('fmt -60 | quote-br' .. url, 'w')<br>handle:write(table.concat(lines, ' '))<br>handle:close()<br>local num_url_spaces = 30<br>if arg[1] then<br>&nbsp;&nbsp;io.stdout:write('&gt;&lt;br&gt;&gt;')<br>&nbsp;&nbsp;for i=1,num_url_spaces do<br>&nbsp;&nbsp;&nbsp;&nbsp;io.stdout:write('&nbsp;')<br>&nbsp;&nbsp;end<br>&nbsp;&nbsp;print('- ' .. arg[1])<br>end<br></code></pre>

quote-br:

<pre><code>#! /usr/bin/env lua<br>local lines = {}<br>for line in io.stdin:lines() do<br>&nbsp;&nbsp;if arg[1] then<br>&nbsp;&nbsp;&nbsp;&nbsp;local whitespace,rest = string.match(line, '^(%s+)(.*) )<br>&nbsp;&nbsp;&nbsp;&nbsp;if whitespace then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;whitespace = string.gsub(whitespace, ' ', '&nbsp;&nbsp;')<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;whitespace = string.gsub(whitespace, '\t', '&nbsp;&nbsp;')<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if rest then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rest = string.gsub(rest, '&lt;', '&lt;')<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rest = string.gsub(rest, '&gt;', '&gt;')<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rest = ''<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line = whitespace .. rest<br>&nbsp;&nbsp;&nbsp;&nbsp;end<br>&nbsp;&nbsp;end<br>&nbsp;&nbsp;if arg[1] then<br>&nbsp;&nbsp;&nbsp;&nbsp;table.insert(lines, line .. '&lt;br&gt;')<br>&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;table.insert(lines, '&gt; ' .. line .. '&lt;br&gt;')<br>&nbsp;&nbsp;end<br>end<br>io.stdout:write(table.concat(lines, ''))<br></code></pre>

Write a reply