lm2doc 0.0.1 → 0.0.2

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -13,17 +13,70 @@ module Lm2doc
13
13
 
14
14
  def convert
15
15
  html = Kramdown::Document.new(self.content,
16
- coderay_line_numbers: :table,
17
- coderay_tab_width: 4,
16
+ enable_coderay: false,
18
17
  toc_levels: [ 2, 3 ]
19
18
  ).to_html
20
19
 
21
20
  doc = Nokogiri::HTML::DocumentFragment.parse(html)
22
21
 
23
22
  figure_role(doc)
23
+ code_block(doc)
24
24
  doc.to_html
25
25
  end
26
26
 
27
+
28
+ def code_block(doc)
29
+ doc.css("pre > code[class^=language]").each do |code_node|
30
+ lang = (code_node["class"].scan(/language-([^\s]+)/).first || []).first
31
+ highlight_code_block(code_node, lang)
32
+ end
33
+
34
+ doc.css("pre[lang] > code").each do |code_node|
35
+ lang = code_node.parent["lang"]
36
+ highlight_code_block(code_node, lang)
37
+ end
38
+ end
39
+
40
+ def highlight_code_block(code_node, lang)
41
+ pre = code_node.parent
42
+ code_output = highlight(code_node.content, lang)
43
+ code_doc = Nokogiri::HTML::DocumentFragment.parse(code_output)
44
+ pre.replace code_doc.children
45
+ end
46
+
47
+ def highlight(content, lang)
48
+ # require "pry-nav"
49
+ # binding.pry
50
+ require 'pygments'
51
+ highlighted_code = Pygments.highlight(content, :lexer => lang, :formatter => 'html', :options => {:encoding => 'utf-8'})
52
+ str = highlighted_code.match(/<pre>(.+)<\/pre>/m)[1].to_s.gsub(/ *$/, '')
53
+ tableize_code(str, lang)
54
+ end
55
+
56
+ def tableize_code (str, lang = '')
57
+ line_number, code = '', ''
58
+ # code = ''
59
+ str.lines.each_with_index do |line, index|
60
+ line_number += "<span class='line-number'>#{index + 1}</span>\n"
61
+ code += "<span class='line'>#{line}</span>"
62
+ end
63
+
64
+ table = <<HTML
65
+ <div class="highlight">
66
+ <table>
67
+ <tr>
68
+ <td class="lines">
69
+ <pre class="line-numbers">#{line_number}</pre>
70
+ </td>
71
+ <td class="code">
72
+ <pre><code>#{code}</code></pre>
73
+ </td>
74
+ </tr>
75
+ </table>
76
+ </div>
77
+ HTML
78
+ end
79
+
27
80
  def figure_role(doc)
28
81
  doc.css("p[role=figure]").each do |p|
29
82
  p.remove_attribute "role"
data/lm2doc.gemspec CHANGED
@@ -19,16 +19,16 @@ Gem::Specification.new do |gem|
19
19
  gem.add_dependency "hashie"
20
20
  gem.add_dependency "nokogiri"
21
21
 
22
- gem.add_dependency "kramdown"
23
- gem.add_dependency "coderay"
22
+ gem.add_dependency "kramdown", "~> 0.14.0"
23
+ gem.add_dependency "pygments.rb", "~> 0.2.13"
24
24
 
25
25
  gem.add_dependency "compass"
26
- gem.add_dependency "bootstrap-sass", "~> 2.1.0.0"
26
+ gem.add_dependency "bootstrap-sass", "~> 2.2.1.1"
27
27
 
28
28
 
29
29
  # Test & Development
30
30
  gem.add_development_dependency "rake"
31
- gem.add_development_dependency "pry"
31
+ gem.add_development_dependency "pry-nav"
32
32
  gem.add_development_dependency "version"
33
33
 
34
34
  gem.add_development_dependency "rspec"
@@ -10,12 +10,12 @@ body {
10
10
  }
11
11
 
12
12
 
13
- h1 { font-size: $baseFontSize * 2.5; }
14
- h2 { font-size: $baseFontSize * 2.0; }
15
- h3 { font-size: $baseFontSize * 1.5; }
16
- h4 { font-size: $baseFontSize * 1.1; }
17
- h5 { font-size: $baseFontSize * 0.9; }
18
- h6 { font-size: $baseFontSize * 0.8; }
13
+ // h1 { font-size: $baseFontSize * 2.5; }
14
+ // h2 { font-size: $baseFontSize * 2.0; }
15
+ // h3 { font-size: $baseFontSize * 1.5; }
16
+ // h4 { font-size: $baseFontSize * 1.1; }
17
+ // h5 { font-size: $baseFontSize * 0.9; }
18
+ // h6 { font-size: $baseFontSize * 0.8; }
19
19
 
