Midnight Pub

Script fiddling

~inquiry

THIS PAGE LEFT INTENTIONALLY BLANK


inquiry

So, for example, I copy/paste the second paragraph, above, into a vi (editor) session.

Then I copy the URL to the post containing it.

Then, in the editor, in "command mode", I execute these keystrokes with the cursor on the line containing the text:

!!y1 https://miso.town/post?id=29

which transforms the text to the right sequence of text and tags to result in this when displayed to you:

Take creating a multi-line "quote" of some lines of<br>> content, with the option to associate a URL with it, doing<br>> so in a way that helps the Midnight Pub post rendering<br>> code path "do the right thing" (i.e. what I want it to<br>> do) with respect to keeping the text to no more than 60<br>> columns, while having line breaks that *don't* cause the<br>> aforementioned code path to essentially double line break<br>> the lines by wrapping then all in html paragraph tags....<br>><br>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- https://miso.town/post?id=29

Fun!

("y1" is the name of the script... the '!!' tells vi to run the script against selected standard input, replacing it with the standard output of the command)

reply

m15o

WOOOW! This looks absolutely amazing! I love how it's simple to read with the columns being cut when too long, and how the link to the post stands out to see more. All of that done in vi with bash + lua? Darn. If you ever feel like, I'd love to see the script so I could use it as well. Cheers sir, you made my day!

reply

inquiry

Put the latest here: https://miso.town/reply?id=46

Sorry for all the clutter in this thread, but that's kind of how it goes when trying this and that.

reply

inquiry

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('&nbsp;')<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>

reply

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>

reply

inquiry

Hmmm.

So I needed to add &lt;br&gt; tags to the end of all the code lines, then much all the code lines into a single line to make it work. Not too convenient.

And then I'd need to go a step further and convert tab characters (which I prefer for indentation) to good 'ole "nbsp" entities....

&lt;gives up&gt;

reply

inquiry

And then there's the "deceptivity" of leaving around replies that refer to stuff that changed.. or refer to stuff implying a relative screen location, which also might change... it's... it's... &lt;panting&gt; oh my gosh, the insanity of it all... :-)

reply