tdiary-style-gfm 0.0.3 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81359b23dd148e13e8e53c63a7d948768537e7bc
4
- data.tar.gz: 64473dae3fae447d020a0b717f8462ea25f105f0
3
+ metadata.gz: e50242d3e4c9de5a6471cd39305d19ecc63db7b3
4
+ data.tar.gz: 7581983b9fab9eee31fd720f5f0b3cca84cce960
5
5
  SHA512:
6
- metadata.gz: 6e69fb429c4070fc7d4cc9f4ad772ad83ffac1822632a9eb9129622f3ccc34fd5b90978dea36c4f577def47e3b717e00c443b67a4040b38dfbe5adf54c9fd516
7
- data.tar.gz: b89a3a41ecf6d8e2f9c295399bc70398e6bc85f584f53da886b94f12d943b7069ae6cd353c1203d2507cb76f965fde607a4ab3116b08511857ab70301a4c50e2
6
+ metadata.gz: 4db97817b2b3d1cf8142598fb6726e37a1cccf7c1e7f58c3878b4289c2b3a85e2ab2c7c11a5d72c88506143d6c53a39275df852d85e2f7da4456f50eb1834011
7
+ data.tar.gz: 34b54f4903d6675fbf27e15228b46289b0305594a52bb1fd4b90473e4e141a9b026dbb1bee7fbbcfe9bfe326ce83a05f9c9a3f95088b4e41f6bb5090da7a0af3
data/.travis.yml CHANGED
@@ -1,3 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.0
3
+ - 1.9.3
4
+ - 2.0.0
5
+ script: bundle exec rake spec
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Tdiary::Style::Gfm
1
+ # TDiary::Style::Gfm
2
2
 
3
3
  "GitHub Flavored Markdown" (GFM) style for tDiary 2.x format.
4
4
 
@@ -1,24 +1,12 @@
1
1
  # -*- coding: utf-8; -*-
2
2
 
3
- require 'redcarpet'
3
+ require 'github/markdown'
4
4
  require 'pygments'
5
5
  require 'twitter-text'
6
6
 
7
- class HTMLwithPygments < Redcarpet::Render::HTML
8
- def block_code(code, language)
9
- Pygments.highlight(code, :lexer => language)
10
- rescue Exception
11
- <<-HTML
12
- <div class="highlight"><pre>#{CGI.escapeHTML(code)}</pre></div>
13
- HTML
14
- end
15
- end
16
-
17
7
  module TDiary
18
8
  module Style
19
9
  class GfmSection
20
- include Twitter::Autolink
21
-
22
10
  def initialize(fragment, author = nil)
23
11
  @author = author
24
12
  @subtitle, @body = fragment.split(/\n/, 2)
@@ -64,35 +52,35 @@ module TDiary
64
52
  private
65
53
 
66
54
  def to_html(string)
