Tuesday, December 20, 2011

Code Blocks in Git-Scribe

‹prev | My Chain | next›

With my last remaining PhantomJS questions answered last night, I think I am ready to bid a fond adieu to Backbone.js. I will still have need of the occasional follow-up post, but the regular material needed to support Recipes with Backbone is complete. And so, I turn my attention back to my toolchain for generating ebooks, git-scribe.

Between the time that I wrote The SPDY Book and Recipes with Backbone, there was quite a bit of activity on git-scribe. Much of it was fairly exciting. One of the features added was one with I had wrestled unsuccessfully: code-highlighting.

The thing about highlighting is that not all highlighters are created equal. The code in our book ended up looking like:

In Emacs, by contrast, methods properties and top-level class names are highlighted:

That coupled with an unsatisfactory control over the page size led my co-author, Nick Gauthier, and I to stick with my my fork of git-scribe. I hope to take a few days now ideally to switch back over to the mainstream git-scribe. Failing that, I hope to at least get a little closer.

Tonight, I start with the getting closer. One of the annoyances in my git-scribe fork is that code sample can span pages:

That just sucks. Fortunately there's a commit for that. A commit, that is, in the upstream version of git-scribe. I am already tracking upstream, so I can just cherry-pick that into my local copy:
➜  git-scribe git:(master)  git cherry-pick 8e35785
Now, to test that out. It is not exactly the kind of thing that I can BDD since the desired output is entirely visual. So I start with the bit of code that was not wrapping previously. I delete enough lines so that it is just at the bottom of one page:

Then I add just enough text to add one line of text above that code sample and re-check the output:

Yay! The one line that would have otherwise pushed a single line of a closing parenthesis onto the next page now sends the entire code block onto the next page.

That is a small victory, but I'll take it. If nothing else, it is a good way to get me back in the swing of git-scribe coding and I can definitely make use of that immediately to improve Recipes with Backbone.

Day #240

No comments:

Post a Comment