bluefeather 0.33 → 0.40

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.
@@ -18,7 +18,7 @@
18
18
  <li><a href="http://ja.wikipedia.org/wiki/GNU_General_Public_License">Wikipedia - GNU General Public License</a></li>
19
19
  </ul>
20
20
 
21
- <p>BlueFeather への要望、ご意見、バグ報告などがありましたら、<a href="http://ruby.morphball.net/bluefeather/">BlueFeather 配布サイト</a>よりメッセージを送信していただくか、もしくは Dice(<a href="&#x6D;&#097;&#x69;l&#116;&#x6F;:&#x74;&#101;&#116;&#x72;a&#x64;&#x69;&#099;&#x65;&#064;&#103;&#109;a&#105;&#x6C;&#x2E;&#x63;&#x6F;&#109;">&#x74;&#101;&#116;&#x72;a&#x64;&#x69;&#099;&#x65;&#064;&#103;&#109;a&#105;&#x6C;&#x2E;&#x63;&#x6F;&#109;</a>)までメールでご連絡していただけるよう、よろしくお願いします。</p>
21
+ <p>BlueFeather への要望、ご意見、バグ報告などがありましたら、<a href="http://ruby.morphball.net/bluefeather/">BlueFeather 配布サイト</a>よりメッセージを送信していただくか、もしくは Dice(<a href="m&#x61;&#105;&#108;&#116;&#111;:&#116;&#x65;&#x74;&#x72;&#x61;&#100;&#x69;&#099;&#101;&#x40;&#103;&#109;&#x61;&#x69;&#x6C;&#046;c&#111;&#109;">&#116;&#x65;&#x74;&#x72;&#x61;&#100;&#x69;&#099;&#101;&#x40;&#103;&#109;&#x61;&#x69;&#x6C;&#046;c&#111;&#109;</a>)までメールでご連絡していただけるよう、よろしくお願いします。</p>
22
22
 
23
23
  </body>
24
24
  </html>
@@ -176,7 +176,7 @@ test3.html
176
176
  `-e NAME`, `--encoding NAME`
177
177
  :
178
178
  変換するテキストファイルのエンコーディングを、指定したエンコーディングとして解釈します。
179
- (`shift-jis` / `euc-jp` / `utf-8` / `none` のうちいずれか、もしくは最初の数文字。標準では `utf-8`)
179
+ (`shift-jis` / `euc-jp` / `utf-8` / `ascii` のうちいずれか、もしくは最初の数文字。標準では `utf-8`)
180
180
 
181
181
  `-f TYPE`, `--format TYPE`
182
182
  :
@@ -190,7 +190,7 @@ Test paragraph.
190
190
  <dt><code>-e NAME</code>, <code>--encoding NAME</code></dt>
191
191
  <dd>
192
192
  変換するテキストファイルのエンコーディングを、指定したエンコーディングとして解釈します。
193
- (<code>shift-jis</code> / <code>euc-jp</code> / <code>utf-8</code> / <code>none</code> のうちいずれか、もしくは最初の数文字。標準では <code>utf-8</code>)</dd>
193
+ (<code>shift-jis</code> / <code>euc-jp</code> / <code>utf-8</code> / <code>ascii</code> のうちいずれか、もしくは最初の数文字。標準では <code>utf-8</code>)</dd>
194
194
  <dt><code>-f TYPE</code>, <code>--format TYPE</code></dt>
195
195
  <dd>
196
196
  出力するhtmlの種別を特定します。
@@ -24,7 +24,7 @@
24
24
  <p>If you want to send requests, comments, or bug reports to BlueFeather, please
25
25
  feel free to post messages from
26
26
  <a href="http://ruby.morphball.net/bluefeather/index_en.html">http://ruby.morphball.net/bluefeather/index_en.html</a> or to send mail to Dice.
27
- (<a href="&#x6D;&#097;&#x69;&#x6C;&#x74;&#111;:&#116;&#x65;&#116;&#114;&#x61;d&#x69;&#x63;&#x65;&#x40;&#x67;&#x6D;&#097;&#x69;l.c&#111;&#x6D;">&#116;&#x65;&#116;&#114;&#x61;d&#x69;&#x63;&#x65;&#x40;&#x67;&#x6D;&#097;&#x69;l.c&#111;&#x6D;</a>)</p>
27
+ (<a href="&#109;&#097;&#105;&#108;&#x74;&#111;:&#116;&#x65;&#116;&#x72;&#097;&#100;&#x69;&#099;&#x65;&#x40;&#x67;m&#x61;&#105;&#x6C;&#046;&#x63;&#x6F;&#109;">&#116;&#x65;&#116;&#x72;&#097;&#100;&#x69;&#099;&#x65;&#x40;&#x67;m&#x61;&#105;&#x6C;&#046;&#x63;&#x6F;&#109;</a>)</p>
28
28
 
29
29
  </body>
30
30
  </html>
@@ -37,8 +37,8 @@ BlueFeather uses the following order.
37
37
  If you want to know about encoding header, see the [Metadata reference](metadata-reference.html).
38
38
 
39
39
  You can specify encoding.
40
- If you use with [`parse_document`](class-reference.html#parse_document) or [`parse_document_file`](class-reference.html#parse_document), you must use 2nd argument of these methods for it.
41
40
  If you use `bluefeather` command, you must use -e (--encoding) option for it.
41
+ If you use with [`parse_document`](class-reference.html#parse_document) or [`parse_document_file`](class-reference.html#parse_document), you must use 2nd argument of these methods for it.
42
42
 
43
43
 
44
44
 
@@ -40,8 +40,8 @@ Else if ruby 1.9.x later, it is based on encoding which String object has.</p>
40
40
  <p>If you want to know about encoding header, see the <a href="metadata-reference.html">Metadata reference</a>.</p>
41
41
 
42
42
  <p>You can specify encoding.
43
- If you use with <a href="class-reference.html#parse_document"><code>parse_document</code></a> or <a href="class-reference.html#parse_document"><code>parse_document_file</code></a>, you must use 2nd argument of these methods for it.
44
- If you use <code>bluefeather</code> command, you must use -e (--encoding) option for it.</p>
43
+ If you use <code>bluefeather</code> command, you must use -e (--encoding) option for it.
44
+ If you use with <a href="class-reference.html#parse_document"><code>parse_document</code></a> or <a href="class-reference.html#parse_document"><code>parse_document_file</code></a>, you must use 2nd argument of these methods for it.</p>
45
45
 
46
46
  </body>
47
47
  </html>
@@ -10,7 +10,7 @@ BlueFeather Manual
10
10
 
11
11
  -> [Japanese version (original)](../index.html)
12
12
 
13
- (2009-11-22: this document based on version 0.33)
13
+ (2010-04-29: this document based on version 0.40)
14
14
 
15
15
  BlueFeather is software for converting text written by extended Markdown like
16
16
  [PHP Markdown Extra][] to html. It is pair of command-line tool and pure Ruby
@@ -12,7 +12,7 @@
12
12
 
13
13
  <p>-> <a href="../index.html">Japanese version (original)</a></p>
14
14
 
15
- <p>(2009-11-22: this document based on version 0.33)</p>
15
+ <p>(2010-04-29: this document based on version 0.40)</p>
16
16
 
17
17
  <p>BlueFeather is software for converting text written by extended Markdown like
18
18
  <a href="http://michelf.com/projects/php-markdown/extra/">PHP Markdown Extra</a> to html. It is pair of command-line tool and pure Ruby
@@ -31,9 +31,12 @@ CSS: black.css
31
31
  3. UTF-8
32
32
 
33
33
 
34
- 「文書メタデータの Encoding ヘッダ」については、[メタデータリファレンス](metadata-reference.html)内の[説明](metadata-reference.html#encoding)を参照してください。
34
+ 「1. 文書メタデータの Encoding ヘッダ」についての詳細は、[メタデータリファレンス](metadata-reference.html)内の[説明](metadata-reference.html#encoding)を参照してください。
35
35
 
36
- 変換時のエンコーディング指定は、[`parse_document`](class-reference.html#parse_document) メソッドや [`parse_document_file`](class-reference.html#parse_document) メソッドによる変換時にはメソッドの第二引数(default_enc)で、`bluefeather` コマンドであれば -e (--encoding) オプションで、それぞれ指定することが可能です。
36
+ 「2. 変換時に指定したエンコーディング」とは、以下のものを指します。
37
+
38
+ * `bluefeather` コマンドによる変換時は、 -e (--encoding) オプションで指定したエンコーディング。
39
+ * [`parse_document`](class-reference.html#parse_document) メソッドや [`parse_document_file`](class-reference.html#parse_document) メソッドによる変換時は、メソッドの第二引数(default_enc)で指定したエンコーディング。
37
40
 
38
41
 
39
42
 
@@ -36,9 +36,14 @@
36
36
  <li>UTF-8</li>
37
37
  </ol>
38
38
 
39
- <p>「文書メタデータの Encoding ヘッダ」については、<a href="metadata-reference.html">メタデータリファレンス</a>内の<a href="metadata-reference.html#encoding">説明</a>を参照してください。</p>
39
+ <p>「1. 文書メタデータの Encoding ヘッダ」についての詳細は、<a href="metadata-reference.html">メタデータリファレンス</a>内の<a href="metadata-reference.html#encoding">説明</a>を参照してください。</p>
40
40
 
41
- <p>変換時のエンコーディング指定は、<a href="class-reference.html#parse_document"><code>parse_document</code></a> メソッドや <a href="class-reference.html#parse_document"><code>parse_document_file</code></a> メソッドによる変換時にはメソッドの第二引数(default_enc)で、<code>bluefeather</code> コマンドであれば -e (--encoding) オプションで、それぞれ指定することが可能です。</p>
41
+ <p>「2. 変換時に指定したエンコーディング」とは、以下のものを指します。</p>
42
+
43
+ <ul>
44
+ <li><code>bluefeather</code> コマンドによる変換時は、 -e (--encoding) オプションで指定したエンコーディング。</li>
45
+ <li><a href="class-reference.html#parse_document"><code>parse_document</code></a> メソッドや <a href="class-reference.html#parse_document"><code>parse_document_file</code></a> メソッドによる変換時は、メソッドの第二引数(default_enc)で指定したエンコーディング。</li>
46
+ </ul>
42
47
 
43
48
  </body>
44
49
  </html>
@@ -9,7 +9,7 @@ BlueFeather マニュアル
9
9
  → [English version](en/index.html)
10
10
 
11
11
 
12
- 2009-11-22 バージョン 0.33 準拠)
12
+ 2010-04-29 バージョン 0.40 準拠)
13
13
 
14
14
  BlueFeather は、拡張 Markdown 記法で書かれたテキストを html に変換するソフトウェアです。
15
15
  コマンドラインツールと、Ruby スクリプト内で変換を行うためのライブラリがセットになっています。
@@ -13,7 +13,7 @@
13
13
 
14
14
  <p>→ <a href="en/index.html">English version</a></p>
15
15
 
16
- <p>(2009-11-22 バージョン 0.33 準拠)</p>
16
+ <p>(2010-04-29 バージョン 0.40 準拠)</p>
17
17
 
18
18
  <p>BlueFeather は、拡張 Markdown 記法で書かれたテキストを html に変換するソフトウェアです。
19
19
  コマンドラインツールと、Ruby スクリプト内で変換を行うためのライブラリがセットになっています。</p>
@@ -36,7 +36,7 @@ CSS スタイルシートの URL。生成される html 文書の head 要素内
36
36
 
37
37
  Encoding: utf-8
38
38
 
39
- その文書のマルチバイトエンコーディングを表す。utf-8, euc-jp, shift-jis, ascii のいずれかが有効(小文字と大文字は区別しない)。
39
+ その文書のマルチバイトエンコーディングを表す。utf-8, euc-jp, shift_jis (shift-jis), ascii のいずれかが有効(小文字と大文字は区別しない)。
40
40
  html の head 要素内に出力される Content-Type の値、および変換処理に影響する。
41
41
 
42
42
  なお、他のヘッダーの値をマルチバイト文字列で記述する場合、 *Encoding はそれらのヘッダーよりも先に記述されていなければならない。*
@@ -57,7 +57,7 @@ Atom-Feed: info/atom.xml
57
57
  <pre><code>Encoding: utf-8
58
58
  </code></pre>
59
59
 
60
- <p>その文書のマルチバイトエンコーディングを表す。utf-8, euc-jp, shift-jis, ascii のいずれかが有効(小文字と大文字は区別しない)。
60
+ <p>その文書のマルチバイトエンコーディングを表す。utf-8, euc-jp, shift_jis (shift-jis), ascii のいずれかが有効(小文字と大文字は区別しない)。
61
61
  html の head 要素内に出力される Content-Type の値、および変換処理に影響する。</p>
62
62
 
63
63
  <p>なお、他のヘッダーの値をマルチバイト文字列で記述する場合、 <em>Encoding はそれらのヘッダーよりも先に記述されていなければならない。</em>
@@ -42,9 +42,9 @@ require 'uri'
42
42
 
43
43
 
44
44
  module BlueFeather
45
- VERSION = '0.33'
46
- VERSION_NUMBER = 0.33
47
- RELEASE_DATE = '2009-11-22'
45
+ VERSION = '0.40'
46
+ VERSION_NUMBER = 0.40
47
+ RELEASE_DATE = '2010-04-29'
48
48
  VERSION_LABEL = "#{VERSION} (#{RELEASE_DATE})"
49
49
 
50
50
  UTF8_BOM = "\xef\xbb\xbf"
@@ -98,11 +98,16 @@ module BlueFeather
98
98
  end
99
99
  end
100
100
 
101
+ module HeaderIDType
102
+ MD5 = 'md5'
103
+ ESCAPE = 'escape'
104
+ end
105
+
101
106
  module EncodingType
102
107
  EUC = 'euc-jp'
103
108
  EUCJP = EUC_JP = EUC
104
109
 
105
- SJIS = 'shift-jis'
110
+ SJIS = 'shift_jis'
106
111
  SHIFT_JIS = SJIS
107
112
 
108
113
  UTF8 = 'utf-8'
@@ -111,19 +116,34 @@ module BlueFeather
111
116
  ASCII = 'ascii'
112
117
  US_ASCII = ASCII
113
118
 
114
- def self.type_to_kcode(type)
119
+ def self.regulate(str_value)
120
+ case str_value.downcase
121
+ when 'shift-jis', 'shift_jis'
122
+ SJIS
123
+ when 'euc-jp'
124
+ EUC
125
+ when 'utf-8'
126
+ UTF8
127
+ when 'ascii'
128
+ ASCII
129
+ else
130
+ raise EncodingError, "not adapted encoding type - #{str_value} (shift[-_]jis, euc-jp, utf-8, or ascii)"
131
+ end
132
+ end
133
+
134
+ def self.convert_to_kcode(str_value)
135
+ type = self.regulate(str_value)
115
136
  case type
116
137
  when EUC, SJIS, UTF8
117
138
  type
118
139
  when ASCII
119
140
  'none'
120
- else
121
- raise EncodingError, "not adapted encoding type - #{type} (shift-jis, euc-jp, utf-8, or ascii)"
122
141
  end
123
142
  end
124
143
 
125
144
 
126
- def self.type_to_charset(type)
145
+ def self.convert_to_charset(str_value)
146
+ type = self.regulate(str_value)
127
147
  case type
128
148
  when EUC
129
149
  'euc-jp'
@@ -131,10 +151,8 @@ module BlueFeather
131
151
  'shift_jis'
132
152
  when UTF8
133
153
  'utf-8'
134
- when ASCII, nil
154
+ when ASCII
135
155
  nil
136
- else
137
- raise EncodingError, "not adapted encoding type - #{type} (shift-jis, euc-jp, utf-8, or ascii)"
138
156
  end
139
157
  end
140
158
 
@@ -185,6 +203,23 @@ module BlueFeather
185
203
  end
186
204
  end # if defined?
187
205
  end # def
206
+
207
+
208
+ def utf8_bom?(str)
209
+ if str.respond_to?(:getbyte) and str.respond_to?(:bytesize) then
210
+ if str.bytesize >= 3 and
211
+ str.getbyte(0) == UTF8_BOM.getbyte(0) and
212
+ str.getbyte(1) == UTF8_BOM.getbyte(1) and
213
+ str.getbyte(2) == UTF8_BOM.getbyte(2) then
214
+ return true
215
+ else
216
+ return false
217
+ end
218
+
219
+ else
220
+ return(str =~ UTF8_BOM_PATTERN ? true : false)
221
+ end
222
+ end
188
223
  end
189
224
 
190
225
  class Document
@@ -201,8 +236,9 @@ module BlueFeather
201
236
  headers = {}
202
237
  body = nil
203
238
  first_pos = input.pos
239
+ default_enc = EncodingType.regulate(default_enc)
204
240
 
205
- Util.change_kcode(EncodingType.type_to_kcode(default_enc)){
241
+ Util.change_kcode(EncodingType.convert_to_kcode(default_enc)){
206
242
  # default encoding
207
243
  if defined?(Encoding) then
208
244
  input.set_encoding(Encoding.find(default_enc))
@@ -219,7 +255,7 @@ module BlueFeather
219
255
  line = input.gets
220
256
 
221
257
  # cut UTF-8 BOM
222
- if first_line and line =~ UTF8_BOM_PATTERN then
258
+ if first_line and Util.utf8_bom?(line) then
223
259
  line.slice!(UTF8_BOM_PATTERN)
224
260
  end
225
261
  first_line = false
@@ -228,9 +264,9 @@ module BlueFeather
228
264
  key = $1.downcase; value = $2
229
265
 
230
266
  if key == 'encoding' and not headers.include?('encoding') then
231
- kc = EncodingType.type_to_kcode(value.downcase)
267
+ kc = EncodingType.convert_to_kcode(value.downcase)
232
268
  if input.respond_to?(:set_encoding) then
233
- input.set_encoding(value.downcase)
269
+ input.set_encoding(EncodingType.regulate(value))
234
270
 
235
271
  # rewind (reason => [ruby-list:45988])
236
272
  input.pos = first_pos
@@ -284,7 +320,10 @@ module BlueFeather
284
320
 
285
321
 
286
322
  def initialize(headers = {}, body = '')
287
- @headers = headers
323
+ @headers = {}
324
+ headers.each do |k, v|
325
+ self[k] = v
326
+ end
288
327
  @body = body
289
328
  end
290
329
 
@@ -325,11 +364,15 @@ module BlueFeather
325
364
  end
326
365
 
327
366
  def encoding_type
328
- (@headers['encoding'] ? @headers['encoding'].downcase : 'utf-8')
367
+ @headers['encoding'] || EncodingType::UTF8
368
+ end
369
+
370
+ def header_id_type
371
+ (@headers['header-id-type'] || HeaderIDType::MD5).downcase
329
372
  end
330
373
 
331
374
  def kcode
332
- self.encoding_type && EncodingType.type_to_kcode(self.encoding_type)
375
+ self.encoding_type && EncodingType.convert_to_kcode(self.encoding_type)
333
376
  end
334
377
 
335
378
  def to_html
@@ -352,6 +395,7 @@ module BlueFeather
352
395
  # BlueFeather Extension
353
396
  attr_accessor :footnotes, :found_footnote_ids, :warnings
354
397
  attr_accessor :headers, :block_transform_depth
398
+ attr_accessor :header_id_type # option switch
355
399
  attr_accessor :numbering, :numbering_start_level # option switch
356
400
  alias numbering? numbering
357
401
 
@@ -361,6 +405,7 @@ module BlueFeather
361
405
  @footnotes, @found_footnote_ids, @warnings = {}, [], []
362
406
  @headers = []
363
407
  @block_transform_depth = 0
408
+ @header_id_type = HeaderIDType::MD5
364
409
  @numbering = false
365
410
  @numbering_start_level = 2
366
411
  end
@@ -446,6 +491,13 @@ module BlueFeather
446
491
  ### unused, though that may change in the future.
447
492
  def parse_text(source, rs = nil)
448
493
  rs ||= RenderState.new
494
+
495
+ # check
496
+ case rs.header_id_type
497
+ when HeaderIDType::MD5, HeaderIDType::ESCAPE
498
+ else
499
+ rs.warnings << "illegal header id type - #{rs.header_id_type}"
500
+ end
449
501
 
450
502
  # Create a StringScanner we can reuse for various lexing tasks
451
503
  @scanner = StringScanner::new( '' )
@@ -562,6 +614,7 @@ module BlueFeather
562
614
  rs.numbering = true
563
615
  end
564
616
  rs.numbering_start_level = doc.numbering_start_level
617
+ rs.header_id_type = doc.header_id_type
565
618
 
566
619
  body_html = nil
567
620
 
@@ -584,7 +637,7 @@ module BlueFeather
584
637
  # head
585
638
  out.puts %Q|<head>|
586
639
 
587
- if doc.encoding_type and (charset = EncodingType.type_to_charset(doc.encoding_type)) then
640
+ if doc.encoding_type and (charset = EncodingType.convert_to_charset(doc.encoding_type)) then
588
641
  out.puts %Q|<meta http-equiv="Content-Type" content="text/html; charset=#{charset}" />|
589
642
  end
590
643
 
@@ -1553,6 +1606,7 @@ module BlueFeather
1553
1606
  end
1554
1607
  end
1555
1608
 
1609
+ prefix = ''
1556
1610
  if rs.numbering? then
1557
1611
  if level >= rs.numbering_start_level and level <= 6 then
1558
1612
  depth = level - rs.numbering_start_level
@@ -1575,15 +1629,31 @@ module BlueFeather
1575
1629
  no << "#{section_numbers[i]}."
1576
1630
  end
1577
1631
 
1578
- title = "#{no} #{title}"
1632
+ prefix = "#{no} "
1579
1633
  end
1580
1634
  end
1581
1635
 
1582
1636
  title_html = apply_span_transforms( title, rs )
1583
- id ||= "bfheader-#{Digest::MD5.hexdigest(title)}"
1637
+
1638
+ unless id then
1639
+ case rs.header_id_type
1640
+ when HeaderIDType::ESCAPE
1641
+ id = escape_to_header_id(title_html)
1642
+ if rs.headers.find{|h| h.id == id} then
1643
+ rs.warnings << "header id collision - #{id}"
1644
+ id = "bfheader-#{Digest::MD5.hexdigest(title)}"
1645
+ end
1646
+ else
1647
+ id = "bfheader-#{Digest::MD5.hexdigest(title)}"
1648
+ end
1649
+ end
1650
+
1651
+ title = "#{prefix}#{title}"
1652
+ title_html = "#{prefix}#{title_html}"
1653
+
1584
1654
 
1585
1655
  unless id =~ IdRegexp then
1586
- rs.warnings << "illegal header id - #{id} (legal chars: a-zA-Z0-9_-. | 1st: a-zA-Z)"
1656
+ rs.warnings << "illegal header id - #{id} (legal chars: [a-zA-Z0-9_-.] | 1st: [a-zA-Z])"
1587
1657
  end
1588
1658
 
1589
1659
  if rs.block_transform_depth == 1 then
@@ -1745,6 +1815,8 @@ module BlueFeather
1745
1815
  url = @scanner[1]
1746
1816
  title = @scanner[3]
1747
1817
  @log.debug " Found an inline link to %p" % url
1818
+
1819
+ url = "##{link}" if url == '#' # target anchor briefing (since BlueFeather 0.40)
1748
1820
 
1749
1821
  text += %{<a href="%s"} % escape_md( url )
1750
1822
  if title
@@ -1940,6 +2012,9 @@ module BlueFeather
1940
2012
  gsub( CodeEscapeRegexp ) {|match| EscapeTable[match][:md5]}
1941
2013
  end
1942
2014
 
2015
+ def escape_to_header_id(str)
2016
+ URI.escape(escape_md(str.gsub(/<\/?[^>]*>/, "").gsub(/\s/, "_")).gsub("/", ".2F")).gsub("%", ".")
2017
+ end
1943
2018
 
1944
2019
  #################################################################
1945
2020
  ### U T I L I T Y F U N C T I O N S
@@ -1996,8 +2071,7 @@ module BlueFeather
1996
2071
 
1997
2072
  # Scan either an opener or a closer
1998
2073
  chunk = @scanner.scan( HTMLTagPart ) or
1999
- raise "Malformed tag at character %d: %p" %
2000
- [ tagstart, token + @scanner.rest ]
2074
+ break # BlueFeather Fix (refer to spec/code-block.rb)
2001
2075
 
2002
2076
  @log.debug " Found another part of the tag at depth %d: %p" % [ depth, chunk ]
2003
2077
 
@@ -24,8 +24,6 @@ module BlueFeather
24
24
  'bftext' => TEXT,
25
25
  }
26
26
 
27
- ENCODING_LIST = %w(shift-jis euc-jp utf-8 ascii)
28
-
29
27
  HELP = <<-EOS
30
28
  bluefeather - Extended Markdown Converter
31
29
 
@@ -33,7 +31,7 @@ Usage: bluefeather [options] file1 [file2 file3 ..]
33
31
 
34
32
  Options:
35
33
  -e, --encoding NAME parse input files as encoding of NAME.
36
- (s[hift-jis] / e[uc-jp] / u[tf-8] / a[scii]
34
+ (s[hift(_-)jis] / e[uc-jp] / u[tf-8] / a[scii]
37
35
  default: 'utf-8')
38
36
  -f, --format TYPE specify format.
39
37
  (t[ext] => text mode
@@ -81,13 +79,28 @@ More info:
81
79
  suffix = '.html'
82
80
  format = nil
83
81
  output_dir_path = nil
84
- encoding = 'utf-8'
82
+ encoding = EncodingType::UTF_8
85
83
 
86
84
 
87
85
  message_out = @stderr
88
86
 
89
87
 
90
- op.on('-e', '--encoding NAME', ENCODING_LIST){|x| encoding = x}
88
+ op.on('-e', '--encoding NAME') do |v|
89
+ case v.downcase
90
+ when /^sh?i?f?t?[-_]?j?i?s?$/
91
+ encoding = EncodingType::SHIFT_JIS
92
+ when /^eu?c?-?j?p?$/
93
+ encoding = EncodingType::EUC_JP
94
+ when /^ut?f?-?8?$/
95
+ encoding = EncodingType::UTF_8
96
+ when /^as?c?i?i?$/
97
+ encoding = EncodingType::ASCII
98
+ else
99
+ message_out.puts "ERROR: invalid encoding - #{v}"
100
+ message_out.puts "Expected: s[hift(-_)jis] / e[uc-jp] / u[tf-8] / a[scii]"
101
+ return false
102
+ end
103
+ end
91
104
  op.on('-f', '--format TYPE', FORMAT_TYPE_TABLE){|x| format = x}
92
105
  op.on('--force'){|x| force = true}
93
106
  op.on('-v', '--verbose'){ verbose = true }
@@ -115,7 +128,7 @@ More info:
115
128
  unless defined?(Encoding) then
116
129
  # ruby 1.8 or earlier
117
130
  original_kcode = $KCODE
118
- $KCODE = EncodingType.type_to_kcode(encoding)
131
+ $KCODE = EncodingType.convert_to_kcode(encoding)
119
132
  end
120
133
 
121
134
  begin
@@ -127,7 +140,7 @@ More info:
127
140
  src = @stdin.read
128
141
  if defined?(Encoding) then
129
142
  # ruby 1.9 or later
130
- src.force_encoding(encoding)
143
+ src.force_encoding(EncodingType.regulate(encoding))
131
144
  end
132
145
 
133
146
  # default: text
@@ -5,7 +5,7 @@ require(Pathname.new(__FILE__).parent + 'lib/common.rb')
5
5
  describe 'Auto Link:' do
6
6
  before(:each) do
7
7
  @html = BlueFeather.parse(@src)
8
- @doc = Hpricot(@html)
8
+ @doc = Nokogiri(@html)
9
9
  end
10
10
 
11
11
  describe 'Valid URL:' do
@@ -5,7 +5,7 @@ describe 'Normal Code Block:' do
5
5
  before(:each) do
6
6
  @bf = BlueFeather::Parser.new
7
7
  @html = @bf.parse_text(@src)
8
- @doc = Hpricot(@html)
8
+ @doc = Nokogiri(@html)
9
9
  end
10
10
 
11
11
 
@@ -25,7 +25,7 @@ describe 'Fenced Code Block:' do
25
25
  before(:each) do
26
26
  @bf = BlueFeather::Parser.new
27
27
  @html = @bf.parse_text(@src)
28
- @doc = Hpricot(@html)
28
+ @doc = Nokogiri(@html)
29
29
  end
30
30
 
31
31
 
@@ -136,11 +136,9 @@ describe 'Fenced Code Block:' do
136
136
  @doc.at('pre code').inner_text.should == "a\nb\n"
137
137
  end
138
138
  end
139
-
140
-
141
-
142
139
  end
143
140
 
141
+
144
142
 
145
143
  end
146
144
 
@@ -148,7 +146,7 @@ describe "0.30 code block bug in list item:" do
148
146
  before(:each) do
149
147
  @bf = BlueFeather::Parser.new
150
148
  @html = @bf.parse_text(@src)
151
- @doc = Hpricot(@html)
149
+ @doc = Nokogiri(@html)
152
150
  end
153
151
 
154
152
  before(:all) do
@@ -177,7 +175,7 @@ describe "0.31 code block bug in list item:" do
177
175
  before(:each) do
178
176
  @bf = BlueFeather::Parser.new
179
177
  @html = @bf.parse_text(@src)
180
- @doc = Hpricot(@html)
178
+ @doc = Nokogiri(@html)
181
179
  end
182
180
 
183
181
  describe 'simple:' do
@@ -229,4 +227,27 @@ MARKDOWN
229
227
  @doc.at('pre code').inner_text.should == "* example list in code block\n\n ~~~\n code\n ~~~\n"
230
228
  end
231
229
  end
230
+ end
231
+
232
+ describe "0.31 code block bug in list item:" do
233
+ before(:each) do
234
+ @bf = BlueFeather::Parser.new
235
+ @html = @bf.parse_text(@src)
236
+ @doc = Nokogiri(@html)
237
+ end
238
+
239
+ describe 'simple:' do
240
+ before(:all) do
241
+ @src = <<MARKDOWN
242
+ f<a < b>(a)
243
+ MARKDOWN
244
+ end
245
+
246
+ specify 'overview' do
247
+ @doc.should have_elements(1, 'pre code')
248
+ @doc.should_not have_element('pre code pre')
249
+ end
250
+
251
+ end
252
+
232
253
  end
@@ -53,17 +53,18 @@ describe 'CUI:' do
53
53
  Proc.new{@cui.run(['--encoding'])}.should raise_error(OptionParser::MissingArgument)
54
54
  end
55
55
 
56
- valids = %w(s shift-jis u utf-8)
56
+ valids = %w(s shift-jis shift_jis sjis u utf-8 UTF-8 e euc-jp a ascii)
57
+ sample_src = (Pathname.new(__FILE__).parent + 'text/encoding_sample_ascii.bfdoc').to_s
57
58
  valids.each do |name|
58
59
  specify "'#{name}' is valid" do
59
- @cui.run(['--encoding', name])
60
+ @cui.run(['--encoding', name, '-']).should be_true
60
61
  end
61
62
  end
62
63
 
63
- invalids = %w(sjis euc_jp none jis UTF-8)
64
+ invalids = %w(euc_jp none jis)
64
65
  invalids.each do |name|
65
66
  specify "'#{name}' is invalid" do
66
- Proc.new{@cui.run(['--encoding', name])}.should raise_error(OptionParser::InvalidArgument)
67
+ @cui.run(['--encoding', name, '-']).should be_false
67
68
  end
68
69
  end
69
70
 
data/spec/dl.rb CHANGED
@@ -6,7 +6,7 @@ describe 'Definition List:' do
6
6
  before(:each) do
7
7
  @bf = BlueFeather::Parser.new
8
8
  @html = @bf.parse_text(@src)
9
- @doc = Hpricot(@html)
9
+ @doc = Nokogiri(@html)
10
10
  end
11
11
 
12
12
  describe 'Basic:' do
@@ -5,10 +5,26 @@ require 'kconv'
5
5
  require(Pathname.new(__FILE__).parent + 'lib/common.rb')
6
6
 
7
7
 
8
- describe 'Encoding:' do
8
+ describe 'Internal encoding specification:' do
9
+ specify "utf-8 bom check" do
10
+ src = '日本語'.kconv(Kconv::SJIS, Kconv::UTF8)
11
+ BlueFeather::Util.utf8_bom?(src).should be_false
12
+ bom_src = "\xef\xbb\xbf日本語"
13
+ BlueFeather::Util.utf8_bom?(bom_src).should be_true
14
+ end
15
+
16
+ specify "'shift-jis' is available:" do
17
+ src = '日本語'.kconv(Kconv::SJIS, Kconv::UTF8)
18
+ BlueFeather.parse_document(src, 'shift_jis')
19
+ BlueFeather.parse_document(src, 'shift-jis')
20
+ end
21
+ end
22
+
23
+
24
+ describe 'Encoding of files:' do
9
25
  before(:each) do
10
26
  @html = BlueFeather.parse_document_file(Pathname.new(__FILE__).parent + 'text/' + @src_name)
11
- @doc = Hpricot(@html)
27
+ @doc = Nokogiri(@html)
12
28
  end
13
29
 
14
30
  share_as :Base do
@@ -76,7 +92,7 @@ describe 'Encoding:' do
76
92
  end
77
93
 
78
94
 
79
- describe 'Shift-JIS:' do
95
+ describe 'Shift_JIS:' do
80
96
  include Base
81
97
 
82
98
  before(:all) do
@@ -8,8 +8,8 @@ describe 'Footnote:' do
8
8
 
9
9
  describe 'simple:' do
10
10
  before(:all) do
11
- @html = @bf.parse_text("[^testid]\n\n[^testid]: none")
12
- @doc = Hpricot(@html)
11
+ @html = "<div>" + @bf.parse_text("[^testid]\n\n[^testid]: none") + "</div>"
12
+ @doc = Nokogiri(@html)
13
13
  end
14
14
 
15
15
  specify "reference a" do
@@ -2,11 +2,11 @@ require 'pathname'
2
2
  require(Pathname.new(__FILE__).parent + 'lib/common.rb')
3
3
 
4
4
 
5
- describe 'Header ID:' do
5
+ describe 'Specified Header ID:' do
6
6
  before(:each) do
7
7
  @bf = BlueFeather::Parser.new
8
8
  @html = @bf.parse_text(@src)
9
- @doc = Hpricot(@html)
9
+ @doc = Nokogiri(@html)
10
10
  end
11
11
 
12
12
 
@@ -32,7 +32,79 @@ describe 'Header ID:' do
32
32
  end
33
33
 
34
34
  end
35
+ end
35
36
 
37
+ describe 'Auto Generated Header ID:' do
38
+ before(:each) do
39
+ @bf = BlueFeather::Parser.new
40
+ @rs = BlueFeather::Parser::RenderState.new
41
+ @rs.header_id_type = @header_id_type if @header_id_type
42
+ @html, @rs = @bf.parse_text_with_render_state('# h1/header 1 #', @rs)
43
+ @doc = Nokogiri("<div>" + @html + "</div>")
44
+ end
36
45
 
37
46
 
47
+ describe 'default (=md5):' do
48
+ specify 'pattern matched' do
49
+ @doc.at('h1')['id'].should =~ /^bfheader-[0-9a-f]{32}$/
50
+ @rs.warnings.size.should == 0
51
+ end
52
+ end
53
+
54
+ describe 'md5:' do
55
+ before(:all) do
56
+ @header_id_type = 'md5'
57
+ end
58
+
59
+ specify 'pattern matched' do
60
+ @doc.at('h1')['id'].should =~ /^bfheader-[0-9a-f]{32}$/
61
+ @rs.warnings.size.should == 0
62
+ end
63
+ end
64
+
65
+ describe 'escape:' do
66
+ before(:all) do
67
+ @header_id_type = 'escape'
68
+ end
69
+
70
+ specify 'pattern matched' do
71
+ @doc.at('h1')['id'].should == 'h1.2Fheader_1'
72
+ @rs.warnings.size.should == 0
73
+ end
74
+ end
75
+
76
+
77
+ describe 'illegel type:' do
78
+ before(:all) do
79
+ @header_id_type = '*illegal*'
80
+ end
81
+
82
+ specify 'pattern matched' do
83
+ @doc.at('h1')['id'].should =~ /^bfheader-[0-9a-f]{32}$/
84
+ @rs.warnings.size.should == 1
85
+ end
86
+ end
87
+ end
88
+
89
+ describe "Document Header (Header-ID-Type:)" do
90
+ %w(md5 MD5).each do |value|
91
+ specify value do
92
+ doc = BlueFeather::Document.new({'Header-ID-Type' => value})
93
+ doc.header_id_type.should == BlueFeather::HeaderIDType::MD5
94
+ end
95
+ end
96
+
97
+ %w(escape Escape ESCAPE).each do |value|
98
+ specify value do
99
+ doc = BlueFeather::Document.new({'Header-ID-Type' => value}, '')
100
+ doc.header_id_type.should == BlueFeather::HeaderIDType::ESCAPE
101
+ end
102
+ end
103
+
104
+ end
105
+
106
+ describe 'Anchor Briefing Link:' do
107
+ specify 'equal' do
108
+ BlueFeather.parse_text('[FooBar](#)').should == BlueFeather.parse_text('[FooBar](#FooBar)')
109
+ end
38
110
  end
@@ -7,9 +7,9 @@ require 'pathname'
7
7
  $LOAD_PATH.unshift Pathname.new(__FILE__).dirname.parent.parent + 'lib/'
8
8
 
9
9
  require 'bluefeather'
10
- require 'hpricot'
10
+ require 'nokogiri'
11
11
 
12
- module HpricotMatcher
12
+ module NokogiriMatcher
13
13
  class HaveElement
14
14
  def initialize(selector)
15
15
  @selector = selector
@@ -63,14 +63,14 @@ end
63
63
 
64
64
  # ex) doc.should have_element('div table')
65
65
  def have_element(selector)
66
- HpricotMatcher::HaveElement.new(selector)
66
+ NokogiriMatcher::HaveElement.new(selector)
67
67
  end
68
68
 
69
69
  alias have_element_as have_element
70
70
 
71
71
  # ex) doc.should have_elements(3, 'p')
72
72
  def have_elements(number, selector)
73
- HpricotMatcher::HaveElements.new(number, selector)
73
+ NokogiriMatcher::HaveElements.new(number, selector)
74
74
  end
75
75
 
76
76
  alias have_elements_as have_elements
@@ -17,7 +17,7 @@ Numbering-Start-Level: #{@start_level}
17
17
  MARKDOWN
18
18
 
19
19
  @html = BlueFeather.parse_document(@src)
20
- @doc = Hpricot(@html)
20
+ @doc = Nokogiri(@html)
21
21
  end
22
22
 
23
23
 
@@ -7,7 +7,7 @@ describe 'Simple Table:' do
7
7
  @bf = BlueFeather::Parser.new
8
8
 
9
9
  @html = @bf.parse_text(@src)
10
- @doc = Hpricot(@html)
10
+ @doc = Nokogiri(@html)
11
11
  end
12
12
 
13
13
  share_as :StandardTable do
@@ -9,8 +9,9 @@ describe 'TOC:' do
9
9
  @html = @bf.parse_document(@doc_src)
10
10
  else
11
11
  @html, @rs = @bf.parse_text_with_render_state(@src)
12
+ @html = "<div>#{@html}</div>"
12
13
  end
13
- @doc = Hpricot(@html)
14
+ @doc = Nokogiri(@html)
14
15
  end
15
16
 
16
17
  describe 'Standard:' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bluefeather
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.33"
4
+ version: "0.40"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dice
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-22 00:00:00 +09:00
12
+ date: 2010-04-29 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15