💾 Archived View for midnight.pub › replies › 41 captured on 2022-04-28 at 20:28:11. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
This is to see of code/pre tags work in Midnight Pub posts.
So here are the two pieces of code whose high-level description (when combined) transforms text into Mignight Pub friendly text/tags (huh... but I see I used two Lua scripts - not one Lua and one bash as first reported);
The "y1" script:
<pre><code>#! /usr/bin/env lua<br>local lines = {}<br>for line in io.stdin:lines() do<br>table.insert(lines, line)<br>end<br>local url = ''<br>if arg[1] then<br>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>io.stdout:write('><br>>')<br>for i=1,num_url_spaces do<br>io.stdout:write(' ')<br>end<br>print('- ' .. arg[1])<br>end<br></code></pre>
The "quote-br" script called by the "y1" script:
<pre><code>#! /usr/bin/env lua<br>local lines = {}<br>for line in io.stdin:lines() do<br>table.insert(lines, '> ' .. line .. '<br>')<br>end<br>io.stdout:write(table.concat(lines, ''))<br></code></pre>
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> table.insert(lines, line)<br>end<br>local url = ''<br>if arg[1] then<br> 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> io.stdout:write('><br>>')<br> for i=1,num_url_spaces do<br> io.stdout:write(' ')<br> end<br> 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> if arg[1] then<br> local whitespace,rest = string.match(line, '^(%s+)(.*)