20
20
  // h4, h5, h6 {
21
21
  // line-height: $baseLineHeight;
@@ -88,49 +88,119 @@ article {
88
88
  }
89
89
  }
90
90
 
91
- .CodeRay {
92
- width: auto;
91
+
92
+ .highlight {
93
+ padding: 8px;
94
+ background-color: #f7f7f9;
95
+ border: 1px solid #e1e1e8;
96
+ margin-bottom: 20px;
97
+
98
+ @include box-shadow(inset 40px 0 0 #fbfbfc, inset 41px 0 0 #ececf0);
99
+ @include border-radius(4px);
100
+
101
+ table {
102
+ margin: 0;
103
+ table-layout: fixed;
104
+ }
93
105
 
94
- td {
106
+ table, td, th {
107
+ border: none;
95
108
  padding: 0;
96
-
109
+ }
110
+
111
+ .lines {
112
+ width: 33px;
97
113
  pre {
98
- font-size: $baseFontSize * 0.80;
99
- line-height: 1.4;
100
- margin: 0;
101
- padding: 8px;
102
- white-space: pre;
103
- border: none;
114
+ color: #bebec5;
115
+ }
116
+
117
+ .line-number:after {
118
+ content: ".";
104
119
  }
105
120
  }
106
121
 
107
122
  .code {
108
- width: 100%;
123
+ padding-left: 8px;
109
124
  }
110
125
 
111
- .code pre {
112
- border-top-left-radius: 0;
113
- border-bottom-left-radius: 0;
114
-
115
- padding-left: 10px;
116
- }
117
-
118
- .line-numbers pre {
119
- background-color: #FBFBFC;
120
-
121
- border-top-right-radius: 0;
122
- border-bottom-right-radius: 0;
123
- text-align: right;
124
-
125
- padding-left: 15px;
126
- padding-right: 5px;
126
+ pre {
127
+ font-size: $baseFontSize * 0.8;
128
+ line-height: 1.5;
129
+ @include border-radius(0px);
130
+ border: none;
131
+ margin: 0;
132
+ padding: 0;
133
+ white-space: pre;
134
+ background: transparent;
135
+ overflow-x: auto;
136
+ word-break: normal;
137
+ word-wrap: normal;
127
138
 
128
- a {
129
- color: #BEBEC5;
130
-
131
- &:after {
132
- content: ".";
133
- }
139
+ code {
140
+ font-size: inherit;
141
+ tab-size: 4;
134
142
  }
135
143
  }
144
+
145
+ .c { color: #999988; font-style: italic } /* Comment */
146
+ .err { color: #a61717; background-color: #e3d2d2 } /* Error */
147
+ .k { color: #000000; font-weight: bold } /* Keyword */
148
+ .o { color: #000000; font-weight: bold } /* Operator */
149
+ .cm { color: #999988; font-style: italic } /* Comment.Multiline */
150
+ .cp { color: #999999; font-weight: bold; font-style: italic } /* Comment.Preproc */
151
+ .c1 { color: #999988; font-style: italic } /* Comment.Single */
152
+ .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
153
+ .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
154
+ .ge { color: #000000; font-style: italic } /* Generic.Emph */
155
+ .gr { color: #aa0000 } /* Generic.Error */
156
+ .gh { color: #999999 } /* Generic.Heading */
157
+ .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
158
+ .go { color: #888888 } /* Generic.Output */
159
+ .gp { color: #555555 } /* Generic.Prompt */
160
+ .gs { font-weight: bold } /* Generic.Strong */
161
+ .gu { color: #aaaaaa } /* Generic.Subheading */
162
+ .gt { color: #aa0000 } /* Generic.Traceback */
163
+ .kc { color: #000000; font-weight: bold } /* Keyword.Constant */
164
+ .kd { color: #000000; font-weight: bold } /* Keyword.Declaration */
165
+ .kn { color: #000000; font-weight: bold } /* Keyword.Namespace */
166
+ .kp { color: #000000; font-weight: bold } /* Keyword.Pseudo */
167
+ .kr { color: #000000; font-weight: bold } /* Keyword.Reserved */
168
+ .kt { color: #445588; font-weight: bold } /* Keyword.Type */
169
+ .m { color: #009999 } /* Literal.Number */
170
+ .s { color: #d01040 } /* Literal.String */
171
+ .na { color: #008080 } /* Name.Attribute */
172
+ .nb { color: #0086B3 } /* Name.Builtin */
173
+ .nc { color: #445588; font-weight: bold } /* Name.Class */
174
+ .no { color: #008080 } /* Name.Constant */
175
+ .nd { color: #3c5d5d; font-weight: bold } /* Name.Decorator */
176
+ .ni { color: #800080 } /* Name.Entity */
177
+ .ne { color: #990000; font-weight: bold } /* Name.Exception */
178
+ .nf { color: #990000; font-weight: bold } /* Name.Function */
179
+ .nl { color: #990000; font-weight: bold } /* Name.Label */
180
+ .nn { color: #555555 } /* Name.Namespace */
181
+ .nt { color: #000080 } /* Name.Tag */
182
+ .nv { color: #008080 } /* Name.Variable */
183
+ .ow { color: #000000; font-weight: bold } /* Operator.Word */
184
+ .w { color: #bbbbbb } /* Text.Whitespace */
185
+ .mf { color: #009999 } /* Literal.Number.Float */
186
+ .mh { color: #009999 } /* Literal.Number.Hex */
187
+ .mi { color: #009999 } /* Literal.Number.Integer */
188
+ .mo { color: #009999 } /* Literal.Number.Oct */
189
+ .sb { color: #d01040 } /* Literal.String.Backtick */
190
+ .sc { color: #d01040 } /* Literal.String.Char */
191
+ .sd { color: #d01040 } /* Literal.String.Doc */
192
+ .s2 { color: #d01040 } /* Literal.String.Double */
193
+ .se { color: #d01040 } /* Literal.String.Escape */
194
+ .sh { color: #d01040 } /* Literal.String.Heredoc */
195
+ .si { color: #d01040 } /* Literal.String.Interpol */
196
+ .sx { color: #d01040 } /* Literal.String.Other */
197
+ .sr { color: #009926 } /* Literal.String.Regex */
198
+ .s1 { color: #d01040 } /* Literal.String.Single */
199
+ .ss { color: #990073 } /* Literal.String.Symbol */
200
+ .bp { color: #999999 } /* Name.Builtin.Pseudo */
201
+ .vc { color: #008080 } /* Name.Variable.Class */
202
+ .vg { color: #008080 } /* Name.Variable.Global */
203
+ .vi { color: #008080 } /* Name.Variable.Instance */
204
+ .il { color: #009999 } /* Literal.Number.Integer.Long */
136
205
  }
206
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lm2doc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-07 00:00:00.000000000 Z
12
+ date: 2012-11-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -64,33 +64,33 @@ dependencies:
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
- - - ! '>='
67
+ - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: '0'
69
+ version: 0.14.0
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
- - - ! '>='
75
+ - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: '0'
77
+ version: 0.14.0
78
78
  - !ruby/object:Gem::Dependency
79
- name: coderay
79
+ name: pygments.rb
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
- - - ! '>='
83
+ - - ~>
84
84
  - !ruby/object:Gem::Version
85
- version: '0'
85
+ version: 0.2.13
86
86
  type: :runtime
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
91
- - - ! '>='
91
+ - - ~>
92
92
  - !ruby/object:Gem::Version
93
- version: '0'
93
+ version: 0.2.13
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: compass
96
96
  requirement: !ruby/object:Gem::Requirement
@@ -114,7 +114,7 @@ dependencies:
114
114
  requirements:
115
115
  - - ~>
116
116
  - !ruby/object:Gem::Version
117
- version: 2.1.0.0
117
+ version: 2.2.1.1
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
@@ -122,7 +122,7 @@ dependencies:
122
122
  requirements:
123
123
  - - ~>
124
124
  - !ruby/object:Gem::Version
125
- version: 2.1.0.0
125
+ version: 2.2.1.1
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: rake
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -140,7 +140,7 @@ dependencies:
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  - !ruby/object:Gem::Dependency
143
- name: pry
143
+ name: pry-nav
144
144
  requirement: !ruby/object:Gem::Requirement
145
145
  none: false
146
146
  requirements:
@@ -230,7 +230,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
230
230
  version: '0'
231
231
  segments:
232
232
  - 0
233
- hash: -3067056615157754198
233
+ hash: 1074557977306794039
234
234
  required_rubygems_version: !ruby/object:Gem::Requirement
235
235
  none: false
236
236
  requirements:
@@ -239,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
239
  version: '0'
240
240
  segments:
241
241
  - 0
242
- hash: -3067056615157754198
242
+ hash: 1074557977306794039
243
243
  requirements: []
244
244
  rubyforge_project:
245
245
  rubygems_version: 1.8.24