updated docs with description of new code start, end and range options

This commit is contained in:
Brandon Mathis 2012-05-27 02:04:45 -05:00
parent b673641d4f
commit 8bf5b8a25c
4 changed files with 91 additions and 33 deletions

View File

@ -5,34 +5,34 @@ footer: false
sidebar: false
---
{% include_code javascripts/test.js %}
{% include_code test.js range:5,10 %}
``` html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<title>A Tiny Page</title>
<style type="text/css">
<!--
p { font-size:15pt; color:#000 }
-->
</style></head><!-- real comment -->
<body bgcolor="#FFFFFF" text="#000000" link="#0000CC">
<script language="javascript" type="text/javascript">
function changeHeight(h) {
var tds = document.getElementsByTagName("td");
for(var i = 0; i < tds.length; i++) {
tds[i].setAttribute("height", h + "px");
}}
</script>
<h1>abc</h1>
<h2>def</h2>
<p>Testing page</p>
</body></html>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<title>A Tiny Page</title>
<style type="text/css">
<!--
p { font-size:15pt; color:#000 }
-->
</style></head><!-- real comment -->
<body bgcolor="#FFFFFF" text="#000000" link="#0000CC">
<script language="javascript" type="text/javascript">
function changeHeight(h) {
var tds = document.getElementsByTagName("td");
for(var i = 0; i < tds.length; i++) {
tds[i].setAttribute("height", h + "px");
}}
</script>
<h1>abc</h1>
<h2>def</h2>
<p>Testing page</p>
</body></html>
```
{% gist 996818 %}
{% codeblock Testing PHP (syntax_test.php) %}
{% codeblock Testing PHP (syntax_test.php) lang:php %}
<?php
require_once($GLOBALS['g_campsiteDir']. "/$ADMIN_DIR/country/common.php");
require_once($GLOBALS['g_campsiteDir']. "/classes/SimplePager.php");

View File

@ -12,7 +12,7 @@ Simply start a line with three back ticks followed by a space and the language y
#### Syntax
``` [language] [title] [url] [link text]
``` [language] [title] [url] [link text] [start:#]
code snippet
```
@ -44,3 +44,21 @@ class Fixnum
end
end
```
#### Example with a custom starting line number
``` coffeescript Coffeescript Tricks start:51
# Given an alphabet:
alphabet = 'abcdefghijklmnopqrstuvwxyz'
# Iterate over part of the alphabet:
console.log letter for letter in alphabet[4..8]
```
``` coffeescript Coffeescript Tricks start:51
# Given an alphabet:
alphabet = 'abcdefghijklmnopqrstuvwxyz'
# Iterate over part of the alphabet:
console.log letter for letter in alphabet[4..8]
```

View File

@ -10,7 +10,7 @@ With this plugin you can write blocks of code directly in your posts and optiona
#### Syntax
{{ "{% codeblock [title] [lang:language] [url] [link text]" }} %}
{{ "{% codeblock [title] [lang:language] [start:#] [url] [link text]" }} %}
code snippet
{{ "{% endcodeblock" }} %}
@ -24,7 +24,7 @@ With this plugin you can write blocks of code directly in your posts and optiona
Awesome code snippet
{% endcodeblock %}
#### Example 2
#### Syntax highlighting
You can also add syntax highlighting like this.
@ -36,7 +36,7 @@ You can also add syntax highlighting like this.
[rectangle setX: 10 y: 10 width: 20 height: 20];
{% endcodeblock %}
#### Example 3
#### Syntax highlighting, alternate method
Including a file extension in the title enables highlighting
@ -48,7 +48,7 @@ Including a file extension in the title enables highlighting
puts "Awesome!" unless lame
{% endcodeblock %}
#### Example 4 (Force Highlighting)
#### Force highlighting
Pygments supports many languages, but doesn't recognize some file extensions.
Add `lang:your_language` to force highlighting if the filename doesn't work.
@ -61,7 +61,7 @@ Add `lang:your_language` to force highlighting if the filename doesn't work.
rvm ruby-1.8.6 # ZOMG, seriously? We still use this version?
{% endcodeblock %}
#### Example 5
#### Add a URL
Add an optional URL to enable downloading or linking to source.
@ -76,3 +76,22 @@ var arr2 = new Array(element0, element1, ..., elementN);
{% endcodeblock %}
The last argument `link_text` is optional. You may want to link to a source for download file, or documentation on some other site.
#### Start on a custom line number
{% raw %}{% codeblock Coffeescript Tricks lang:coffeescript start:51 %}
# Given an alphabet:
alphabet = 'abcdefghijklmnopqrstuvwxyz'
# Iterate over part of the alphabet:
console.log letter for letter in alphabet[4..8]
{% endcodeblock %}{% endraw %}
{% codeblock lang:coffeescript Coffeescript Tricks start:51 %}
# Given an alphabet:
alphabet = 'abcdefghijklmnopqrstuvwxyz'
# Iterate over part of the alphabet:
console.log letter for letter in alphabet[4..8]
{% endcodeblock %}

View File

@ -11,18 +11,18 @@ Import files on your filesystem into any blog post as embedded code snippets wit
In the `_config.yml` you can set your `code_dir` but the default is `source/downloads/code`. Simply put a file anywhere under that directory and
use the following tag to embed it in a post.
#### Syntax
### Syntax
{{ "{% include_code [title] [lang:language] path/to/file" }} %}
{{ "{% include_code [title] [lang:language] path/to/file [start:#] [end:#] [range:#,#]" }} %}
#### Example 1
### Basic
This includes a file from `source/downloads/code/test.js`.
{{ "{% include_code test.js" }} %}
{% include_code test.js %}
#### Example 2
### Custom title
By default the `<figcaption>` will be the filename, but you can add a title before the filepath if you like.
{{ "{% include_code Add to_fraction for floats ruby/test.rb" }} %}
@ -31,7 +31,27 @@ This includes a file from `source/downloads/code/ruby/test.rb`.
{% include_code Add to_fraction for floats ruby/test.rb %}
#### Example 3 (Force Highlighting)
### Include part of a file
Start on line a specific line.
{% raw %}{% include_code test.js start:10 %}{% endraw %}
{% include_code test.js start:10 %}
End on line a specific line.
{% raw %}{% include_code test.js end:10 %}{% endraw %}
{% include_code test.js end:10 %}
Choose a custom range of lines to include.
{% raw %}{% include_code test.js range:10,15 %}{% endraw %}
{% include_code test.js range:10,15 %}
### Force highlighting
Pygments supports many languages, but doesn't recognize some file extensions.
Add `lang:your_language` to force highlighting if the filename doesn't work.
@ -39,3 +59,4 @@ Add `lang:your_language` to force highlighting if the filename doesn't work.
{{ "{% include_code test.coffee lang:coffeescript" }} %}
{% include_code test.coffee lang:coffeescript %}