octopress-codefence 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
19
+ .pygments-cache
20
+ _site
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in octopress-codefence.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Brandon Mathis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Octopress::Codefence
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'octopress-codefence'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install octopress-codefence
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ module Octopress
2
+ class Codefence
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,68 @@
1
+ require 'octopress-codefence/version'
2
+ require 'octopress-pygments'
3
+ require 'jekyll-page-hooks'
4
+
5
+ module Jekyll
6
+ class Codefence < PageHooks
7
+ def pre_render(page)
8
+ page.content = Octopress::Codefence.new(page.content, page.ext).render
9
+ end
10
+ end
11
+ end
12
+
13
+ module Octopress
14
+ class Codefence
15
+ AllOptions = /([^\s]+)\s+(.+?)\s+(https?:\/\/\S+|\/\S+)\s*(.+)?/i
16
+ LangCaption = /([^\s]+)\s*(.+)?/i
17
+
18
+ def initialize(input, ext=nil)
19
+ @input = input
20
+ @ext = ext
21
+ end
22
+
23
+ def render
24
+ @input.encode!("UTF-8")
25
+ @input.gsub /^`{3}(.+?)`{3}/m do
26
+ str = $1.to_s
27
+ str.gsub /([^\n]+)?\n(.+?)\Z/m do
28
+ markup = $1 || ''
29
+ code = $2.to_s
30
+ begin
31
+ get_code(code, get_options(markup))
32
+ rescue MentosError => e
33
+ markup = "```#{markup}"
34
+ Pygments.highlight_failed(e, "```[language] [title] [url] [link text] [linenos:false] [start:#] [mark:#,#-#]\ncode\n```", markup, code)
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ def get_options(markup)
41
+ defaults = {}
42
+ clean_markup = Pygments.clean_markup(markup)
43
+
44
+ if clean_markup =~ AllOptions
45
+ defaults = {
46
+ lang: $1,
47
+ title: $2,
48
+ url: $3,
49
+ link_text: $4,
50
+ }
51
+ elsif clean_markup =~ LangCaption
52
+ defaults = {
53
+ lang: $1,
54
+ title: $2
55
+ }
56
+ end
57
+ Pygments.parse_markup(markup, defaults)
58
+ end
59
+
60
+
61
+ def get_code(code, options)
62
+ code = Pygments.highlight(code, options)
63
+ code = "<notextile>#{code}</notextile>" if !@ext.nil? and @ext.match(/textile/)
64
+ code
65
+ end
66
+ end
67
+ end
68
+
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'octopress-codefence/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "octopress-codefence"
8
+ gem.version = Octopress::Codefence::VERSION
9
+ gem.authors = ["Brandon Mathis"]
10
+ gem.email = ["brandon@imathis.com"]
11
+ gem.description = %q{Write beautiful fenced code snippets with in any template.}
12
+ gem.summary = %q{Write beautiful fenced code snippets with in any template.}
13
+ gem.homepage = "https://github.com/octopress/octopress-codefence"
14
+ gem.license = "MIT"
15
+
16
+ gem.add_runtime_dependency 'octopress-pygments', '>= 1.1.0'
17
+ gem.add_runtime_dependency 'jekyll-page-hooks', '>= 1.0.2'
18
+
19
+ gem.files = `git ls-files`.split($/)
20
+ gem.require_paths = ["lib"]
21
+ end
data/test/.gitignore ADDED
@@ -0,0 +1 @@
1
+ _site
data/test/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'jekyll'
4
+ gem 'jekyll-page-hooks'
5
+ gem 'octopress-codefence', :path => '../'
data/test/_config.yml ADDED
@@ -0,0 +1,3 @@
1
+ name: Your New Jekyll Site
2
+ markdown: redcarpet
3
+ pygments: true
@@ -0,0 +1,46 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
6
+ <title>{{ page.title }}</title>
7
+ <meta name="viewport" content="width=device-width">
8
+
9
+ <!-- syntax highlighting CSS -->
10
+ <link rel="stylesheet" href="/css/syntax.css">
11
+
12
+ <!-- Custom CSS -->
13
+ <link rel="stylesheet" href="/css/main.css">
14
+
15
+ </head>
16
+ <body>
17
+
18
+ <div class="container">
19
+ <div class="site">
20
+ <div class="header">
21
+ <h1 class="title"><a href="/">{{ site.name }}</a></h1>
22
+ <a class="extra" href="/">home</a>
23
+ </div>
24
+
25
+ {{ content }}
26
+
27
+ <div class="footer">
28
+ <div class="contact">
29
+ <p>
30
+ Your Name<br />
31
+ What You Are<br />
32
+ your@email.com
33
+ </p>
34
+ </div>
35
+ <div class="contact">
36
+ <p>
37
+ <a href="http://github.com/yourusername/">github.com/yourusername</a><br />
38
+ <a href="http://twitter.com/yourusername/">twitter.com/yourusername</a><br />
39
+ </p>
40
+ </div>
41
+ </div>
42
+ </div>
43
+ </div> <!-- /container -->
44
+
45
+ </body>
46
+ </html>
@@ -0,0 +1 @@
1
+ require 'octopress-codefence'
data/test/css/main.css ADDED
@@ -0,0 +1,160 @@
1
+ /*****************************************************************************/
2
+ /*
3
+ /* Common
4
+ /*
5
+ /*****************************************************************************/
6
+
7
+ /* Global Reset */
8
+ * {
9
+ margin: 0;
10
+ padding: 0;
11
+ }
12
+
13
+ html, body { height: 100%; }
14
+
15
+ body {
16
+ background-color: #FFF;
17
+ font: 13.34px Helvetica, Arial, sans-serif;
18
+ font-size: small;
19
+ text-align: center;
20
+ }
21
+
22
+ h1, h2, h3, h4, h5, h6 {
23
+ font-size: 100%; }
24
+
25
+ h1 { margin-bottom: 1em; }
26
+ p { margin: 1em 0; }
27
+
28
+ a { color: #00a; }
29
+ a:hover { color: #000; }
30
+ a:visited { color: #a0a; }
31
+
32
+ /*****************************************************************************/
33
+ /*
34
+ /* Home
35
+ /*
36
+ /*****************************************************************************/
37
+ ul.posts {
38
+ list-style-type: none;
39
+ margin-bottom: 2em;
40
+ }
41
+
42
+ ul.posts li {
43
+ line-height: 1.75em;
44
+ }
45
+
46
+ ul.posts span {
47
+ color: #aaa;
48
+ font-family: Monaco, "Courier New", monospace;
49
+ font-size: 80%;
50
+ }
51
+
52
+ /*****************************************************************************/
53
+ /*
54
+ /* Site
55
+ /*
56
+ /*****************************************************************************/
57
+
58
+ .site {
59
+ font-size: 115%;
60
+ text-align: justify;
61
+ width: 42em;
62
+ margin: 3em auto 2em;
63
+ line-height: 1.5em;
64
+ }
65
+
66
+ .site .header a {
67
+ font-weight: bold;
68
+ text-decoration: none;
69
+ }
70
+
71
+ .site .header h1.title {
72
+ display: inline-block;
73
+ margin-bottom: 2em;
74
+ }
75
+
76
+ .site .header h1.title a {
77
+ color: #a00;
78
+ }
79
+
80
+ .site .header h1.title a:hover {
81
+ color: #000;
82
+ }
83
+
84
+ .site .header a.extra {
85
+ color: #aaa;
86
+ margin-left: 1em;
87
+ }
88
+
89
+ .site .header a.extra:hover {
90
+ color: #000;
91
+ }
92
+
93
+ .site .meta {
94
+ color: #aaa;
95
+ }
96
+
97
+ .site .footer {
98
+ font-size: 80%;
99
+ color: #666;
100
+ border-top: 4px solid #eee;
101
+ margin-top: 2em;
102
+ overflow: hidden;
103
+ }
104
+
105
+ .site .footer .contact {
106
+ float: left;
107
+ margin-right: 3em;
108
+ }
109
+
110
+ .site .footer .contact a {
111
+ color: #8085C1;
112
+ }
113
+
114
+ .site .footer .rss {
115
+ margin-top: 1.1em;
116
+ margin-right: -.2em;
117
+ float: right;
118
+ }
119
+
120
+ .site .footer .rss img {
121
+ border: 0;
122
+ }
123
+
124
+ /*****************************************************************************/
125
+ /*
126
+ /* Posts
127
+ /*
128
+ /*****************************************************************************/
129
+
130
+ /* standard */
131
+ .post pre {
132
+ border: 1px solid #ddd;
133
+ background-color: #eef;
134
+ padding: 0 .4em;
135
+ }
136
+
137
+ .post ul, .post ol {
138
+ margin-left: 1.35em;
139
+ }
140
+
141
+ .post code {
142
+ border: 1px solid #ddd;
143
+ background-color: #eef;
144
+ padding: 0 .2em;
145
+ }
146
+
147
+ .post pre code {
148
+ border: none;
149
+ }
150
+
151
+ /* terminal */
152
+ .post pre.terminal {
153
+ border: 1px solid #000;
154
+ background-color: #333;
155
+ color: #FFF;
156
+ }
157
+
158
+ .post pre.terminal code {
159
+ background-color: #333;
160
+ }
@@ -0,0 +1,60 @@
1
+ .highlight { background: #ffffff; }
2
+ .highlight .c { color: #999988; font-style: italic } /* Comment */
3
+ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
4
+ .highlight .k { font-weight: bold } /* Keyword */
5
+ .highlight .o { font-weight: bold } /* Operator */
6
+ .highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */
7
+ .highlight .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
8
+ .highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */
9
+ .highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
10
+ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
11
+ .highlight .gd .x { color: #000000; background-color: #ffaaaa } /* Generic.Deleted.Specific */
12
+ .highlight .ge { font-style: italic } /* Generic.Emph */
13
+ .highlight .gr { color: #aa0000 } /* Generic.Error */
14
+ .highlight .gh { color: #999999 } /* Generic.Heading */
15
+ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
16
+ .highlight .gi .x { color: #000000; background-color: #aaffaa } /* Generic.Inserted.Specific */
17
+ .highlight .go { color: #888888 } /* Generic.Output */
18
+ .highlight .gp { color: #555555 } /* Generic.Prompt */
19
+ .highlight .gs { font-weight: bold } /* Generic.Strong */
20
+ .highlight .gu { color: #aaaaaa } /* Generic.Subheading */
21
+ .highlight .gt { color: #aa0000 } /* Generic.Traceback */
22
+ .highlight .kc { font-weight: bold } /* Keyword.Constant */
23
+ .highlight .kd { font-weight: bold } /* Keyword.Declaration */
24
+ .highlight .kp { font-weight: bold } /* Keyword.Pseudo */
25
+ .highlight .kr { font-weight: bold } /* Keyword.Reserved */
26
+ .highlight .kt { color: #445588; font-weight: bold } /* Keyword.Type */
27
+ .highlight .m { color: #009999 } /* Literal.Number */
28
+ .highlight .s { color: #d14 } /* Literal.String */
29
+ .highlight .na { color: #008080 } /* Name.Attribute */
30
+ .highlight .nb { color: #0086B3 } /* Name.Builtin */
31
+ .highlight .nc { color: #445588; font-weight: bold } /* Name.Class */
32
+ .highlight .no { color: #008080 } /* Name.Constant */
33
+ .highlight .ni { color: #800080 } /* Name.Entity */
34
+ .highlight .ne { color: #990000; font-weight: bold } /* Name.Exception */
35
+ .highlight .nf { color: #990000; font-weight: bold } /* Name.Function */
36
+ .highlight .nn { color: #555555 } /* Name.Namespace */
37
+ .highlight .nt { color: #000080 } /* Name.Tag */
38
+ .highlight .nv { color: #008080 } /* Name.Variable */
39
+ .highlight .ow { font-weight: bold } /* Operator.Word */
40
+ .highlight .w { color: #bbbbbb } /* Text.Whitespace */
41
+ .highlight .mf { color: #009999 } /* Literal.Number.Float */
42
+ .highlight .mh { color: #009999 } /* Literal.Number.Hex */
43
+ .highlight .mi { color: #009999 } /* Literal.Number.Integer */
44
+ .highlight .mo { color: #009999 } /* Literal.Number.Oct */
45
+ .highlight .sb { color: #d14 } /* Literal.String.Backtick */
46
+ .highlight .sc { color: #d14 } /* Literal.String.Char */
47
+ .highlight .sd { color: #d14 } /* Literal.String.Doc */
48
+ .highlight .s2 { color: #d14 } /* Literal.String.Double */
49
+ .highlight .se { color: #d14 } /* Literal.String.Escape */
50
+ .highlight .sh { color: #d14 } /* Literal.String.Heredoc */
51
+ .highlight .si { color: #d14 } /* Literal.String.Interpol */
52
+ .highlight .sx { color: #d14 } /* Literal.String.Other */
53
+ .highlight .sr { color: #009926 } /* Literal.String.Regex */
54
+ .highlight .s1 { color: #d14 } /* Literal.String.Single */
55
+ .highlight .ss { color: #990073 } /* Literal.String.Symbol */
56
+ .highlight .bp { color: #999999 } /* Name.Builtin.Pseudo */
57
+ .highlight .vc { color: #008080 } /* Name.Variable.Class */
58
+ .highlight .vg { color: #008080 } /* Name.Variable.Global */
59
+ .highlight .vi { color: #008080 } /* Name.Variable.Instance */
60
+ .highlight .il { color: #009999 } /* Literal.Number.Integer.Long */
data/test/index.html ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ layout: default
3
+ ---
4
+
5
+ ``` ruby
6
+ puts @awesome if true
7
+ ```
data/test/test.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'octopress-codefence'
2
+
3
+ str = <<-EOF
4
+
5
+ whatver
6
+
7
+ ``` ruby
8
+ puts awesome unless lame
9
+ ```
10
+
11
+ something
12
+
13
+ EOF
14
+
15
+ puts Octopress::Codefence.new(str).render
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: octopress-codefence
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brandon Mathis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: octopress-pygments
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.1.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: jekyll-page-hooks
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.0.2
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.2
46
+ description: Write beautiful fenced code snippets with in any template.
47
+ email:
48
+ - brandon@imathis.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - lib/octopress-codefence.rb
59
+ - lib/octopress-codefence/version.rb
60
+ - octopress-codefence.gemspec
61
+ - test/.gitignore
62
+ - test/Gemfile
63
+ - test/_config.yml
64
+ - test/_layouts/default.html
65
+ - test/_plugins/codefence.rb
66
+ - test/css/main.css
67
+ - test/css/syntax.css
68
+ - test/index.html
69
+ - test/test.rb
70
+ homepage: https://github.com/octopress/octopress-codefence
71
+ licenses:
72
+ - MIT
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 1.8.23
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Write beautiful fenced code snippets with in any template.
95
+ test_files: []