tdiary-style-gfm 0.4.1 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc7ec0f2808b5f533557c9da17f0f6af706e6c5b
4
- data.tar.gz: 87aa44e3842d7d1fd64031cccc7ec39d1d8b1ba5
3
+ metadata.gz: 1dac1dabf34213a56e17ccaa5758418af83e5f43
4
+ data.tar.gz: c83cbe2fcb8baaa9774ab5414a0bbbc2b36ccaee
5
5
  SHA512:
6
- metadata.gz: 04fc77764f9f29396ff5d4f60c63761963a6a91018865654d23d52d4413700a82cfddc436860a03c189b544e8bbd06c96ef26ab6a395c239a4ffe818fbf40ca3
7
- data.tar.gz: 758c5857a6044c632b9b882419178cb0144867b559f6d6bed62fada4ed325299918ae18a211495458a95db64b37bcb4c5dfed696c585cf1852631f7ae3bb033c
6
+ metadata.gz: 01c40e2f8a84880827d8b64bdeed5485905ca7611fe83d4a1c212ee9f51117227df421abf3e2a9b88efa4b649746e750f038306134195460e1a395a5e2eb3c2b
7
+ data.tar.gz: aef4277b16355da84abf58b7d4b1d24740eeeb4649a1d734bb95c28bfa22186818869747e81d767eb4da5e9389e5a8f2cd78d4e7f58d9a94d161d0b83b3bb4d1
data/.travis.yml CHANGED
@@ -1,9 +1,12 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
4
- - 2.1
5
3
  - 2.2
6
- - 2.3.0
4
+ - 2.3
5
+ - 2.4
7
6
  - ruby-head
7
+ matrix:
8
+ allowed_failures:
9
+ - rvm: ruby-head
10
+
8
11
  before_install: gem update bundler
9
12
  script: bundle exec rake spec
@@ -1,7 +1,7 @@
1
1
  module TDiary
2
2
  module Style
3
3
  module Gfm
4
- VERSION = "0.4.1"
4
+ VERSION = "0.5.0"
5
5
  end
6
6
  end
7
7
  end
@@ -56,17 +56,18 @@ module TDiary
56
56
 
57
57
  # 1. Stash plugin calls
58
58
  plugin_stashes = []
59
- r.gsub!(/\{\{(.*?)\}\}/) do |matched|
59
+ plugin_blocks, replaced_r = extract_plugin_blocks_and_replace(r)
60
+ plugin_blocks.each do |plugin_block|
60
61
  # Convert `{{ }}' to erb tags
61
- plugin_stashes.push([matched, "<%=#{$1}%>"])
62
- "@@tdiary_style_gfm_plugin#{plugin_stashes.length - 1}@@"
62
+ plugin_stashes.push(["{{#{plugin_block}}}", "<%=#{plugin_block}%>"])
63
63
  end
64
+ r = replaced_r
64
65
 
65
66
  # 2. Apply markdown conversion
66
67
  r = GitHub::Markdown.to_html(r, :gfm) do |code, lang|
67
68
  begin
68
69
  formatter = Rouge::Formatters::HTMLPygments.new(Rouge::Formatters::HTML.new, 'highlight')
69
- lexer = Rouge::Lexer.find(lang)
70
+ lexer = Rouge::Lexer.find_fancy(lang)
70
71
  formatter.format(lexer.lex(code))
71
72
  rescue Exception => ex
72
73
  "<div class=\"highlight\"><pre>#{CGI.escapeHTML(code)}</pre></div>"
@@ -150,6 +151,37 @@ module TDiary
150
151
  r
151
152
  end
152
153
  end
154
+
155
+ def extract_plugin_blocks_and_replace(text)
156
+ s = StringScanner.new(text)
157
+ blocks = []
158
+ count = 0
159
+ replaced_text = ""
160
+ while chunk = s.scan_until(/\{\{/)
161
+ chunk[-2, 2] = ""
162
+ replaced_text << chunk
163
+ if plugin_str = extract_plugin_block(s)
164
+ replaced_text << "@@tdiary_style_gfm_plugin#{count}@@"
165
+ blocks << plugin_str
166
+ count += 1
167
+ end
168
+ end
169
+ replaced_text << s.rest
170
+ return blocks, replaced_text
171
+ end
172
+
173
+ def extract_plugin_block(s)
174
+ pos = s.pos
175
+ buf = ""
176
+ while chunk = s.scan_until(/\}\}/)
177
+ buf << chunk
178
+ buf.chomp!("}}")
179
+ return buf
180
+ end
181
+ s.pos = pos
182
+ nil
183
+ end
184
+
153
185
  end
