Featured Post

No Tears

As we take my wife to her resting place today, no tears. That was her mantra over the past few weeks. She took that from her father, as it w...

Wednesday, September 23, 2020

Testing code blocks in Blogger

So after I posted my tribute to my deceased dad here on Blogger, I wondered if I could use Blogger to post code. After a number of false starts, I have chosen the easiest way for me to do so. Here's a step by step for you.

  • Type out your text. Insert markers where your code should go. Markers should be a separate paragraph with easily findable text, like:

    [SNIPPET #1 GOES HERE]
  • Create a new gist for each post. Create a new file in the gist for each snippet.
  • Copy the embed link from the gist.
  • Switch to "HTML view" in Blogger.
  • Locate each snippet marker and remove just the tags around it. I usually start at the marker and work left until I find an end tag. Then I know that the tag to the right of the end tag is the start of my snippet. The tags may be spans and font settings.
  • Once you have removed all the tags, replace the snippet marker with the embed link. Add "?file=somefilename" to the embed link to limit to one file in the gist.
  • Switch back to "Compose view."
  • Preview. You won't see anything in Compose view.
  • Voila!
Here is the whole gist:
<p><span style="font-family: inherit;">So after I posted my tribute to my deceased dad here on Blogger, I wondered if I could use Blogger to post code. After a number of false starts, I have chosen the easiest way for me to do so. Here's a step by step for you.</span></p><p></p><ul style="text-align: left;"><li><span style="font-family: inherit;">Type out your text. Insert markers where your code should go. Markers should be a separate paragraph with easily findable text, like:<br /><br />[SNIPPET #1 GOES HERE]</span></li><li>Create a new gist for each post. Create a new file in the gist for each snippet.</li><li>Copy the embed link from the gist.</li><li>Switch to "HTML view" in Blogger.<br /></li><li>Locate each snippet marker and remove just the tags around it. I usually start at the marker and work left until I find an end tag. Then I know that the tag to the right of the end tag is the start of my snippet. The tags may be spans and font settings.</li><li>Once you have removed all the tags, replace the snippet marker with the embed link. Add "?file=somefilename" to the embed link to limit to one file in the gist.</li><li>Switch back to "Compose view."<br /></li><li>Preview. You won't see anything in Compose view.</li><li>Voila!</li></ul><div>Sample:</div><div><br /></div><div>Here is the whole gist:</div><script src="https://gist.github.com/matthewpersico/c5ae8f9e178c65bd1f2c43134d031380.js"></script><span><div><br /></div><span></span><div>Here is just one file in the gist:</div><script src="https://gist.github.com/matthewpersico/c5ae8f9e178c65bd1f2c43134d031380.js?file=snippet1.pl"></script><span></span><div><br /><br /><br /></div><span></span></span><br />
view raw post.html hosted with ❤ by GitHub
my $junk = 42;
if ($junk == 42) {
print("This is snippet1, indent2");
}
view raw snippet1.pl hosted with ❤ by GitHub
my $junk = 42;
if ($junk == 42) {
print("This is snippet2, indent 4");
}
view raw snippet2.pl hosted with ❤ by GitHub

Here is just one file in the gist:
my $junk = 42;
if ($junk == 42) {
print("This is snippet1, indent2");
}
view raw snippet1.pl hosted with ❤ by GitHub

As a reference, the first file in the first snip above (post.html) contains the entire HTML for this post as it was BEFORE I added this line and everything below it.

And thanks to Low Level Manager for the final piece - syntax for adding the filename to the embed to limit the snip to one file. 

Tuesday, September 22, 2020