hateda2md 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -19,6 +19,9 @@ Or install it yourself as:
19
19
  $ gem install hateda2md
20
20
 
21
21
  ## Usage
22
+ First of all, you get `username.xml` file from export section of your Hatena Dairy Admin. Then process followings:
23
+
24
+ 最初に`username.xml`ファイル(はてなの日記データ形式)を、はてなダイアリーのエクスポート頁から取得します。そして次のように処理します。
22
25
 
23
26
  require "Hateda2md"
24
27
 
@@ -35,13 +38,13 @@ Or install it yourself as:
35
38
  # 変換を実行する
36
39
  mdb.run
37
40
 
38
- # save converted data to separated markdown files correspond to each entry
39
- # 変換後のデータを各エントリーに対応した複数のMarkdownファイルに保存する
41
+ # save converted data to separated markdown files correspond to each diary
42
+ # 変換後のデータを各日記に対応した複数のMarkdownファイルに保存する
40
43
  mdb.save_to_files
41
44
 
42
- This process create several markdown files under `md` directory.
45
+ This process create several markdown files, which correspond to each diary, not each entry, under `md` directory. The filenames are constructed from date and title of each diary. Non-ASCII words are removed from the title part in the filename.
43
46
 
44
- 本処理により`md`ディレクトリ以下に、複数のmarkdownファイルが生成されます。
47
+ 本処理により`md`ディレクトリ以下に、(各エントリではなく)各日記に対応した複数のmarkdownファイルが生成されます。そのファイル名は各日記の日付とタイトルで構成されます。ASCII以外の文字はファイル名のタイトル部分から除去されます。
45
48
 
46
49
  To set all pre-defined filters, you can call `MdBuilder#pre_defined_filters` or `HateDa::Converter.pre_defined_filters` method.
47
50
 
@@ -17,6 +17,5 @@ Gem::Specification.new do |gem|
17
17
  gem.version = Hateda2md::VERSION
18
18
  gem.required_ruby_version = '>=1.9.2'
19
19
  gem.add_development_dependency 'rspec'
20
- gem.add_dependency 'nokogiri'
21
20
  gem.add_dependency 'gsub_filter'
22
21
  end
@@ -4,6 +4,7 @@ module HateDa
4
4
  require_relative 'hateda2md/entry'
5
5
  require_relative 'hateda2md/mdbuilder'
6
6
  require_relative 'hateda2md/converter'
7
+ require_relative 'hateda2md/system_extension'
7
8
 
8
9
  Entry.send(:include, Converter)
9
10
  end
@@ -1,15 +1,5 @@
1
1
  # encoding: UTF-8
