hateda2md 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -24,8 +24,8 @@ Or install it yourself as:
24
24
 
25
25
  mdb = HateDa::MdBuilder.new('hatena-diary.xml')
26
26
 
27
- # set several pre-defined filters
28
- # 幾つかの定義済みフィルタをセットする
27
+ # set pre-defined filters
28
+ # 定義済みフィルタをセットする
29
29
  mdb.set :title
30
30
  mdb.set :subtitle
31
31
  mdb.set :link
@@ -56,9 +56,13 @@ To set all pre-defined filters, you can call `MdBuilder#pre_defined_filters` or
56
56
  # すべての定義済みフィルタをセットする
57
57
  filters.each { |f| mdb.set f }
58
58
 
59
- You can define filters.
59
+ Filters of super_pre, footnote, hatebu, amazon, youtube, gist are create a liquid tag. Only for hatebu, youtube, gist, you can select html code to be created, instead of liquid tag by passing false as its second parameter.
60
60
 
61
- 独自フィルタを定義できます。
61
+ super_pre, footnote, hatebu, amazon, youtube, gistの各フィルタはliquid tagを生成します。hatebu, youtube, gistのフィルタに関しては、その第2引数にfalseを渡すことで、liquid tagに代えてhtmlコードを生成させることができます。
62
+
63
+ You can define your filters using `MdBuilder#filter` method.
64
+
65
+ `MdBuilder#filter`を使って、独自フィルタを定義できます。
62
66
 
63
67
  # define a filter to convert wikipedia hatena tag to a correspond liquid tag
64
68
  # はてな記法によるwikipediaタグをliquid tagに変換するフィルタを定義する
@@ -86,13 +86,13 @@ module HateDa::Converter
86
86
 
87
87
  def blockquote
88
88
  filter(/^>>\n(.*?)^<<$/m) do |md|
89
- "\n" + md[1].lines.map { |line| "> #{line}" }.join
89
+ "\n" + md[1].gsub(/^.*$/, '> \0')
90
90
  end
91
91
  end
92
92
 
93
93
  def pre
94
94
  filter(/^>\|\n(.*?)^\|<$/m) do |md|
95
- "\n" + md[1].lines.map { |line| " #{line}" }.join
95
+ "\n" + md[1].gsub(/^.*$/, ' \0')
96
96
  end
97
97
  end
98
98
 
@@ -130,10 +130,14 @@ module HateDa::Converter
130
130
  end
131
131
  end
132
132
 
133
- def hatebu
133
+ def hatebu(liquid=true)
134
134
  url_r = URI.regexp(['http', 'https'])
135
135
  filter(/\[(#{url_r}):bookmark\]/) do |md|
136
- "{% hatebu #{md[1]} %}"
136
+ if liquid
137
+ "{% hatebu #{md[1]} %}"
138
+ else
139
+ hatebu_html(md[1])
140
+ end
137
141
  end
138
142
  end
139
143
 
@@ -152,9 +156,13 @@ module HateDa::Converter
152
156
  end
153
157
  end
154
158
 
155
- def youtube
159
+ def youtube(liquid=true)
156
160
  filter(/[\(\[]?\s*https?:\/\/.*?youtube.*?\?v=([a-zA-Z0-9_-]+):movie\s*[\]\)]?/) do |md|
157
- "{% youtube #{md[1]} %}"
161
+ if liquid
162
+ "{% youtube #{md[1]} %}"
163
+ else
164
+ youtube_html(md)
165
+ end
158
166
  end
159
167
  end
160
168
 
@@ -167,10 +175,33 @@ module HateDa::Converter
167
175
  end
168
176
  end
169
177
 
170
- def gist
178
+ def gist(liquid=true)
171
179
  host = %r{https?://gist.github.com/}
172
180
  filter(/<script src=\"#{host}(\d+)\.js\?file=(.*?)\"><\/script>/) do |md|
173
- "{% gist #{md[1]} #{md[2]} %}"
181
+ if liquid
182
+ "{% gist #{md[1]} #{md[2]} %}"
183
+ else
184
+ gist_html(md)
185
+ end
186
+ end
187
+ end
188
+
189
+ def hatebu_html(md)
190
+ url, title = md.to_s.match(/(https?:\/\/\S+)(.*)/){ [$1, $2] }
191
+ bm_url = %{<a href="http://b.hatena.ne.jp/entry/#{url}" class="http-bookmark" target="_blank"><img src="http://b.hatena.ne.jp/entry/image/#{url}" alt="" class="http-bookmark"></a>}
192
+
193
+ unless title.nil?
194
+ %{<a href="#{url}" target="_blank">#{title.strip} </a>} + bm_url
195
+ else
196
+ bm_url
174
197
  end
175
198
  end
176
- end
199
+
200
+ def gist_html(md)
201
+ %{<div><script src="https://gist.github.com/#{md[1]}.js?file=#{md[2]}"></script></div>%}
202
+ end
203
+
204
+ def youtube_html(md)
205
+ %{<iframe width="560" height="420" src="http://www.youtube.com/embed/#{md[1]}?color=white&theme=light"></iframe>}
206
+ end
207
+ end
@@ -1,3 +1,3 @@
1
1
  module Hateda2md
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hateda2md
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-04 00:00:00.000000000 Z
12
+ date: 2012-05-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2160489100 !ruby/object:Gem::Requirement
16
+ requirement: &2153731440 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2160489100
24
+ version_requirements: *2153731440
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nokogiri
27
- requirement: &2160488640 !ruby/object:Gem::Requirement
27
+ requirement: &2153730980 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2160488640
35
+ version_requirements: *2153730980
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: gsub_filter
38
- requirement: &2160488220 !ruby/object:Gem::Requirement
38
+ requirement: &2153730560 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2160488220
46
+ version_requirements: *2153730560
47
47
  description: Convert Hatena-Diary XML file to Markdown files for Jekyll
48
48
  email:
49
49
  - postagie@gmail.com