154
186
 
155
187
  class GfmDiary
@@ -203,8 +203,8 @@ http://example.com is example.com
203
203
  <div class="section">
204
204
  <%=section_enter_proc( Time.at( 1041346800 ) )%>
205
205
  <h3><%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %></h3>
206
- <pre class="highlight"><code><span class="vi">@foo</span>
207
- </code></pre>
206
+ <div class="highlight"><pre class="highlight"><code><span class="vi">@foo</span>
207
+ </code></pre></div>
208
208
  <p><a href="http://example.com">http://example.com</a> is example.com</p>
209
209
  <%=section_leave_proc( Time.at( 1041346800 ) )%>
210
210
  </div>
@@ -243,6 +243,13 @@ http://example.com is example.com
243
243
 
244
244
  {{plugin "val", 'val'}}
245
245
 
246
+ {{plugin <<EOS, 'val'
247
+ valval
248
+ valval
249
+ vaoooo
250
+ EOS
251
+ }}
252
+
246
253
  EOF
247
254
  @diary.append(source)
248
255
 
@@ -253,6 +260,13 @@ http://example.com is example.com
253
260
  <p><%=plugin 'val'%></p>
254
261
 
255
262
  <p><%=plugin "val", 'val'%></p>
263
+
264
+ <p><%=plugin <<EOS, 'val'
265
+ valval
266
+ valval
267
+ vaoooo
268
+ EOS
269
+ %></p>
256
270
  <%=section_leave_proc( Time.at( 1041346800 ) )%>
257
271
  </div>
258
272
  EOF
@@ -324,10 +338,10 @@ http://example.com is example.com
324
338
  <div class="section">
325
339
  <%=section_enter_proc( Time.at( 1041346800 ) )%>
326
340
  <h3><%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %></h3>
327
- <pre class="highlight"><code> <span class="k">def</span> <span class="nf">class</span>
341
+ <div class="highlight"><pre class="highlight"><code> <span class="k">def</span> <span class="nf">class</span>
328
342
  <span class="vi">@foo</span> <span class="o">=</span> <span class="s1">'bar'</span>
329
343
  <span class="k">end</span>
330
- </code></pre><%=section_leave_proc( Time.at( 1041346800 ) )%>
344
+ </code></pre></div><%=section_leave_proc( Time.at( 1041346800 ) )%>
331
345
  </div>
332
346
  EOF
333
347
  end
@@ -447,7 +461,7 @@ http://example.com is example.com
447
461
  <div class="section">
448
462
  <%=section_enter_proc( Time.at( 1041346800 ) )%>
449
463
  <h3><%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %></h3>
450
- <p><img src='http://www.webpagefx.com/tools/emoji-cheat-sheet/graphics/emojis/sushi.png' width='20' height='20' title='sushi' alt='sushi' class='emoji' /> は美味しい</p>
464
+ <p><img src='//www.webpagefx.com/tools/emoji-cheat-sheet/graphics/emojis/sushi.png' width='20' height='20' title='sushi' alt='sushi' class='emoji' /> は美味しい</p>
451
465
  <%=section_leave_proc( Time.at( 1041346800 ) )%>
452
466
  </div>
453
467
  EOF
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.summary = %q{GFM Style for tDiary}
13
13
  spec.homepage = "https://github.com/tdiary/tdiary-style-gfm"
14
14
  spec.license = "GPL-3.0"
15
+ spec.required_ruby_version = ">= 2.2.0"
15
16
 
16
17
  spec.files = `git ls-files`.split($/)
17
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tdiary-style-gfm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SHIBATA Hiroshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-28 00:00:00.000000000 Z
11
+ date: 2017-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: github-markdown
@@ -140,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
140
  requirements:
141
141
  - - ">="
142
142
  - !ruby/object:Gem::Version
143
- version: '0'
143
+ version: 2.2.0
144
144
  required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  requirements:
146
146
  - - ">="
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  version: '0'
149
149
  requirements: []
150
150
  rubyforge_project:
151
- rubygems_version: 2.6.8
151
+ rubygems_version: 2.6.12
152
152
  signing_key:
153
153
  specification_version: 4
154
154
  summary: GFM Style for tDiary