2
- require "nokogiri"
3
- class String
4
- def ~
5
- mergin = scan(/^ +/).map(&:size).min
6
- gsub(/^ {#{mergin}}/, '')
7
- end
8
-
9
- def to_nil
10
- self.empty? ? nil : self
11
- end
12
- end
2
+ require "rexml/document"
13
3
 
14
4
  class HateDa::MdBuilder
15
5
  attr_reader :entries
@@ -18,14 +8,16 @@ class HateDa::MdBuilder
18
8
  end
19
9
 
20
10
  def build_entries(filepath)
21
- xml = Nokogiri::XML(open filepath)
22
- xml.search('day').map do |ent|
23
- date = ent.attributes['date'].value
24
- body = ent.css('body').text.strip
11
+ xml = REXML::Document.new(open filepath)
12
+ res = []
13
+ xml.elements.each('diary/day') do |ent|
14
+ date = ent.attributes['date']
15
+ body = ent.elements['body'].text.strip
25
16
  mdbody = nil
26
- title = ent.attributes['title'].value
27
- HateDa::Entry[date, body, mdbody, title]
17
+ title = ent.attributes['title']
18
+ res << HateDa::Entry[date, body, mdbody, title]
28
19
  end
20
+ res
29
21
  end
30
22
 
31
23
  def set(item, *args)
@@ -43,7 +35,7 @@ class HateDa::MdBuilder
43
35
  def run(*range)
44
36
  range = [0..-1] if range.empty?
45
37
  entries[*range].map do |entry|
46
- md = entry.to_md(entry.ent_body)
38
+ md = entry.to_md(entry.ent_body) # place this before use of get_title()
47
39
  entry.ent_title = get_title(entry) if entry.ent_title.empty?
48
40
  entry.ent_mdbody = md
49
41
  entry
@@ -0,0 +1,10 @@
1
+ class String
2
+ def ~
3
+ mergin = scan(/^ +/).map(&:size).min
4
+ gsub(/^ {#{mergin}}/, '')
5
+ end
6
+
7
+ def to_nil
8
+ self.empty? ? nil : self
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module Hateda2md
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -7,18 +7,18 @@ include HateDa::Converter
7
7
  describe HateDa::Converter do
8
8
  context "pass a text to to_md method" do
9
9
  before(:each) do
10
- @hdtext = <<EOS
11
- *p1*title1
12
- content1
13
- content2
14
- **subtitle1
15
- content3
16
- content4
17
- **subtitle2
18
- contetn5
19
- *123*title2
20
-
21
- EOS
10
+ @hdtext = ~<<-EOS
11
+ *p1*title1
12
+ content1
13
+ content2
14
+ **subtitle1
15
+ content3
16
+ content4
17
+ **subtitle2
18
+ contetn5
19
+ *123*title2
20
+
21
+ EOS
22
22
  end
23
23
 
24
24
  after(:each) do
@@ -119,29 +119,29 @@ EOS
119
119
  end
120
120
 
121
121
  it "change nested ordered list" do
122
- hdtext = <<EOS
123
- +item1
124
- ++item1-1
125
- ++item1-2
126
- +item2
127
- +item3
128
- ++item3-1
129
- +++item3-1-1
130
- +++item3-1-2
131
- ++item3-2
132
- EOS
122
+ hdtext = ~<<-EOS
123
+ +item1
124
+ ++item1-1
125
+ ++item1-2
126
+ +item2
127
+ +item3
128
+ ++item3-1
129
+ +++item3-1-1
130
+ +++item3-1-2
131
+ ++item3-2
132
+ EOS
133
133
 
134
- md = <<EOS
135
- 1. item1
136
- 1. item1-1
137
- 1. item1-2
138
- 1. item2
139
- 1. item3
140
- 1. item3-1
141
- 1. item3-1-1
142
- 1. item3-1-2
143
- 1. item3-2
144
- EOS
134
+ md = ~<<-EOS
135
+ 1. item1
136
+ 1. item1-1
137
+ 1. item1-2
138
+ 1. item2
139
+ 1. item3
140
+ 1. item3-1
141
+ 1. item3-1-1
142
+ 1. item3-1-2
143
+ 1. item3-2
144
+ EOS
145
145
  set :order_list
146
146
  to_md(hdtext).should eql md
147
147
  end
@@ -154,29 +154,29 @@ EOS
154
154
  end
155
155
 
156
156
  it "change nested unordered list" do
157
- hdtext = <<EOS
158
- -item1
159
- --item1-1
160
- --item1-2
161
- -item2
162
- -item3
163
- --item3-1
164
- ---item3-1-1
165
- ---item3-1-2
166
- --item3-2
167
- EOS
168
-
169
- md = <<EOS
170
- - item1
171
- - item1-1
172
- - item1-2
173
- - item2
174
- - item3
175
- - item3-1
176
- - item3-1-1
177
- - item3-1-2
178
- - item3-2
179
- EOS
157
+ hdtext = ~<<-EOS
158
+ -item1
159
+ --item1-1
160
+ --item1-2
161
+ -item2
162
+ -item3
163
+ --item3-1
164
+ ---item3-1-1
165
+ ---item3-1-2
166
+ --item3-2
167
+ EOS
168
+
169
+ md = ~<<-EOS
170
+ - item1
171
+ - item1-1
172
+ - item1-2
173
+ - item2
174
+ - item3
175
+ - item3-1
176
+ - item3-1-1
177
+ - item3-1-2
178
+ - item3-2
179
+ EOS
180
180
  set :unorder_list
181
181
  to_md(hdtext).should eql md
182
182
  end
@@ -186,58 +186,58 @@ EOS
186
186
 
187
187
  context "pre" do
188
188
  it "change blockquote '>> <<' to '>'" do
189
- hdtext = <<EOS
190
- >>
191
- blockquoted
192
- blockquoted
193
- blockquoted
194
- <<
195
- EOS
196
- md = <<EOS
197
-
198
- > blockquoted
199
- > blockquoted
200
- > blockquoted
201
-
202
- EOS
189
+ hdtext = ~<<-EOS
190
+ >>
191
+ blockquoted
192
+ blockquoted
193
+ blockquoted
194
+ <<
195
+ EOS
196
+ md = ~<<-EOS
197
+
198
+ > blockquoted
199
+ > blockquoted
200
+ > blockquoted
201
+
202
+ EOS
203
203
  set :blockquote
204
204
  to_md(hdtext).should eql md
205
205
  end
206
206
 
207
207
  it "change pre '>|' to 4 spaces" do
208
- hdtext = <<EOS
209
- >|
210
- blockquoted
211
- blockquoted
212
- blockquoted
213
- |<
214
- EOS
215
- md = <<EOS
208
+ hdtext = ~<<-EOS
209
+ >|
210
+ blockquoted
211
+ blockquoted
212
+ blockquoted
213
+ |<
214
+ EOS
215
+ md = <<-EOS
216
216
 
217
217
  blockquoted
218
218
  blockquoted
219
219
  blockquoted
220
220
 
221
- EOS
221
+ EOS
222
222
  set :pre
223
223
  to_md(hdtext).should eql md
224
224
  end
225
225
 
226
226
  it "change super_pre '>|type|' to highlight tag" do
227
- hdtext = <<EOS
228
- >|ruby|
229
- def hello(name)
230
- "hello, \#{name}!"
231
- end
232
- ||<
233
- EOS
234
- md = <<EOS
235
- {% highlight ruby %}
236
- def hello(name)
237
- "hello, \#{name}!"
238
- end
239
- {% endhighlight %}
240
- EOS
227
+ hdtext = ~<<-EOS
228
+ >|ruby|
229
+ def hello(name)
230
+ "hello, \#{name}!"
231
+ end
232
+ ||<
233
+ EOS
234
+ md = ~<<-EOS
235
+ {% highlight ruby %}
236
+ def hello(name)
237
+ "hello, \#{name}!"
238
+ end
239
+ {% endhighlight %}
240
+ EOS
241
241
  set :super_pre
242
242
  to_md(hdtext).should eql md
243
243
  end
@@ -264,41 +264,41 @@ EOS
264
264
 
265
265
  context "link" do
266
266
  it "change a url to a link" do
267
- hdtext = <<EOS
268
- sentence
269
- http://www.abc.com
270
- sentence http://www.efg.com/123_456 sentence
271
- sentence(https://www.xyz.co.jp),sen..
272
- EOS
273
- md = <<EOS
274
- sentence
275
- [http://www.abc.com](http://www.abc.com)
276
- sentence [http://www.efg.com/123_456](http://www.efg.com/123_456) sentence
277
- sentence([https://www.xyz.co.jp](https://www.xyz.co.jp)),sen..
278
- EOS
267
+ hdtext = ~<<-EOS
268
+ sentence
269
+ http://www.abc.com
270
+ sentence http://www.efg.com/123_456 sentence
271
+ sentence(https://www.xyz.co.jp),sen..
272
+ EOS
273
+ md = ~<<-EOS
274
+ sentence
275
+ [http://www.abc.com](http://www.abc.com)
276
+ sentence [http://www.efg.com/123_456](http://www.efg.com/123_456) sentence
277
+ sentence([https://www.xyz.co.jp](https://www.xyz.co.jp)),sen..
278
+ EOS
279
279
  set :link
280
280
  to_md(hdtext).should eql md
281
281
  end
282
282
 
283
283
  it "change a url with title to a link" do
284
- hdtext = <<EOS
285
- *p1*Title X
286
- sentence
287
- [http://www.abc.com/:title]
288
- sentence [http://www.efg.com/123_456:title=Title1] sentence
289
- *p3*Title Y
290
- sentence([https://www.xyz.co.jp/:title=Title no.2]),sen..
291
- http://mmm.ff.co.jp/
292
- EOS
293
- md = <<EOS
294
- #Title X
295
- sentence
296
- [Title X](http://www.abc.com/)
297
- sentence [Title1](http://www.efg.com/123_456) sentence
298
- #Title Y
299
- sentence([Title no.2](https://www.xyz.co.jp/)),sen..
300
- [http://mmm.ff.co.jp/](http://mmm.ff.co.jp/)
301
- EOS
284
+ hdtext = ~<<-EOS
285
+ *p1*Title X
286
+ sentence
287
+ [http://www.abc.com/:title]
288
+ sentence [http://www.efg.com/123_456:title=Title1] sentence
289
+ *p3*Title Y
290
+ sentence([https://www.xyz.co.jp/:title=Title no.2]),sen..
291
+ http://mmm.ff.co.jp/
292
+ EOS
293
+ md = ~<<-EOS
294
+ #Title X
295
+ sentence
296
+ [Title X](http://www.abc.com/)
297
+ sentence [Title1](http://www.efg.com/123_456) sentence
298
+ #Title Y
299
+ sentence([Title no.2](https://www.xyz.co.jp/)),sen..
300
+ [http://mmm.ff.co.jp/](http://mmm.ff.co.jp/)
301
+ EOS
302
302
  set :title
303
303
  set :link
304
304
  to_md(hdtext).should eql md
@@ -2,3 +2,4 @@ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
2
2
 
3
3
  require "rspec"
4
4
  require "hateda2md"
5
+ require "hateda2md/system_extension"
@@ -23,3 +23,4 @@ line4
23
23
  line5
24
24
  </body>
25
25
  </day>
26
+ </diary>
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.4
4
+ version: 0.0.5
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-06 00:00:00.000000000 Z
12
+ date: 2012-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2156110820 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2156110820
25
- - !ruby/object:Gem::Dependency
26
- name: nokogiri
27
- requirement: &2156110360 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
28
25
  none: false
29
26
  requirements:
30
27
  - - ! '>='
31
28
  - !ruby/object:Gem::Version
32
29
  version: '0'
33
- type: :runtime
34
- prerelease: false
35
- version_requirements: *2156110360
36
30
  - !ruby/object:Gem::Dependency
37
31
  name: gsub_filter
38
- requirement: &2156109940 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
39
33
  none: false
40
34
  requirements:
41
35
  - - ! '>='
@@ -43,7 +37,12 @@ dependencies:
43
37
  version: '0'
44
38
  type: :runtime
45
39
  prerelease: false
46
- version_requirements: *2156109940
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
47
46
  description: Convert Hatena-Diary XML file to Markdown files for Jekyll
48
47
  email:
49
48
  - postagie@gmail.com
@@ -63,6 +62,7 @@ files:
63
62
  - lib/hateda2md/converter.rb
64
63
  - lib/hateda2md/entry.rb
65
64
  - lib/hateda2md/mdbuilder.rb
65
+ - lib/hateda2md/system_extension.rb
66
66
  - lib/hateda2md/version.rb
67
67
  - spec/hateda_converter_spec.rb
68
68
  - spec/hateda_entry_spec.rb
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  version: '0'
91
91
  requirements: []
92
92
  rubyforge_project:
93
- rubygems_version: 1.8.11
93
+ rubygems_version: 1.8.24
94
94
  signing_key:
95
95
  specification_version: 3
96
96
  summary: This is a converter that build separated markdown files using for Jekyll