#028: Code Syntax Highlighting, Part 2

(Updated on )

We’ve just installed Prism.js and got it working.

In this screencast we find a theme called the Tomorrow Theme and ingrate it’s colors into the syntax highlighting. We make a little color key at the top of the file for quick reference. We also make some guesses as to what is what, at least to start. What we end up with, color wise, is OK but not spectacular. If you browse around the site today, you’ll notice the color theme is more like Twilight, which I used to love in TextMate and I’m currently loving in Sublime Text 2.

We finish up by adding the header bars to code snippets. We don’t have actual markup do this (which is probably good, it’s mostly just a decorator) we add it through using a pseudo element and generated content via the rel attribute on the code. Most of the existing code on CSS-Tricks has this attribute. If it doesn’t, not a big deal. We aren’t really using rel in the correct way here, but I’m not overly worried about it.

pre[rel]:before {
  content: attr(rel);
}

We run into a little problem with making that pseudo element 100% wide with padding. Turns out our box-sizing declaration on the * selector doesn’t affect pseudo elements (kinda makes sense), so we update our Normalize to include that.