Syntax Highlighting Post

August 16, 2013

Reading time ~5 minutes

Syntax highlighting is a feature that displays source code, in different colors and fonts according to the category of terms. @EdgarSandi :+1: ! This feature facilitates writing in a structured language such as a programming language or a markup language as both structures and syntax errors are visually distinct. Highlighting does not affect the meaning of the text itself; it is intended only for human readers.

Pygments Code Blocks

To modify styling and highlight colors edit /assets/less/pygments.less and compile main.less with your favorite preprocessor. Or edit main.css if that’s your thing, the classes you want to modify all begin with .highlight.

1 #container {
2     float: left;
3     margin: 0 -240px 0 0;
4     width: 100%;
5 }

Line numbering enabled:

1 <nav class="pagination" role="navigation">
2     {% if page.previous %}
3         <a href="{{ site.url }}{{ page.previous.url }}" class="btn" title="{{ page.previous.title }}">Previous article</a>
4     {% endif %}
5     {% if page.next %}
6         <a href="{{ site.url }}{{ page.next.url }}" class="btn" title="{{ page.next.title }}">Next article</a>
7     {% endif %}
8 </nav><!-- /.pagination -->
10 module Jekyll
11   class TagIndex < Page
12     def initialize(site, base, dir, tag)
13       <a href='https://github.com/site' class='user-mention'>@site</a> = site
14       <a href='https://github.com/base' class='user-mention'>@base</a> = base
15       <a href='https://github.com/dir' class='user-mention'>@dir</a> = dir
16       <a href='https://github.com/name' class='user-mention'>@name</a> = 'index.html'
17       self.process(<a href='https://github.com/name' class='user-mention'>@name</a>)
18       self.read_yaml(File.join(base, '_layouts'), 'tag_index.html')
19       self.data['tag'] = tag
20       tag_title_prefix = site.config['tag_title_prefix'] || 'Tagged: '
21       tag_title_suffix = site.config['tag_title_suffix'] || '&#8211;'
22       self.data['title'] = "#{tag_title_prefix}#{tag}"
23       self.data['description'] = "An archive of posts tagged #{tag}."
24     end
25   end
26 end

Standard Code Block

<nav class="pagination" role="navigation">
    {% if page.previous %}
        <a href="{{ site.url }}{{ page.previous.url }}" class="btn" title="{{ page.previous.title }}">Previous article</a>
    {% endif %}
    {% if page.next %}
        <a href="{{ site.url }}{{ page.next.url }}" class="btn" title="{{ page.next.title }}">Next article</a>
    {% endif %}
</nav><!-- /.pagination -->

Fenced Code Blocks

To modify styling and highlight colors edit /assets/less/coderay.less and compile main.less with your favorite preprocessor. Or edit main.css if that’s your thing, the classes you want to modify all begin with .coderay. Line numbers and a few other things can be modified in _config.yml under coderay.

1
2
3
4
5
#container {
    float: left;
    margin: 0 -240px 0 0;
    width: 100%;
}
1
2
3
4
5
6
7
8
<nav class="pagination" role="navigation">
    {% if page.previous %}
        <a href="{{ site.url }}{{ page.previous.url }}" class="btn" title="{{ page.previous.title }}">Previous article</a>
    {% endif %}
    {% if page.next %}
        <a href="{{ site.url }}{{ page.next.url }}" class="btn" title="{{ page.next.title }}">Next article</a>
    {% endif %}
</nav><!-- /.pagination -->
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
module Jekyll
  class TagIndex < Page
    def initialize(site, base, dir, tag)
      <a href='https://github.com/site' class='user-mention'>@site</a> = site
      <a href='https://github.com/base' class='user-mention'>@base</a> = base
      <a href='https://github.com/dir' class='user-mention'>@dir</a> = dir
      <a href='https://github.com/name' class='user-mention'>@name</a> = 'index.html'
      self.process(<a href='https://github.com/name' class='user-mention'>@name</a>)
      self.read_yaml(File.join(base, '_layouts'), 'tag_index.html')
      self.data['tag'] = tag
      tag_title_prefix = site.config['tag_title_prefix'] || 'Tagged: '
      tag_title_suffix = site.config['tag_title_suffix'] || '&#8211;'
      self.data['title'] = "#{tag_title_prefix}#{tag}"
      self.data['description'] = "An archive of posts tagged #{tag}."
    end
  end
end

Exemplo de post

Este é um exemplo de post. Continue reading

Post with a Background Image

Published on October 26, 2013

Sample Link Post

Published on August 12, 2013