Amnesiac Programmer
Setting up SyntaxHighlighter in SquareSpace 6

1 Comment

Share

Setting up SyntaxHighlighter in SquareSpace 6

SyntaxHighlighter can produce very clear code highlighting but getting it to work in Squarespace 6 is not straightforward. In this post I describe how I got it running in current browsers.

Installation

In the gist linked HERE you can find code to add to the Code Injection section in the Settings of your Squarespace website. Place the contents of the Header file in the Header area and the contents of the Footer file in the Footer area.

The Header section has to be edited to add the languages to be used (brush in SyntaxHighlighter lingo). In the Footer section, the default language has to be set. Here it is set to the C brush:

brush: js
// Default brush
var brush = "brush: c";

Once configured, any code block will use the default configuration. If you want to change the language of the code, write the language selection on the first line of the code block, as follows:

brush: c
brush: c
int main() {
   return 0;
}

In the above example the C brush is selected. Refer to this SyntaxHighlighter page for other available brushes.

Some examples

A C example:

brush: c
int main(int argc, char **argc) {
   for (int n = 0; n < argc; n++) {
      printf("Argument %d: %s", n, argv[n]);
   }
   return 0;
}

Technical explanation for the curious-minded

The main trick that we need to do to get SyntaxHighlighter to work in Squarespace is annotate the 'code' tag with a class that contains the brush to use:

brush: xml
<code class="brush: c">
int main() {
   return 0;
}
</code>

In the Footer code, this is done by using JQuery. A default language is assigned if this is not overiden in the first line.

In addition, there seems to be a bug in Squarespace where data-preserve-html-node="true" is added for code that looks like an HTML tag inside a markdown block. As longs as Squarespace does not fix this, the behavior is fixed in the Footer code.

1 Comment

Share

Comment

Share

Image naming conventions in Xcode

While developing a very simple SpriteKit game I wanted to have different images for different device resolutions using atlases. While there are plenty of pages describing how to include retina images (using @2X as a suffix), it was quite hard to find a description on how to specify that an image is for an iPad. Hence this post.

It turns out there is some documentation from Apple on how to do this. You can find it HERE. It does not cover the @2X suffix for retina displays. This might be described somewhere else.

For an iPad, you need to add ~ipad. Hence, the possible file names are:

  • image@2X~ipad.png: Image for retina iPad
  • image~ipad.png: Image for non-retina iPad
  • image@2X.png: Image or retina display
  • image.png: Default image

For an iPhone, the suffix is ~iphone. Hence:

  • image@2X~iphone.png: Image for retina iPhone
  • image~iphone.png: Image for non-retina iPhone
  • image@2X.png: Image on retina display
  • image.png: Default

Comment

Share

Renaming an application in Xcode 5

Comment

Share

Renaming an application in Xcode 5

In a recent project I started with a name for my iOS application and later decided to change it. I tried to rename it as described in the Apple Technical Q&A QA1625 without success. For some reason the simulators targets were gone and the iOS device target was also gone.

After several attempts i found the problem. My project was embedded in an Xcode workspace. All I had to do was open the project (not the workspace) and do the rename from there. After that, I had to relink the project in the workspace. And that was it.

Comment

Share