From 52334ed604bdd2e13e19ea0688e0e3a02d999142 Mon Sep 17 00:00:00 2001 From: Brandon Mathis Date: Wed, 27 Jul 2011 00:08:38 -0400 Subject: [PATCH] added docs for github-style codeblocks --- source/_includes/head.html | 2 +- source/_layouts/default.html | 2 +- source/docs/blogging/code/test/index.markdown | 44 +++++++++---------- .../github-style-codeblock/index.markdown | 38 ++++++++++++++++ source/javascripts/octopress.js | 13 +----- 5 files changed, 63 insertions(+), 36 deletions(-) create mode 100644 source/docs/plugins/github-style-codeblock/index.markdown diff --git a/source/_includes/head.html b/source/_includes/head.html index 34fb222..d04d0d0 100644 --- a/source/_includes/head.html +++ b/source/_includes/head.html @@ -1,7 +1,7 @@ - + {{site.title}}{% if page.title %}: {{page.title}}{% endif %} diff --git a/source/_layouts/default.html b/source/_layouts/default.html index 5b6240d..f633343 100644 --- a/source/_layouts/default.html +++ b/source/_layouts/default.html @@ -5,7 +5,7 @@
- {{ content | expand_urls: root_url | smart_quotes }} + {{ content | expand_urls: root_url | backtick_codeblock | smart_quotes }} {% unless page.sidebar == false %} {% endunless %} diff --git a/source/docs/blogging/code/test/index.markdown b/source/docs/blogging/code/test/index.markdown index c36b9c9..c685870 100644 --- a/source/docs/blogging/code/test/index.markdown +++ b/source/docs/blogging/code/test/index.markdown @@ -7,28 +7,28 @@ sidebar: false {% include_code javascripts/test.js %} -{% codeblock Testing html files (test.html) %} - - -A Tiny Page - - - -

abc

-

def

-

Testing page

- -{% endcodeblock %} +``` html + + + A Tiny Page + + + +

abc

+

def

+

Testing page

+ +``` {% gist 996818 %} diff --git a/source/docs/plugins/github-style-codeblock/index.markdown b/source/docs/plugins/github-style-codeblock/index.markdown new file mode 100644 index 0000000..7639934 --- /dev/null +++ b/source/docs/plugins/github-style-codeblock/index.markdown @@ -0,0 +1,38 @@ +--- +layout: page +title: "Github Style Codeblock" +date: 2011-07-26 23:42 +sidebar: false +footer: false +--- + +With the `backtick_codeblock` filter you can use Github's lovely back tick syntax highlighting blocks. +Simply start a line with three back ticks followed by a space and the language you're using. Tab in four spaces +for your code snippets, and then finish your code block with three more back ticks. + +#### Syntax + + ``` language + code snippet + ``` + +### Example + + ``` ruby + class Fixnum + def prime? + ('1' * self) !~ /^1?$|^(11+?)\1+$/ + end + end + ``` + +``` ruby + class Fixnum + def prime? + ('1' * self) !~ /^1?$|^(11+?)\1+$/ + end + end +``` + +This is a nice, lightweight way to add a highlighted code snippet. For features like titles and links you'll want to look +at the `codeblock` or `include_code` liquid tags. diff --git a/source/javascripts/octopress.js b/source/javascripts/octopress.js index 12ca23e..5266ecb 100644 --- a/source/javascripts/octopress.js +++ b/source/javascripts/octopress.js @@ -48,8 +48,7 @@ function testFeatures() { function addCodeLineNumbers(){ if (navigator.appName == 'Microsoft Internet Explorer') { return } - $('div.highlight pre code').each(function(el){ addDivLines(el); }); - $('div.highlight, div.gist-highlight').each(function(code){ + $('div.gist-highlight').each(function(code){ var tableStart = '
'; var lineNumbers = '
';
     var tableMiddle = '
'; @@ -62,16 +61,6 @@ function addCodeLineNumbers(){ $(code).html(table); }); } -function addDivLines(el){ - var content = $(el).html(); - var lines = content.replace(/\s*$/g, '').split(/\n/); - var count = lines.length; - $(lines).each(function(line, index){ - if(line == '') line = ' '; - lines[index] = '
' + line + '
'; - }); - $(el).html(lines.join('')); -} function flashVideoFallback(){ var flashplayerlocation = "/assets/jwplayer/player.swf",