tdiary-style-gfm 0.0.3 → 0.1.1
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 +4 -4
- data/.travis.yml +3 -1
- data/README.md +1 -1
- data/lib/tdiary/style/gfm.rb +31 -35
- data/lib/tdiary/style/gfm/version.rb +2 -2
- data/spec/tdiary/style/gfm_spec.rb +23 -6
- data/tdiary-style-gfm.gemspec +3 -3
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e50242d3e4c9de5a6471cd39305d19ecc63db7b3
|
4
|
+
data.tar.gz: 7581983b9fab9eee31fd720f5f0b3cca84cce960
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4db97817b2b3d1cf8142598fb6726e37a1cccf7c1e7f58c3878b4289c2b3a85e2ab2c7c11a5d72c88506143d6c53a39275df852d85e2f7da4456f50eb1834011
|
7
|
+
data.tar.gz: 34b54f4903d6675fbf27e15228b46289b0305594a52bb1fd4b90473e4e141a9b026dbb1bee7fbbcfe9bfe326ce83a05f9c9a3f95088b4e41f6bb5090da7a0af3
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
data/lib/tdiary/style/gfm.rb
CHANGED
@@ -1,24 +1,12 @@
|
|
1
1
|
# -*- coding: utf-8; -*-
|
2
2
|
|
3
|
-
require '
|
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
|
-
|
68
|
-
|
69
|
-
r =
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
-
#
|
79
|
-
|
80
|
-
|
81
|
-
|
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
|
-
#
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
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
|
|
@@ -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"
|
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"
|
119
|
+
<p><a href="https://www.google.com">google</a></p>
|
120
120
|
|
121
|
-
<p><a href="http://www.google.com"
|
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"
|
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"
|
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"
|
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:
|
data/tdiary-style-gfm.gemspec
CHANGED
@@ -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 =
|
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 '
|
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.
|
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-
|
11
|
+
date: 2013-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
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.
|
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:
|