[DRE-commits] [tdiary-style-gfm] 01/07: New upstream version 0.5.0

Youhei SASAKI uwabami-guest at moszumanska.debian.org
Mon Aug 28 04:44:18 UTC 2017


This is an automated email from the git hooks/post-receive script.

uwabami-guest pushed a commit to branch master
in repository tdiary-style-gfm.

commit e220b76e8ec29739077f7435c710fd4f742a040d
Author: Youhei SASAKI <uwabami at gfd-dennou.org>
Date:   Mon Aug 28 13:28:55 2017 +0900

    New upstream version 0.5.0
---
 .travis.yml                     |  9 ++++++---
 lib/tdiary/style/gfm.rb         | 40 ++++++++++++++++++++++++++++++++++++----
 lib/tdiary/style/gfm/version.rb |  2 +-
 spec/tdiary/style/gfm_spec.rb   | 24 +++++++++++++++++++-----
 tdiary-style-gfm.gemspec        |  1 +
 5 files changed, 63 insertions(+), 13 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 80db2da..5ba236c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,9 +1,12 @@
 language: ruby
 rvm:
-  - 2.0.0
-  - 2.1
   - 2.2
-  - 2.3.0
+  - 2.3
+  - 2.4
   - ruby-head
+matrix:
+  allowed_failures:
+    - rvm: ruby-head
+
 before_install: gem update bundler
 script: bundle exec rake spec
diff --git a/lib/tdiary/style/gfm.rb b/lib/tdiary/style/gfm.rb
index 1782294..8f849a5 100644
--- a/lib/tdiary/style/gfm.rb
+++ b/lib/tdiary/style/gfm.rb
@@ -56,17 +56,18 @@ module TDiary
 
 				# 1. Stash plugin calls
 				plugin_stashes = []
-				r.gsub!(/\{\{(.*?)\}\}/) do |matched|
+				plugin_blocks, replaced_r = extract_plugin_blocks_and_replace(r)
+				plugin_blocks.each do |plugin_block|
 					# Convert `{{ }}' to erb tags
-					plugin_stashes.push([matched, "<%=#{$1}%>"])
-					"@@tdiary_style_gfm_plugin#{plugin_stashes.length - 1}@@"
+					plugin_stashes.push(["{{#{plugin_block}}}", "<%=#{plugin_block}%>"])
 				end
+				r = replaced_r
 
 				# 2. Apply markdown conversion
 				r = GitHub::Markdown.to_html(r, :gfm) do |code, lang|
 					begin
 						formatter = Rouge::Formatters::HTMLPygments.new(Rouge::Formatters::HTML.new, 'highlight')
-						lexer = Rouge::Lexer.find(lang)
+						lexer = Rouge::Lexer.find_fancy(lang)
 						formatter.format(lexer.lex(code))
 					rescue Exception => ex
 						"<div class=\"highlight\"><pre>#{CGI.escapeHTML(code)}</pre></div>"
@@ -150,6 +151,37 @@ module TDiary
 					r
 				end
 			end
+
+			def extract_plugin_blocks_and_replace(text)
+				s = StringScanner.new(text)
+				blocks = []
+				count = 0
+				replaced_text = ""
+				while chunk = s.scan_until(/\{\{/)
+					chunk[-2, 2] = ""
+					replaced_text << chunk
+					if plugin_str = extract_plugin_block(s)
+						replaced_text << "@@tdiary_style_gfm_plugin#{count}@@"
+						blocks << plugin_str
+						count += 1
+					end
+				end
+				replaced_text << s.rest
+				return blocks, replaced_text
+			end
+
+			def extract_plugin_block(s)
+				pos = s.pos
+				buf = ""
+				while chunk = s.scan_until(/\}\}/)
+					buf << chunk
+					buf.chomp!("}}")
+					return buf
+				end
+				s.pos = pos
+				nil
+			end
+
 		end
 
 		class GfmDiary
diff --git a/lib/tdiary/style/gfm/version.rb b/lib/tdiary/style/gfm/version.rb
index 7a3b3a6..f7726fa 100644
--- a/lib/tdiary/style/gfm/version.rb
+++ b/lib/tdiary/style/gfm/version.rb
@@ -1,7 +1,7 @@
 module TDiary
   module Style
     module Gfm
-      VERSION = "0.4.1"
+      VERSION = "0.5.0"
     end
   end
 end
diff --git a/spec/tdiary/style/gfm_spec.rb b/spec/tdiary/style/gfm_spec.rb
index 1b41a10..bd6c6c8 100644
--- a/spec/tdiary/style/gfm_spec.rb
+++ b/spec/tdiary/style/gfm_spec.rb
@@ -203,8 +203,8 @@ http://example.com is example.com
 <div class="section">
 <%=section_enter_proc( Time.at( 1041346800 ) )%>
 <h3><%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %></h3>
-<pre class="highlight"><code><span class="vi">@foo</span>
-</code></pre>
+<div class="highlight"><pre class="highlight"><code><span class="vi">@foo</span>
+</code></pre></div>
 <p><a href="http://example.com">http://example.com</a> is example.com</p>
 <%=section_leave_proc( Time.at( 1041346800 ) )%>
 </div>
@@ -243,6 +243,13 @@ http://example.com is example.com
 
 {{plugin "val", 'val'}}
 
+{{plugin <<EOS, 'val'
+valval
+valval
+vaoooo
+EOS
+}}
+
 			EOF
 			@diary.append(source)
 
@@ -253,6 +260,13 @@ http://example.com is example.com
 <p><%=plugin 'val'%></p>
 
 <p><%=plugin "val", 'val'%></p>
+
+<p><%=plugin <<EOS, 'val'
+valval
+valval
+vaoooo
+EOS
+%></p>
 <%=section_leave_proc( Time.at( 1041346800 ) )%>
 </div>
 			EOF
@@ -324,10 +338,10 @@ http://example.com is example.com
 <div class="section">
 <%=section_enter_proc( Time.at( 1041346800 ) )%>
 <h3><%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %></h3>
-<pre class="highlight"><code> <span class="k">def</span> <span class="nf">class</span>
+<div class="highlight"><pre class="highlight"><code> <span class="k">def</span> <span class="nf">class</span>
    <span class="vi">@foo</span> <span class="o">=</span> <span class="s1">'bar'</span>
  <span class="k">end</span>
-</code></pre><%=section_leave_proc( Time.at( 1041346800 ) )%>
+</code></pre></div><%=section_leave_proc( Time.at( 1041346800 ) )%>
 </div>
 			EOF
 		end
@@ -447,7 +461,7 @@ http://example.com is example.com
 <div class="section">
 <%=section_enter_proc( Time.at( 1041346800 ) )%>
 <h3><%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %></h3>
-<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>
+<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>
 <%=section_leave_proc( Time.at( 1041346800 ) )%>
 </div>
 				EOF
diff --git a/tdiary-style-gfm.gemspec b/tdiary-style-gfm.gemspec
index 70e3041..441de89 100644
--- a/tdiary-style-gfm.gemspec
+++ b/tdiary-style-gfm.gemspec
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
   spec.summary       = %q{GFM Style for tDiary}
   spec.homepage      = "https://github.com/tdiary/tdiary-style-gfm"
   spec.license       = "GPL-3.0"
+  spec.required_ruby_version = ">= 2.2.0"
 
   spec.files         = `git ls-files`.split($/)
   spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/tdiary-style-gfm.git



More information about the Pkg-ruby-extras-commits mailing list