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 +7 -4
- data/hateda2md.gemspec +0 -1
- data/lib/hateda2md.rb +1 -0
- data/lib/hateda2md/mdbuilder.rb +10 -18
- data/lib/hateda2md/system_extension.rb +10 -0
- data/lib/hateda2md/version.rb +1 -1
- data/spec/hateda_converter_spec.rb +124 -124
- data/spec/spec_helper.rb +1 -0
- data/spec/test2.xml +1 -0
- metadata +13 -13
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
|
39
|
-
#
|
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
|
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
|
|
data/hateda2md.gemspec
CHANGED
data/lib/hateda2md.rb
CHANGED
data/lib/hateda2md/mdbuilder.rb
CHANGED
@@ -1,15 +1,5 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
require "
|
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 =
|
22
|
-
|
23
|
-
|
24
|
-
|
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']
|
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
|
data/lib/hateda2md/version.rb
CHANGED
@@ -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 =
|
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 =
|
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 =
|
135
|
-
1. item1
|
136
|
-
|
137
|
-
|
138
|
-
1. item2
|
139
|
-
1. item3
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
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 =
|
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 =
|
170
|
-
- item1
|
171
|
-
|
172
|
-
|
173
|
-
- item2
|
174
|
-
- item3
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
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 =
|
190
|
-
>>
|
191
|
-
blockquoted
|
192
|
-
blockquoted
|
193
|
-
blockquoted
|
194
|
-
<<
|
195
|
-
EOS
|
196
|
-
|
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 =
|
209
|
-
>|
|
210
|
-
blockquoted
|
211
|
-
blockquoted
|
212
|
-
blockquoted
|
213
|
-
|<
|
214
|
-
EOS
|
215
|
-
|
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 =
|
228
|
-
>|ruby|
|
229
|
-
def hello(name)
|
230
|
-
|
231
|
-
end
|
232
|
-
||<
|
233
|
-
EOS
|
234
|
-
|
235
|
-
{% highlight ruby %}
|
236
|
-
def hello(name)
|
237
|
-
|
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 =
|
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 =
|
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 =
|
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 =
|
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
|
data/spec/spec_helper.rb
CHANGED
data/spec/test2.xml
CHANGED
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
|
+
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-
|
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:
|
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:
|
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:
|
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:
|
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.
|
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
|