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.
- data/doc/author-and-license.html +1 -1
- data/doc/basic-usage.bfdoc +1 -1
- data/doc/basic-usage.html +1 -1
- data/doc/en/author-and-license.html +1 -1
- data/doc/en/encoding-rule.bfdoc +1 -1
- data/doc/en/encoding-rule.html +2 -2
- data/doc/en/index.bfdoc +1 -1
- data/doc/en/index.html +1 -1
- data/doc/encoding-rule.bfdoc +5 -2
- data/doc/encoding-rule.html +7 -2
- data/doc/index.bfdoc +1 -1
- data/doc/index.html +1 -1
- data/doc/metadata-reference.bfdoc +1 -1
- data/doc/metadata-reference.html +1 -1
- data/lib/bluefeather.rb +98 -24
- data/lib/bluefeather/cui.rb +20 -7
- data/spec/auto-link.rb +1 -1
- data/spec/code-block.rb +28 -7
- data/spec/cui.rb +5 -4
- data/spec/dl.rb +1 -1
- data/spec/encoding.rb +19 -3
- data/spec/footnote.rb +2 -2
- data/spec/header-id.rb +74 -2
- data/spec/lib/common.rb +4 -4
- data/spec/numbering.rb +1 -1
- data/spec/table.rb +1 -1
- data/spec/toc.rb +2 -1
- metadata +2 -2
data/doc/author-and-license.html
CHANGED
|
@@ -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="&#
|
|
21
|
+
<p>BlueFeather への要望、ご意見、バグ報告などがありましたら、<a href="http://ruby.morphball.net/bluefeather/">BlueFeather 配布サイト</a>よりメッセージを送信していただくか、もしくは Dice(<a href="mailto:tetradice@gmail.com">tetradice@gmail.com</a>)までメールでご連絡していただけるよう、よろしくお願いします。</p>
|
|
22
22
|
|
|
23
23
|
</body>
|
|
24
24
|
</html>
|
data/doc/basic-usage.bfdoc
CHANGED
|
@@ -176,7 +176,7 @@ test3.html
|
|
|
176
176
|
`-e NAME`, `--encoding NAME`
|
|
177
177
|
:
|
|
178
178
|
変換するテキストファイルのエンコーディングを、指定したエンコーディングとして解釈します。
|
|
179
|
-
(`shift-jis` / `euc-jp` / `utf-8` / `
|
|
179
|
+
(`shift-jis` / `euc-jp` / `utf-8` / `ascii` のうちいずれか、もしくは最初の数文字。標準では `utf-8`)
|
|
180
180
|
|
|
181
181
|
`-f TYPE`, `--format TYPE`
|
|
182
182
|
:
|
data/doc/basic-usage.html
CHANGED
|
@@ -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>
|
|
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="&#
|
|
27
|
+
(<a href="mailto:tetradice@gmail.com">tetradice@gmail.com</a>)</p>
|
|
28
28
|
|
|
29
29
|
</body>
|
|
30
30
|
</html>
|
data/doc/en/encoding-rule.bfdoc
CHANGED
|
@@ -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
|
|
data/doc/en/encoding-rule.html
CHANGED
|
@@ -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
|
|
44
|
-
If you use <code>
|
|
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>
|
data/doc/en/index.bfdoc
CHANGED
|
@@ -10,7 +10,7 @@ BlueFeather Manual
|
|
|
10
10
|
|
|
11
11
|
-> [Japanese version (original)](../index.html)
|
|
12
12
|
|
|
13
|
-
(
|
|
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
|
data/doc/en/index.html
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
<p>-> <a href="../index.html">Japanese version (original)</a></p>
|
|
14
14
|
|
|
15
|
-
<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
|
data/doc/encoding-rule.bfdoc
CHANGED
|
@@ -31,9 +31,12 @@ CSS: black.css
|
|
|
31
31
|
3. UTF-8
|
|
32
32
|
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
「1. 文書メタデータの Encoding ヘッダ」についての詳細は、[メタデータリファレンス](metadata-reference.html)内の[説明](metadata-reference.html#encoding)を参照してください。
|
|
35
35
|
|
|
36
|
-
|
|
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
|
|
data/doc/encoding-rule.html
CHANGED
|
@@ -36,9 +36,14 @@
|
|
|
36
36
|
<li>UTF-8</li>
|
|
37
37
|
</ol>
|
|
38
38
|
|
|
39
|
-
<p
|
|
39
|
+
<p>「1. 文書メタデータの Encoding ヘッダ」についての詳細は、<a href="metadata-reference.html">メタデータリファレンス</a>内の<a href="metadata-reference.html#encoding">説明</a>を参照してください。</p>
|
|
40
40
|
|
|
41
|
-
<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>
|
data/doc/index.bfdoc
CHANGED
data/doc/index.html
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
<p>→ <a href="en/index.html">English version</a></p>
|
|
15
15
|
|
|
16
|
-
<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 はそれらのヘッダーよりも先に記述されていなければならない。*
|
data/doc/metadata-reference.html
CHANGED
|
@@ -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>
|
data/lib/bluefeather.rb
CHANGED
|
@@ -42,9 +42,9 @@ require 'uri'
|
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
module BlueFeather
|
|
45
|
-
VERSION = '0.
|
|
46
|
-
VERSION_NUMBER = 0.
|
|
47
|
-
RELEASE_DATE = '
|
|
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 = '
|
|
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.
|
|
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.
|
|
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
|
|
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.
|
|
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
|
|
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.
|
|
267
|
+
kc = EncodingType.convert_to_kcode(value.downcase)
|
|
232
268
|
if input.respond_to?(:set_encoding) then
|
|
233
|
-
input.set_encoding(value
|
|
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 =
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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
|
-
|
|
1632
|
+
prefix = "#{no} "
|
|
1579
1633
|
end
|
|
1580
1634
|
end
|
|
1581
1635
|
|
|
1582
1636
|
title_html = apply_span_transforms( title, rs )
|
|
1583
|
-
|
|
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
|
-
|
|
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
|
|
data/lib/bluefeather/cui.rb
CHANGED
|
@@ -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 =
|
|
82
|
+
encoding = EncodingType::UTF_8
|
|
85
83
|
|
|
86
84
|
|
|
87
85
|
message_out = @stderr
|
|
88
86
|
|
|
89
87
|
|
|
90
|
-
op.on('-e', '--encoding NAME'
|
|
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.
|
|
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
|
data/spec/auto-link.rb
CHANGED
data/spec/code-block.rb
CHANGED
|
@@ -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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
data/spec/cui.rb
CHANGED
|
@@ -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(
|
|
64
|
+
invalids = %w(euc_jp none jis)
|
|
64
65
|
invalids.each do |name|
|
|
65
66
|
specify "'#{name}' is invalid" do
|
|
66
|
-
|
|
67
|
+
@cui.run(['--encoding', name, '-']).should be_false
|
|
67
68
|
end
|
|
68
69
|
end
|
|
69
70
|
|
data/spec/dl.rb
CHANGED
data/spec/encoding.rb
CHANGED
|
@@ -5,10 +5,26 @@ require 'kconv'
|
|
|
5
5
|
require(Pathname.new(__FILE__).parent + 'lib/common.rb')
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
describe '
|
|
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 =
|
|
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 '
|
|
95
|
+
describe 'Shift_JIS:' do
|
|
80
96
|
include Base
|
|
81
97
|
|
|
82
98
|
before(:all) do
|
data/spec/footnote.rb
CHANGED
|
@@ -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 =
|
|
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
|
data/spec/header-id.rb
CHANGED
|
@@ -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 =
|
|
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
|
data/spec/lib/common.rb
CHANGED
|
@@ -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 '
|
|
10
|
+
require 'nokogiri'
|
|
11
11
|
|
|
12
|
-
module
|
|
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
|
-
|
|
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
|
-
|
|
73
|
+
NokogiriMatcher::HaveElements.new(number, selector)
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
alias have_elements_as have_elements
|
data/spec/numbering.rb
CHANGED
data/spec/table.rb
CHANGED
data/spec/toc.rb
CHANGED
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.
|
|
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:
|
|
12
|
+
date: 2010-04-29 00:00:00 +09:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|