67
- renderer = HTMLwithPygments.new(:hard_wrap => true)
68
- extensions = {:fenced_code_blocks => true, :tables => true, :no_intra_emphasis => true}
69
- r = Redcarpet::Markdown.new(renderer, extensions).render(string)
70
-
71
- # Twitter Autolink
72
- r = auto_link(r)
73
-
74
- if r =~ /(<pre>|<code>)/
75
- r.gsub!(/<a class=\"tweet-url username\" href=\".*?\">(.*?)<\/a>/){ $1 }
55
+ # 1. Stash plugin calls
56
+ plugin_stashes = []
57
+ r = string.gsub(/\{\{(.*?)\}\}/) do
58
+ # Convert `{{ }}' to erb tags
59
+ plugin_stashes.push("<%=#{$1}%>")
60
+ "@@tdiary_style_gfm_plugin#{plugin_stashes.length - 1}@@"
76
61
  end
77
62
 
78
- # except url autolink in plugin block
79
- if r =~ /\{\{.+?\}\}/
80
- r.gsub!(/<a href=\"(.*?)\" rel=\"nofollow\">.*?<\/a>/){ $1 }
81
- r.gsub!(/\{\{(.+?)\}\}/) { "<%=#{CGI.unescapeHTML($1).gsub(/&#39;/, "'").gsub(/&quot;/, '"')}%>" }
63
+ # 2. Apply markdown conversion
64
+ r = GitHub::Markdown.to_html(r, :gfm) do |code, lang|
65
+ begin
66
+ Pygments.highlight(code, :lexer => lang)
67
+ rescue Exception => ex
68
+ "<div class=\"highlight\"><pre>#{CGI.escapeHTML(code)}</pre></div>"
69
+ end
82
70
  end
83
71
 
84
- # ignore duplicate autolink
85
- if r =~ /<a href="<a href="/
86
- r.gsub!(/<a href="<a href=".*?" rel="nofollow">(.*?)<\/a>"(.*?)>(.*?)<\/a>/) do
87
- "<a href=\"#{$1}\" rel=\"nofollow\"#{$2}>#{$3}</a>"
88
- end
72
+ # 3. Stash <pre> tags
73
+ pre_tag_stashes = []
74
+ r.gsub!(/<pre>(.*?)<\/pre>/) do |matched|
75
+ pre_tag_stashes.push(matched)
76
+ "@@tdiary_style_gfm_pre_tag#{pre_tag_stashes.length - 1}@@"
89
77
  end
90
- # ignore auto imagelink
91
- if r =~ /<img src="<a href="/
92
- r.gsub!(/<img src="<a href=".*?" rel="nofollow">(.*?)<\/a>"(?: alt="(.*?)")?>/){ "<img src=\"#{$1}\" alt=\"#{$2}\">" }
78
+
79
+ # 4. Convert miscellaneous
80
+ unless r =~ /(<pre>|<code>)/
81
+ r = Twitter::Autolink.auto_link_usernames_or_lists(r)
93
82
  end
94
83
 
95
- # emoji
96
84
  r = r.emojify
97
85
 
98
86
  # diary anchor
@@ -108,6 +96,14 @@ module TDiary
108
96
  end
109
97
  }
110
98
 
99
+ # 5. Unstash pre and plugin
100
+ pre_tag_stashes.each.with_index do |str, i|
101
+ r.sub!(/@@tdiary_style_gfm_pre_tag#{i}@@/, str)
102
+ end
103
+ plugin_stashes.each.with_index do |str, i|
104
+ r.sub!(/@@tdiary_style_gfm_plugin#{i}@@/, str)
105
+ end
106
+
111
107
  r
112
108
  end
113
109
 
@@ -1,7 +1,7 @@
1
- module Tdiary
1
+ module TDiary
2
2
  module Style
3
3
  module Gfm
4
- VERSION = "0.0.3"
4
+ VERSION = "0.1.1"
5
5
  end
6
6
  end
7
7
  end
@@ -113,12 +113,12 @@ http://www.google.com
113
113
  <%=section_enter_proc( Time.at( 1041346800 ) )%>
114
114
  <h3><%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %></h3>
115
115
  <ul>
116
- <li><a href="http://www.google.com" rel="nofollow">http://www.google.com</a></li>
116
+ <li><a href="http://www.google.com">http://www.google.com</a></li>
117
117
  </ul>
118
118
 
119
- <p><a href="https://www.google.com" rel="nofollow">google</a></p>
119
+ <p><a href="https://www.google.com">google</a></p>
120
120
 
121
- <p><a href="http://www.google.com" rel="nofollow">http://www.google.com</a></p>
121
+ <p><a href="http://www.google.com">http://www.google.com</a></p>
122
122
  <%=section_leave_proc( Time.at( 1041346800 ) )%>
123
123
  </div>
124
124
  EOF
@@ -165,7 +165,7 @@ http://www.google.com
165
165
  <div class="section">
166
166
  <%=section_enter_proc( Time.at( 1041346800 ) )%>
167
167
  <h3><%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %></h3>
168
- <p><a href="http://www.exaple.com" rel="nofollow" target="_blank">Anchor</a></p>
168
+ <p><a href="http://www.exaple.com" target="_blank">Anchor</a></p>
169
169
  <%=section_leave_proc( Time.at( 1041346800 ) )%>
170
170
  </div>
171
171
  EOF
@@ -195,7 +195,7 @@ http://example.com is example.com
195
195
  <h3><%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %></h3>
196
196
  <div class="highlight"><pre><span class="vi">@foo</span>
197
197
  </pre></div>
198
- <p><a href="http://example.com" rel="nofollow">http://example.com</a> is example.com</p>
198
+ <p><a href="http://example.com">http://example.com</a> is example.com</p>
199
199
  <%=section_leave_proc( Time.at( 1041346800 ) )%>
200
200
  </div>
201
201
  EOF
@@ -217,7 +217,7 @@ http://example.com is example.com
217
217
  <div class="section">
218
218
  <%=section_enter_proc( Time.at( 1041346800 ) )%>
219
219
  <h3><%= subtitle_proc( Time.at( 1041346800 ), "subTitle" ) %></h3>
220
- <p><a href="http://example.com" rel="nofollow">example</a> is example.com</p>
220
+ <p><a href="http://example.com">example</a> is example.com</p>
221
221
  <%=section_leave_proc( Time.at( 1041346800 ) )%>
222
222
  </div>
223
223
  EOF
@@ -369,6 +369,23 @@ http://example.com is example.com
369
369
  end
370
370
  it { @diary.to_html.should eq @html }
371
371
  end
372
+
373
+ describe 'do not modify original string' do
374
+ before do
375
+ @orig_source = <<-'EOF'
376
+ # subTitle
377
+
378
+ {{fn 'テスト'}}"
379
+ EOF
380
+ @source = @orig_source.dup
381
+ @diary.append(@source)
382
+ @diary.to_html
383
+
384
+ @section = nil
385
+ @diary.each_section{|x| @section = x}
386
+ end
387
+ it { expect(@section.body).to eq("\n"+@orig_source.lines.to_a.last+"\n") }
388
+ end
372
389
  end
373
390
 
374
391
  # Local Variables:
@@ -5,12 +5,12 @@ require 'tdiary/style/gfm/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "tdiary-style-gfm"
8
- spec.version = Tdiary::Style::Gfm::VERSION
8
+ spec.version = TDiary::Style::Gfm::VERSION
9
9
  spec.authors = ["SHIBATA Hiroshi"]
10
10
  spec.email = ["shibata.hiroshi@gmail.com"]
11
11
  spec.description = %q{GFM Style for tDiary}
12
12
  spec.summary = %q{GFM Style for tDiary}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/tdiary/tdiary-style-gfm"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency 'redcarpet'
21
+ spec.add_dependency 'github-markdown'
22
22
  spec.add_dependency 'pygments.rb'
23
23
  spec.add_dependency 'twitter-text'
24
24
 
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tdiary-style-gfm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - SHIBATA Hiroshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-28 00:00:00.000000000 Z
11
+ date: 2013-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: redcarpet
14
+ name: github-markdown
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -114,7 +114,7 @@ files:
114
114
  - spec/spec_helper.rb
115
115
  - spec/tdiary/style/gfm_spec.rb
116
116
  - tdiary-style-gfm.gemspec
117
- homepage: ''
117
+ homepage: https://github.com/tdiary/tdiary-style-gfm
118
118
  licenses:
119
119
  - MIT
120
120
  metadata: {}
@@ -134,11 +134,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  version: '0'
135
135
  requirements: []
136
136
  rubyforge_project:
137
- rubygems_version: 2.1.3
137
+ rubygems_version: 2.2.0
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: GFM Style for tDiary
141
141
  test_files:
142
142
  - spec/spec_helper.rb
143
143
  - spec/tdiary/style/gfm_spec.rb
144
- has_rdoc: