I use pastebin to store most of my hacks' source codes and to embed them into this blog. Pastebin was today updated to version 3.1, and it broke the embeds. On my blog's first page the sidebar had fallen to the bottom of the page because of an imbalance in div elements' opening and closing tags. I fixed the first page, but on consequent pages the sidebar might still drop, and embeds contain this 'ss="javascript">' bug. And the code is not syntax highlighted. I notified this to pastebin admin, hope it gets fixed soon. Codes can still be copied like before by clicking the "Download Raw" link.
Update 3 hours later: Pastebin embeds fixed.
Just another blog with Blogspot hacks and tips, made/customized by me.
Showing posts with label pastebin. Show all posts
Showing posts with label pastebin. Show all posts
Saturday, February 18, 2012
3
Pastebin embeds temporarily broken
Friday, October 14, 2011
1
Publishing syntax highlighted code in Blogger
This was tougher than I first thought. I thought that I'll just install SyntaxHighlighter, and that's it. But not quite.
First I installed SyntaxHighlighter 2.x, according to some instructions on the net. It had some problems, so after a few days, I switched to newest version, 3.0.83.
Publishing code between <pre> tags is a bit problematic alltogether. One must escape some characters, like > and < to > and <, to allow for example html to be shown. So there's always this extra step.
The most problematic thing with SyntaxHighlighter is that it changed left intendation spaces to non breaking spaces. That is mainly cosmetic, but can result in nasty looking  :s in template, although harmless. As some sort of a perfectionist I could not let this be.
So my final (at least at this point in time) solution, which I came up yesterday, is to use pastebin.com to host those (longer) code snippets, that are supposed to be copied by user. Other codes may still be shown by SyntaxHighlighter. I styled SyntaxHighlighter and Pastebin codes to look similar.
Example, first pastebin:
Then SyntaxHighlighter:
The best way for user to copy pastebin codes is to click the Download Raw link, and to copy SyntaxHighlighter codes is to doubleclick the code. Of course mouse selection and copy can be used, but depending on browser that might also copy the line numbers. Hopefully my blog's readers are able to figure these out.
First I installed SyntaxHighlighter 2.x, according to some instructions on the net. It had some problems, so after a few days, I switched to newest version, 3.0.83.
Publishing code between <pre> tags is a bit problematic alltogether. One must escape some characters, like > and < to > and <, to allow for example html to be shown. So there's always this extra step.
The most problematic thing with SyntaxHighlighter is that it changed left intendation spaces to non breaking spaces. That is mainly cosmetic, but can result in nasty looking  :s in template, although harmless. As some sort of a perfectionist I could not let this be.
So my final (at least at this point in time) solution, which I came up yesterday, is to use pastebin.com to host those (longer) code snippets, that are supposed to be copied by user. Other codes may still be shown by SyntaxHighlighter. I styled SyntaxHighlighter and Pastebin codes to look similar.
Example, first pastebin:
Data provided by Pastebin.com - Download Raw
Then SyntaxHighlighter:
<script type='text/javascript'>
//<![CDATA[
// make pastebin.com raw links open in target="_blank"
var clss = document.getElementsByClassName("embedFooter");
for (var x=0 ; x < clss.length; x++ )
{
var child = clss[x].firstChild;
while(child) {
if(child.nodeType == 1 && child.tagName.toLowerCase() == 'a')
child.target="_blank";
child = child.nextSibling;
}
}
//]]>
</script>
Internet Explorer needed some styling for its own, that one I figured out this morning, there was for example a persistent vertical scrollbar on SyntaxHighligter code snippets. But I got those sorted out. Finally I coded the above script to make the "Download Raw" link open the code in a new window.The best way for user to copy pastebin codes is to click the Download Raw link, and to copy SyntaxHighlighter codes is to doubleclick the code. Of course mouse selection and copy can be used, but depending on browser that might also copy the line numbers. Hopefully my blog's readers are able to figure these out.
Labels:
pastebin,
syntax highlighting,
syntaxhighlighter,
tip
Short URLs:
tinyurl.com,
goo.gl,
safe.mn,
v.gd,
cli.gs


Subscribe to:
Posts (Atom)