bluefeather 0.11 → 0.20
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/Rakefile.rb +1 -1
- data/doc/author-and-license.bfdoc +1 -1
- data/doc/author-and-license.html +2 -2
- data/doc/class-reference.bfdoc +30 -4
- data/doc/class-reference.html +42 -7
- data/doc/en/author-and-license.bfdoc +2 -1
- data/doc/en/author-and-license.html +3 -2
- data/doc/en/encoding-rule.bfdoc +44 -0
- data/doc/en/encoding-rule.html +47 -0
- data/doc/en/format-extension.bfdoc +8 -0
- data/doc/en/format-extension.html +8 -0
- data/doc/en/index.bfdoc +5 -3
- data/doc/en/index.html +4 -3
- data/doc/encoding-rule.bfdoc +39 -0
- data/doc/encoding-rule.html +44 -0
- data/doc/format-extension.bfdoc +10 -1
- data/doc/format-extension.html +9 -1
- data/doc/index.bfdoc +4 -3
- data/doc/index.html +3 -2
- data/lib/bluefeather.rb +121 -34
- data/lib/bluefeather/cui.rb +7 -6
- data/spec/encoding_sample_eucjp.bfdoc +3 -0
- data/spec/encoding_sample_sjis.bfdoc +3 -0
- data/spec/encoding_sample_utf8.bfdoc +3 -0
- data/spec/toc.rb +49 -16
- metadata +9 -2
data/Rakefile.rb
CHANGED
@@ -7,7 +7,7 @@ CSS: black.css
|
|
7
7
|
連絡先・ライセンス
|
8
8
|
====
|
9
9
|
|
10
|
-
BlueFeather は、改変元である BlueCloth のライセンス(利用条件)に基づき、General Public License(GPL)バージョン 2
|
10
|
+
BlueFeather は、改変元である BlueCloth のライセンス(利用条件)に基づき、General Public License(GPL)バージョン 2 (またはそれ以降)の元で配布されるフリーソフトウェアです。
|
11
11
|
詳しくは、`bluefeather.rb` のファイル頭にある著作権表示、および同梱の `license/` ディレクトリ内にある GPL 公衆利用許諾契約書を参照してください。
|
12
12
|
|
13
13
|
* [Wikipedia - GNU General Public License](http://ja.wikipedia.org/wiki/GNU_General_Public_License)
|
data/doc/author-and-license.html
CHANGED
@@ -11,14 +11,14 @@
|
|
11
11
|
|
12
12
|
<h1 id="bfheader-22033ed9a491d8394d357096e69dee5e">連絡先・ライセンス</h1>
|
13
13
|
|
14
|
-
<p>BlueFeather は、改変元である BlueCloth のライセンス(利用条件)に基づき、General Public License(GPL)バージョン 2
|
14
|
+
<p>BlueFeather は、改変元である BlueCloth のライセンス(利用条件)に基づき、General Public License(GPL)バージョン 2 (またはそれ以降)の元で配布されるフリーソフトウェアです。
|
15
15
|
詳しくは、<code>bluefeather.rb</code> のファイル頭にある著作権表示、および同梱の <code>license/</code> ディレクトリ内にある GPL 公衆利用許諾契約書を参照してください。</p>
|
16
16
|
|
17
17
|
<ul>
|
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">mailto:tetradice@gmail.com</a>)までメールでご連絡していただけるよう、よろしくお願いします。</p>
|
22
22
|
|
23
23
|
</body>
|
24
24
|
</html>
|
data/doc/class-reference.bfdoc
CHANGED
@@ -25,15 +25,18 @@ BFMarkdown 記法で書かれた文字列をパースして、結果のHTML片
|
|
25
25
|
|
26
26
|
BlueFeather.parse_text(File.read(path))
|
27
27
|
|
28
|
-
### `BlueFeather.parse_document(str)` {#parse_document}
|
28
|
+
### `BlueFeather.parse_document(str, default_enc = EncodingType::UTF8)` {#parse_document}
|
29
29
|
|
30
30
|
BFMarkdown 記法で書かれた文字列をパースして、結果のHTML文書を返す。
|
31
31
|
|
32
|
-
|
32
|
+
default_enc は [EncodingType 定数](#EncodingType)で指定することができる。
|
33
|
+
詳細については[エンコーディングの取り扱い](encoding-rule.html)を参照。
|
34
|
+
|
35
|
+
### `BlueFeather.parse_document_file(path, default_enc = EncodingType::UTF8)` {#parse_document_file}
|
33
36
|
|
34
37
|
ファイル `path` の内容を読み取ってパースし、結果のHTML文書を返す。以下の記述と同じ。
|
35
38
|
|
36
|
-
BlueFeather.parse_document(File.read(path))
|
39
|
+
BlueFeather.parse_document(File.read(path), default_enc)
|
37
40
|
|
38
41
|
### `BlueFeather::VERSION`
|
39
42
|
### `BlueFeather::VERSION_NUMBER`
|
@@ -44,10 +47,18 @@ BlueFeather のバージョンを表す定数。VERSION は文字列、VERSION_N
|
|
44
47
|
----
|
45
48
|
文書のメタデータと Markdown テキストの組を保持するクラス。
|
46
49
|
|
47
|
-
### `Document.parse(str)`
|
50
|
+
### `Document.parse(str, default_enc = EncodingType::UTF8)` {#Document-parse}
|
48
51
|
|
49
52
|
BFMarkdown記法で書かれた文字列をパースして、Document オブジェクトを返す。この時点ではテキストの変換は行わない。
|
50
53
|
|
54
|
+
default_enc は [EncodingType 定数](#EncodingType)で指定することができる。
|
55
|
+
詳細については[エンコーディングの取り扱い](encoding-rule.html)を参照。
|
56
|
+
|
57
|
+
### `Document.parse_io(io, default_enc = EncodingType::UTF8)` {#Document-parse_io}
|
58
|
+
|
59
|
+
引数として IO オブジェクトを受け取ること以外は [`Document.parse`](#Document-parse) と同じ。
|
60
|
+
|
61
|
+
|
51
62
|
### `Document.new(headers = {}, body = '')`
|
52
63
|
|
53
64
|
メタデータ(Hash)とテキスト(String)から、Document オブジェクトを生成して返す。この時点ではテキストの変換は行わない。
|
@@ -67,6 +78,10 @@ BFMarkdown記法で書かれた文字列をパースして、Document オブジ
|
|
67
78
|
|
68
79
|
それぞれ `doc['title']`, `doc['css']` と同じ。
|
69
80
|
|
81
|
+
### `encoding_type`
|
82
|
+
|
83
|
+
その文書のエンコーディングを取得する。返り値は EncodingType モジュール内の定数か、もしくは nil。
|
84
|
+
|
70
85
|
|
71
86
|
### `to_html`
|
72
87
|
|
@@ -103,3 +118,14 @@ Parser オブジェクトを生成する。`*restrictions` には以下の Symbo
|
|
103
118
|
### `display_warnings = bool`
|
104
119
|
|
105
120
|
BlueFeather では不正なIDなどを見つけたときに、出力されるHTMLの中に警告を含める機能がある。これを有効にするかどうかのスイッチ(標準では true)。
|
121
|
+
|
122
|
+
|
123
|
+
`BlueFeather::EncodingType` モジュール {#EncodingType}
|
124
|
+
----
|
125
|
+
### `UTF8`, `UTF_8`
|
126
|
+
### `EUC`, `EUCJP`, `EUC_JP`
|
127
|
+
### `SJIS`, `SHIFT_JIS`
|
128
|
+
### `ASCII`, `US_ASCII`
|
129
|
+
|
130
|
+
BlueFeather におけるエンコーディングの種類を表す定数(String)。
|
131
|
+
|
data/doc/class-reference.html
CHANGED
@@ -20,14 +20,15 @@
|
|
20
20
|
<li><a href="#bfheader-fa1477eb445b3fdc80dd2c0525218ab7" rel="toc"><code>BlueFeather.parse_text(str)</code></a></li>
|
21
21
|
<li><a href="#parse<em>text</em>file" rel="toc"><code>BlueFeather.parse_file(path)</code></a></li>
|
22
22
|
<li><a href="#bfheader-858e9b32f250472d1729d73a2609d7b9" rel="toc"><code>BlueFeather.parse_text_file(path)</code></a></li>
|
23
|
-
<li><a href="#parse_document" rel="toc"><code>BlueFeather.parse_document(str)</code></a></li>
|
24
|
-
<li><a href="#parse<em>document</em>file" rel="toc"><code>BlueFeather.parse_document_file(
|
23
|
+
<li><a href="#parse_document" rel="toc"><code>BlueFeather.parse_document(str, default_enc = EncodingType::UTF8)</code></a></li>
|
24
|
+
<li><a href="#parse<em>document</em>file" rel="toc"><code>BlueFeather.parse_document_file(path, default_enc = EncodingType::UTF8)</code></a></li>
|
25
25
|
<li><a href="#bfheader-3857f80b19708653b12301c67de2e1db" rel="toc"><code>BlueFeather::VERSION</code></a></li>
|
26
26
|
<li><a href="#bfheader-042b8b21520ede9536ad15036ee9f27c" rel="toc"><code>BlueFeather::VERSION_NUMBER</code></a></li>
|
27
27
|
</ul></li>
|
28
28
|
<li><a href="#bfheader-8736ab72a1f0a3f39997a38e5ea6ffa5" rel="toc"><code>BlueFeather::Document</code> クラス</a>
|
29
29
|
<ul>
|
30
|
-
<li><a href="#
|
30
|
+
<li><a href="#Document-parse" rel="toc"><code>Document.parse(str, default_enc = EncodingType::UTF8)</code></a></li>
|
31
|
+
<li><a href="#Document-parse_io" rel="toc"><code>Document.parse_io(io, default_enc = EncodingType::UTF8)</code></a></li>
|
31
32
|
<li><a href="#bfheader-0ee4e10469def3879abce3265424e49a" rel="toc"><code>Document.new(headers = {}, body = '')</code></a></li>
|
32
33
|
<li><a href="#bfheader-9a4a2896cad3fd8123e63e051634fad7" rel="toc"><code>headers</code></a></li>
|
33
34
|
<li><a href="#bfheader-d80932823b30aed42cdd3426641abdc7" rel="toc"><code>body</code></a></li>
|
@@ -35,6 +36,7 @@
|
|
35
36
|
<li><a href="#bfheader-6d1c97a406278a22629ccccc9590d9d6" rel="toc"><code>self[key] = value</code></a></li>
|
36
37
|
<li><a href="#bfheader-92f24a1f999095d1e7e6125d7916d913" rel="toc"><code>title</code></a></li>
|
37
38
|
<li><a href="#bfheader-e364b84145e7b2539f6f4cc865ce3605" rel="toc"><code>css</code></a></li>
|
39
|
+
<li><a href="#bfheader-75ce338ba301a5d0566fc17b978e7ef9" rel="toc"><code>encoding_type</code></a></li>
|
38
40
|
<li><a href="#bfheader-ac3aad72cd17d2c5d24bbef5ce7a9a0c" rel="toc"><code>to_html</code></a></li>
|
39
41
|
</ul></li>
|
40
42
|
<li><a href="#bfheader-f93be37288db08fefc350b1b097b132a" rel="toc"><code>BlueFeather::Parser</code> クラス</a>
|
@@ -51,6 +53,13 @@
|
|
51
53
|
<li><a href="#bfheader-0b7fc6da6625a0e867d3a1d6f063d751" rel="toc"><code>display_warnings</code></a></li>
|
52
54
|
<li><a href="#bfheader-9d774efbf227885f2175f1405f450fa7" rel="toc"><code>display_warnings = bool</code></a></li>
|
53
55
|
</ul></li>
|
56
|
+
<li><a href="#EncodingType" rel="toc"><code>BlueFeather::EncodingType</code> モジュール</a>
|
57
|
+
<ul>
|
58
|
+
<li><a href="#bfheader-09f0d7e312745126885b6e05dbb8871d" rel="toc"><code>UTF8</code>, <code>UTF_8</code></a></li>
|
59
|
+
<li><a href="#bfheader-7bf1da914437f82fadb58dba6bb64656" rel="toc"><code>EUC</code>, <code>EUCJP</code>, <code>EUC_JP</code></a></li>
|
60
|
+
<li><a href="#bfheader-078b01e339b95e89823c0a1dc642ee16" rel="toc"><code>SJIS</code>, <code>SHIFT_JIS</code></a></li>
|
61
|
+
<li><a href="#bfheader-936a18b71e0ca92a9d907406dbb7b411" rel="toc"><code>ASCII</code>, <code>US_ASCII</code></a></li>
|
62
|
+
</ul></li>
|
54
63
|
</ul>
|
55
64
|
|
56
65
|
<h2 id="bfheader-80ceaec8f5a40f3d46aac3444c6df2e7"><code>BlueFeather</code> モジュール</h2>
|
@@ -70,15 +79,18 @@
|
|
70
79
|
<pre><code>BlueFeather.parse_text(File.read(path))
|
71
80
|
</code></pre>
|
72
81
|
|
73
|
-
<h3 id="parse_document"><code>BlueFeather.parse_document(str)</code></h3>
|
82
|
+
<h3 id="parse_document"><code>BlueFeather.parse_document(str, default_enc = EncodingType::UTF8)</code></h3>
|
74
83
|
|
75
84
|
<p>BFMarkdown 記法で書かれた文字列をパースして、結果のHTML文書を返す。</p>
|
76
85
|
|
77
|
-
<
|
86
|
+
<p>default_enc は <a href="#EncodingType">EncodingType 定数</a>で指定することができる。
|
87
|
+
詳細については<a href="encoding-rule.html">エンコーディングの取り扱い</a>を参照。</p>
|
88
|
+
|
89
|
+
<h3 id="parse_document_file"><code>BlueFeather.parse_document_file(path, default_enc = EncodingType::UTF8)</code></h3>
|
78
90
|
|
79
91
|
<p>ファイル <code>path</code> の内容を読み取ってパースし、結果のHTML文書を返す。以下の記述と同じ。</p>
|
80
92
|
|
81
|
-
<pre><code>BlueFeather.parse_document(File.read(path))
|
93
|
+
<pre><code>BlueFeather.parse_document(File.read(path), default_enc)
|
82
94
|
</code></pre>
|
83
95
|
|
84
96
|
<h3 id="bfheader-3857f80b19708653b12301c67de2e1db"><code>BlueFeather::VERSION</code></h3>
|
@@ -91,10 +103,17 @@
|
|
91
103
|
|
92
104
|
<p>文書のメタデータと Markdown テキストの組を保持するクラス。</p>
|
93
105
|
|
94
|
-
<h3 id="
|
106
|
+
<h3 id="Document-parse"><code>Document.parse(str, default_enc = EncodingType::UTF8)</code></h3>
|
95
107
|
|
96
108
|
<p>BFMarkdown記法で書かれた文字列をパースして、Document オブジェクトを返す。この時点ではテキストの変換は行わない。</p>
|
97
109
|
|
110
|
+
<p>default_enc は <a href="#EncodingType">EncodingType 定数</a>で指定することができる。
|
111
|
+
詳細については<a href="encoding-rule.html">エンコーディングの取り扱い</a>を参照。</p>
|
112
|
+
|
113
|
+
<h3 id="Document-parse_io"><code>Document.parse_io(io, default_enc = EncodingType::UTF8)</code></h3>
|
114
|
+
|
115
|
+
<p>引数として IO オブジェクトを受け取ること以外は <a href="#Document-parse"><code>Document.parse</code></a> と同じ。</p>
|
116
|
+
|
98
117
|
<h3 id="bfheader-0ee4e10469def3879abce3265424e49a"><code>Document.new(headers = {}, body = '')</code></h3>
|
99
118
|
|
100
119
|
<p>メタデータ(Hash)とテキスト(String)から、Document オブジェクトを生成して返す。この時点ではテキストの変換は行わない。</p>
|
@@ -117,6 +136,10 @@
|
|
117
136
|
|
118
137
|
<p>それぞれ <code>doc['title']</code>, <code>doc['css']</code> と同じ。</p>
|
119
138
|
|
139
|
+
<h3 id="bfheader-75ce338ba301a5d0566fc17b978e7ef9"><code>encoding_type</code></h3>
|
140
|
+
|
141
|
+
<p>その文書のエンコーディングを取得する。返り値は EncodingType モジュール内の定数か、もしくは nil。</p>
|
142
|
+
|
120
143
|
<h3 id="bfheader-ac3aad72cd17d2c5d24bbef5ce7a9a0c"><code>to_html</code></h3>
|
121
144
|
|
122
145
|
<p>その文書をHTML文書に変換する。返り値は String。</p>
|
@@ -161,5 +184,17 @@
|
|
161
184
|
|
162
185
|
<p>BlueFeather では不正なIDなどを見つけたときに、出力されるHTMLの中に警告を含める機能がある。これを有効にするかどうかのスイッチ(標準では true)。</p>
|
163
186
|
|
187
|
+
<h2 id="EncodingType"><code>BlueFeather::EncodingType</code> モジュール</h2>
|
188
|
+
|
189
|
+
<h3 id="bfheader-09f0d7e312745126885b6e05dbb8871d"><code>UTF8</code>, <code>UTF_8</code></h3>
|
190
|
+
|
191
|
+
<h3 id="bfheader-7bf1da914437f82fadb58dba6bb64656"><code>EUC</code>, <code>EUCJP</code>, <code>EUC_JP</code></h3>
|
192
|
+
|
193
|
+
<h3 id="bfheader-078b01e339b95e89823c0a1dc642ee16"><code>SJIS</code>, <code>SHIFT_JIS</code></h3>
|
194
|
+
|
195
|
+
<h3 id="bfheader-936a18b71e0ca92a9d907406dbb7b411"><code>ASCII</code>, <code>US_ASCII</code></h3>
|
196
|
+
|
197
|
+
<p>BlueFeather におけるエンコーディングの種類を表す定数(String)。</p>
|
198
|
+
|
164
199
|
</body>
|
165
200
|
</html>
|
@@ -8,7 +8,8 @@ Author and License
|
|
8
8
|
====
|
9
9
|
|
10
10
|
BlueFeather is a free software. it is distributed by General Public License
|
11
|
-
(GPL) version 2. For details, see top of `bluefeather.rb`, and
|
11
|
+
(GPL) version 2 or later. For details, see top of `bluefeather.rb`, and
|
12
|
+
`license/` directory.
|
12
13
|
|
13
14
|
* [Wikipedia - GNU General Public License](http://en.wikipedia.org/wiki/GNU_General_Public_License)
|
14
15
|
|
@@ -12,7 +12,8 @@
|
|
12
12
|
<h1 id="bfheader-e34a2a350728e95ad54ff76bbdcacac6">Author and License</h1>
|
13
13
|
|
14
14
|
<p>BlueFeather is a free software. it is distributed by General Public License
|
15
|
-
(GPL) version 2. For details, see top of <code>bluefeather.rb</code>, and
|
15
|
+
(GPL) version 2 or later. For details, see top of <code>bluefeather.rb</code>, and
|
16
|
+
<code>license/</code> directory.</p>
|
16
17
|
|
17
18
|
<ul>
|
18
19
|
<li><a href="http://en.wikipedia.org/wiki/GNU_General_Public_License">Wikipedia - GNU General Public License</a></li>
|
@@ -23,7 +24,7 @@
|
|
23
24
|
<p>If you want to send requests, comments, or bug reports to BlueFeather, please
|
24
25
|
feel free to post messages from
|
25
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.
|
26
|
-
(<a href="m&#
|
27
|
+
(<a href="mailto:tetradice@gmail.com">mailto:tetradice@gmail.com</a>)</p>
|
27
28
|
|
28
29
|
</body>
|
29
30
|
</html>
|
@@ -0,0 +1,44 @@
|
|
1
|
+
Encoding: ascii
|
2
|
+
Title: Encoding Rule - BlueFeather Manual
|
3
|
+
CSS: black.css
|
4
|
+
|
5
|
+
<div class="back"><a href="index.html">BlueFeather Manual</a></div>
|
6
|
+
|
7
|
+
Encoding Rule
|
8
|
+
====
|
9
|
+
|
10
|
+
|
11
|
+
{toc}
|
12
|
+
|
13
|
+
|
14
|
+
1. Converting to html part
|
15
|
+
----
|
16
|
+
(converting *.bftext files, parsing by `parse_text` or others.)
|
17
|
+
|
18
|
+
BlueFeather doesn't specially treat.
|
19
|
+
If ruby 1.8.x ealier, it is based on $KCODE value then.
|
20
|
+
Else if ruby 1.9.x later, it is based on encoding which String object has.
|
21
|
+
|
22
|
+
When you use `bluefeather` command, it is based on -e (--encoding) option. Default is UTF-8.
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
2. Converting to html document
|
27
|
+
----
|
28
|
+
(converting *.bfdoc files, parsing by `parse_document` or others.)
|
29
|
+
|
30
|
+
BlueFeather uses the following order.
|
31
|
+
|
32
|
+
1. Encoding header of document metadata (PRIMARY)
|
33
|
+
2. Specified encoding at convert
|
34
|
+
3. UTF-8
|
35
|
+
|
36
|
+
|
37
|
+
If you want to know about encoding header, see the [Metadata reference](metadata-reference.html).
|
38
|
+
|
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
|
+
If you use `bluefeather` command, you must use -e (--encoding) option for it.
|
42
|
+
|
43
|
+
|
44
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Encoding Rule - BlueFeather Manual</title>
|
5
|
+
<link rel="stylesheet" type="text/css" href="black.css" />
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
|
9
|
+
<div class="back"><a href="index.html">BlueFeather Manual</a></div>
|
10
|
+
|
11
|
+
<h1 id="bfheader-06a0303193523282130e680a0d2f058f">Encoding Rule</h1>
|
12
|
+
|
13
|
+
<ul>
|
14
|
+
<li><a href="#bfheader-84fb6cab35fe13eef58167e5cbcf8fe9" rel="toc">1. Converting to html part</a></li>
|
15
|
+
<li><a href="#bfheader-db7b980112a4cd59806c96e2ad4cbe9e" rel="toc">2. Converting to html document</a></li>
|
16
|
+
</ul>
|
17
|
+
|
18
|
+
<h2 id="bfheader-84fb6cab35fe13eef58167e5cbcf8fe9">1. Converting to html part</h2>
|
19
|
+
|
20
|
+
<p>(converting *.bftext files, parsing by <code>parse_text</code> or others.)</p>
|
21
|
+
|
22
|
+
<p>BlueFeather doesn't specially treat.
|
23
|
+
If ruby 1.8.x ealier, it is based on $KCODE value then.
|
24
|
+
Else if ruby 1.9.x later, it is based on encoding which String object has.</p>
|
25
|
+
|
26
|
+
<p>When you use <code>bluefeather</code> command, it is based on -e (--encoding) option. Default is UTF-8.</p>
|
27
|
+
|
28
|
+
<h2 id="bfheader-db7b980112a4cd59806c96e2ad4cbe9e">2. Converting to html document</h2>
|
29
|
+
|
30
|
+
<p>(converting *.bfdoc files, parsing by <code>parse_document</code> or others.)</p>
|
31
|
+
|
32
|
+
<p>BlueFeather uses the following order.</p>
|
33
|
+
|
34
|
+
<ol>
|
35
|
+
<li>Encoding header of document metadata (PRIMARY)</li>
|
36
|
+
<li>Specified encoding at convert</li>
|
37
|
+
<li>UTF-8</li>
|
38
|
+
</ol>
|
39
|
+
|
40
|
+
<p>If you want to know about encoding header, see the <a href="metadata-reference.html">Metadata reference</a>.</p>
|
41
|
+
|
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>
|
45
|
+
|
46
|
+
</body>
|
47
|
+
</html>
|
@@ -222,6 +222,14 @@ BlueFeather Original
|
|
222
222
|
|
223
223
|
Default is h2 - h6.
|
224
224
|
|
225
|
+
Following formats are usable to specify levels.
|
226
|
+
|
227
|
+
{toc:h3-} (same as previous example)
|
228
|
+
{toc:h3} (h3 only)
|
229
|
+
{toc:h3..h4} (from h3 to h4)
|
230
|
+
{toc:..h4} (from h2 to h4)
|
231
|
+
|
232
|
+
|
225
233
|
Be careful, Headers *written by Markdown on the document root*, are only
|
226
234
|
included in TOC. So following headers are NOT included in TOC.
|
227
235
|
|
@@ -316,6 +316,14 @@ Markdown)</p></li>
|
|
316
316
|
|
317
317
|
<p>Default is h2 - h6.</p>
|
318
318
|
|
319
|
+
<p>Following formats are usable to specify levels.</p>
|
320
|
+
|
321
|
+
<pre><code>{toc:h3-} (same as previous example)
|
322
|
+
{toc:h3} (h3 only)
|
323
|
+
{toc:h3..h4} (from h3 to h4)
|
324
|
+
{toc:..h4} (from h2 to h4)
|
325
|
+
</code></pre>
|
326
|
+
|
319
327
|
<p>Be careful, Headers <em>written by Markdown on the document root</em>, are only
|
320
328
|
included in TOC. So following headers are NOT included in TOC.</p>
|
321
329
|
|
data/doc/en/index.bfdoc
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
Encoding: ASCII
|
2
|
+
Title: BlueFeather Manual
|
2
3
|
CSS: black.css
|
3
4
|
|
4
|
-
<div class="back"><a>
|
5
|
+
<div class="back"><a> </a></div>
|
5
6
|
|
6
7
|
|
7
8
|
BlueFeather Manual
|
@@ -9,7 +10,7 @@ BlueFeather Manual
|
|
9
10
|
|
10
11
|
-> [Japanese version (original)](../index.html)
|
11
12
|
|
12
|
-
(2009-
|
13
|
+
(2009-05-04: this document based on version 0.20)
|
13
14
|
|
14
15
|
BlueFeather is software for converting text written by extended Markdown like
|
15
16
|
[PHP Markdown Extra][] to html. It is pair of command-line tool and pure Ruby
|
@@ -25,6 +26,7 @@ files are in the directory, '`doc/en/`'.
|
|
25
26
|
* [Installing and Basic Usage](basic-usage.html)
|
26
27
|
* [Difference from BlueCloth](difference.html)
|
27
28
|
* [Markdown Syntax Extension](format-extension.html)
|
29
|
+
* [Encoding Rule](encoding-rule.html)
|
28
30
|
|
29
31
|
~
|
30
32
|
|
@@ -34,7 +36,7 @@ files are in the directory, '`doc/en/`'.
|
|
34
36
|
~
|
35
37
|
|
36
38
|
* [Author and License](author-and-license.html)
|
37
|
-
* [BlueFeather Website
|
39
|
+
* [BlueFeather Website (http://ruby.morphball.net/bluefeather/index_en.html)](http://ruby.morphball.net/bluefeather/index_en.html)
|
38
40
|
|
39
41
|
|
40
42
|
[BlueCloth 1.0.0]: http://www.deveiate.org/projects/BlueCloth
|
data/doc/en/index.html
CHANGED
@@ -6,13 +6,13 @@
|
|
6
6
|
</head>
|
7
7
|
<body>
|
8
8
|
|
9
|
-
<div class="back"><a>
|
9
|
+
<div class="back"><a> </a></div>
|
10
10
|
|
11
11
|
<h1 id="bfheader-35661d482100191843f35ae0ff825d35">BlueFeather Manual</h1>
|
12
12
|
|
13
13
|
<p>-> <a href="../index.html">Japanese version (original)</a></p>
|
14
14
|
|
15
|
-
<p>(2009-
|
15
|
+
<p>(2009-05-04: this document based on version 0.20)</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
|
@@ -28,6 +28,7 @@ files are in the directory, '<code>doc/en/</code>'.</p>
|
|
28
28
|
<li><a href="basic-usage.html">Installing and Basic Usage</a></li>
|
29
29
|
<li><a href="difference.html">Difference from BlueCloth</a></li>
|
30
30
|
<li><a href="format-extension.html">Markdown Syntax Extension</a></li>
|
31
|
+
<li><a href="encoding-rule.html">Encoding Rule</a></li>
|
31
32
|
</ul>
|
32
33
|
|
33
34
|
|
@@ -41,7 +42,7 @@ files are in the directory, '<code>doc/en/</code>'.</p>
|
|
41
42
|
|
42
43
|
<ul>
|
43
44
|
<li><a href="author-and-license.html">Author and License</a></li>
|
44
|
-
<li><a href="http://ruby.morphball.net/bluefeather/index_en.html">BlueFeather Website
|
45
|
+
<li><a href="http://ruby.morphball.net/bluefeather/index_en.html">BlueFeather Website (http://ruby.morphball.net/bluefeather/index_en.html)</a></li>
|
45
46
|
</ul>
|
46
47
|
|
47
48
|
</body>
|
@@ -0,0 +1,39 @@
|
|
1
|
+
Title: エンコーディングの取り扱い - BlueFeather マニュアル
|
2
|
+
CSS: black.css
|
3
|
+
|
4
|
+
<div class="back"><a href="index.html">BlueFeather マニュアル</a></div>
|
5
|
+
|
6
|
+
エンコーディングの取り扱い
|
7
|
+
====
|
8
|
+
|
9
|
+
|
10
|
+
{toc}
|
11
|
+
|
12
|
+
|
13
|
+
1. HTML片へ変換するとき
|
14
|
+
----
|
15
|
+
(拡張子 *.bftext のファイル変換、parse_text による変換など)
|
16
|
+
|
17
|
+
特殊な処理を行いません。ruby 1.8.x 以前であればそのときの $KCODE が、ruby 1.9.x 以降であれば文字列の持つエンコーディングが反映されます。
|
18
|
+
|
19
|
+
`bluefeather` コマンドでは、-e (--encoding) オプションの指定に従います。指定がなければ UTF-8 です。
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
2. 完全なHTML文書へ変換するとき
|
24
|
+
----
|
25
|
+
(拡張子 *.bfdoc のファイル変換、parse_document による変換など)
|
26
|
+
|
27
|
+
以下の優先順序に従います。
|
28
|
+
|
29
|
+
1. 文書メタデータの Encoding ヘッダ(最優先)
|
30
|
+
2. 変換時に指定したエンコーディング
|
31
|
+
3. UTF-8
|
32
|
+
|
33
|
+
|
34
|
+
「文書メタデータの Encoding ヘッダ」については、[メタデータリファレンス](metadata-reference.html)内の[説明](metadata-reference.html#encoding)を参照してください。
|
35
|
+
|
36
|
+
変換時のエンコーディング指定は、[`parse_document`](class-reference.html#parse_document) メソッドや [`parse_document_file`](class-reference.html#parse_document) メソッドによる変換時にはメソッドの第二引数(default_enc)で、`bluefeather` コマンドであれば -e (--encoding) オプションで、それぞれ指定することが可能です。
|
37
|
+
|
38
|
+
|
39
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>エンコーディングの取り扱い - BlueFeather マニュアル</title>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
6
|
+
<link rel="stylesheet" type="text/css" href="black.css" />
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
|
10
|
+
<div class="back"><a href="index.html">BlueFeather マニュアル</a></div>
|
11
|
+
|
12
|
+
<h1 id="bfheader-2958c11cbc27bd969295196367b69edd">エンコーディングの取り扱い</h1>
|
13
|
+
|
14
|
+
<ul>
|
15
|
+
<li><a href="#bfheader-27481ff9fea6dc4e00937ed0decddca1" rel="toc">1. HTML片へ変換するとき</a></li>
|
16
|
+
<li><a href="#bfheader-17800f328e4f623b4f7a4d5a811bfae9" rel="toc">2. 完全なHTML文書へ変換するとき</a></li>
|
17
|
+
</ul>
|
18
|
+
|
19
|
+
<h2 id="bfheader-27481ff9fea6dc4e00937ed0decddca1">1. HTML片へ変換するとき</h2>
|
20
|
+
|
21
|
+
<p>(拡張子 *.bftext のファイル変換、parse_text による変換など)</p>
|
22
|
+
|
23
|
+
<p>特殊な処理を行いません。ruby 1.8.x 以前であればそのときの $KCODE が、ruby 1.9.x 以降であれば文字列の持つエンコーディングが反映されます。</p>
|
24
|
+
|
25
|
+
<p><code>bluefeather</code> コマンドでは、-e (--encoding) オプションの指定に従います。指定がなければ UTF-8 です。</p>
|
26
|
+
|
27
|
+
<h2 id="bfheader-17800f328e4f623b4f7a4d5a811bfae9">2. 完全なHTML文書へ変換するとき</h2>
|
28
|
+
|
29
|
+
<p>(拡張子 *.bfdoc のファイル変換、parse_document による変換など)</p>
|
30
|
+
|
31
|
+
<p>以下の優先順序に従います。</p>
|
32
|
+
|
33
|
+
<ol>
|
34
|
+
<li>文書メタデータの Encoding ヘッダ(最優先)</li>
|
35
|
+
<li>変換時に指定したエンコーディング</li>
|
36
|
+
<li>UTF-8</li>
|
37
|
+
</ol>
|
38
|
+
|
39
|
+
<p>「文書メタデータの Encoding ヘッダ」については、<a href="metadata-reference.html">メタデータリファレンス</a>内の<a href="metadata-reference.html#encoding">説明</a>を参照してください。</p>
|
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>
|
42
|
+
|
43
|
+
</body>
|
44
|
+
</html>
|
data/doc/format-extension.bfdoc
CHANGED
@@ -223,7 +223,16 @@ PHP Markdown Extra
|
|
223
223
|
|
224
224
|
>{toc:h3..}
|
225
225
|
|
226
|
-
|
226
|
+
指定がなかった場合には、標準で h2 ~ h6 が目次に含まれます。
|
227
|
+
|
228
|
+
見出しレベルの指定には、以下のような書き方を使うことができます。
|
229
|
+
|
230
|
+
{toc:h3-} (上記の例と同じ)
|
231
|
+
{toc:h3} (h3 のみ)
|
232
|
+
{toc:h3..h4} (h3 ~ h4)
|
233
|
+
{toc:..h4} (h2 ~ h4)
|
234
|
+
|
235
|
+
|
227
236
|
|
228
237
|
なお、目次にリストアップされるのは、_Markdown記法の変換によって生成され、なおかつ他のブロック要素に含まれていない見出しのみ_です。
|
229
238
|
つまり、次のような見出しは目次に含まれません。
|
data/doc/format-extension.html
CHANGED
@@ -315,7 +315,15 @@
|
|
315
315
|
</ul>
|
316
316
|
</blockquote>
|
317
317
|
|
318
|
-
<p
|
318
|
+
<p>指定がなかった場合には、標準で h2 ~ h6 が目次に含まれます。</p>
|
319
|
+
|
320
|
+
<p>見出しレベルの指定には、以下のような書き方を使うことができます。</p>
|
321
|
+
|
322
|
+
<pre><code>{toc:h3-} (上記の例と同じ)
|
323
|
+
{toc:h3} (h3 のみ)
|
324
|
+
{toc:h3..h4} (h3 ~ h4)
|
325
|
+
{toc:..h4} (h2 ~ h4)
|
326
|
+
</code></pre>
|
319
327
|
|
320
328
|
<p>なお、目次にリストアップされるのは、<em>Markdown記法の変換によって生成され、なおかつ他のブロック要素に含まれていない見出しのみ</em>です。
|
321
329
|
つまり、次のような見出しは目次に含まれません。</p>
|
data/doc/index.bfdoc
CHANGED
@@ -9,12 +9,12 @@ BlueFeather マニュアル
|
|
9
9
|
→ [English version](en/index.html)
|
10
10
|
|
11
11
|
|
12
|
-
(2009-
|
12
|
+
(2009-05-04 バージョン 0.20 準拠)
|
13
13
|
|
14
14
|
BlueFeather は、拡張 Markdown 記法で書かれたテキストを html に変換するソフトウェアです。
|
15
15
|
コマンドラインツールと、Ruby スクリプト内で変換を行うためのライブラリがセットになっています。
|
16
16
|
|
17
|
-
広く使われている Markdown 実装である [BlueCloth][] をベースとしつつ、既知のバグの修正やインターフェースの変更、そして記法・機能へのさまざまな拡張を施しています。
|
17
|
+
広く使われている Markdown 実装である [BlueCloth 1.0.0][] をベースとしつつ、既知のバグの修正やインターフェースの変更、そして記法・機能へのさまざまな拡張を施しています。
|
18
18
|
|
19
19
|
なお、このマニュアルページそのものも、 BlueFeather を用いて生成された html 文書です。変換前のテキストファイルは `doc` ディレクトリ内に同梱しています。
|
20
20
|
|
@@ -22,6 +22,7 @@ BlueFeather は、拡張 Markdown 記法で書かれたテキストを html に
|
|
22
22
|
* [インストール・基本的な使い方](basic-usage.html)
|
23
23
|
* [BlueCloth との違い](difference.html)
|
24
24
|
* [Markdown 記法の拡張](format-extension.html)
|
25
|
+
* [エンコーディングの取り扱い](encoding-rule.html)
|
25
26
|
|
26
27
|
~
|
27
28
|
|
@@ -33,4 +34,4 @@ BlueFeather は、拡張 Markdown 記法で書かれたテキストを html に
|
|
33
34
|
* [連絡先・ライセンス](author-and-license.html)
|
34
35
|
* [BlueFeather 配布サイト(http://ruby.morphball.net/bluefeather/)](http://ruby.morphball.net/bluefeather/)
|
35
36
|
|
36
|
-
[BlueCloth]: http://www.deveiate.org/projects/BlueCloth
|
37
|
+
[BlueCloth 1.0.0]: http://www.deveiate.org/projects/BlueCloth
|
data/doc/index.html
CHANGED
@@ -13,12 +13,12 @@
|
|
13
13
|
|
14
14
|
<p>→ <a href="en/index.html">English version</a></p>
|
15
15
|
|
16
|
-
<p>(2009-
|
16
|
+
<p>(2009-05-04 バージョン 0.20 準拠)</p>
|
17
17
|
|
18
18
|
<p>BlueFeather は、拡張 Markdown 記法で書かれたテキストを html に変換するソフトウェアです。
|
19
19
|
コマンドラインツールと、Ruby スクリプト内で変換を行うためのライブラリがセットになっています。</p>
|
20
20
|
|
21
|
-
<p>広く使われている Markdown 実装である <a href="http://www.deveiate.org/projects/BlueCloth">BlueCloth</a> をベースとしつつ、既知のバグの修正やインターフェースの変更、そして記法・機能へのさまざまな拡張を施しています。</p>
|
21
|
+
<p>広く使われている Markdown 実装である <a href="http://www.deveiate.org/projects/BlueCloth">BlueCloth 1.0.0</a> をベースとしつつ、既知のバグの修正やインターフェースの変更、そして記法・機能へのさまざまな拡張を施しています。</p>
|
22
22
|
|
23
23
|
<p>なお、このマニュアルページそのものも、 BlueFeather を用いて生成された html 文書です。変換前のテキストファイルは <code>doc</code> ディレクトリ内に同梱しています。</p>
|
24
24
|
|
@@ -26,6 +26,7 @@
|
|
26
26
|
<li><a href="basic-usage.html">インストール・基本的な使い方</a></li>
|
27
27
|
<li><a href="difference.html">BlueCloth との違い</a></li>
|
28
28
|
<li><a href="format-extension.html">Markdown 記法の拡張</a></li>
|
29
|
+
<li><a href="encoding-rule.html">エンコーディングの取り扱い</a></li>
|
29
30
|
</ul>
|
30
31
|
|
31
32
|
|
data/lib/bluefeather.rb
CHANGED
@@ -42,8 +42,8 @@ require 'uri'
|
|
42
42
|
|
43
43
|
|
44
44
|
module BlueFeather
|
45
|
-
VERSION = '0.
|
46
|
-
VERSION_NUMBER = 0.
|
45
|
+
VERSION = '0.20'
|
46
|
+
VERSION_NUMBER = 0.20
|
47
47
|
|
48
48
|
|
49
49
|
# Fancy methods
|
@@ -54,8 +54,8 @@ module BlueFeather
|
|
54
54
|
|
55
55
|
alias parse parse_text
|
56
56
|
|
57
|
-
def parse_document(src)
|
58
|
-
Parser.new.parse_document(src)
|
57
|
+
def parse_document(src, default_enc = EncodingType::UTF8)
|
58
|
+
Parser.new.parse_document(src, default_enc)
|
59
59
|
end
|
60
60
|
|
61
61
|
|
@@ -65,8 +65,8 @@ module BlueFeather
|
|
65
65
|
|
66
66
|
alias parse_file parse_text_file
|
67
67
|
|
68
|
-
def parse_document_file(path)
|
69
|
-
Parser.new.parse_document_file(path)
|
68
|
+
def parse_document_file(path, default_enc = EncodingType::UTF8)
|
69
|
+
Parser.new.parse_document_file(path, default_enc)
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -95,9 +95,16 @@ module BlueFeather
|
|
95
95
|
|
96
96
|
module EncodingType
|
97
97
|
EUC = 'euc-jp'
|
98
|
+
EUCJP = EUC_JP = EUC
|
99
|
+
|
98
100
|
SJIS = 'shift-jis'
|
101
|
+
SHIFT_JIS = SJIS
|
102
|
+
|
99
103
|
UTF8 = 'utf-8'
|
104
|
+
UTF_8 = UTF8
|
105
|
+
|
100
106
|
ASCII = 'ascii'
|
107
|
+
US_ASCII = ASCII
|
101
108
|
|
102
109
|
def self.type_to_kcode(type)
|
103
110
|
case type
|
@@ -125,6 +132,7 @@ module BlueFeather
|
|
125
132
|
raise EncodingError, "not adapted encoding type - #{type} (shift-jis, euc-jp, utf-8, or ascii)"
|
126
133
|
end
|
127
134
|
end
|
135
|
+
|
128
136
|
end
|
129
137
|
|
130
138
|
module Util
|
@@ -184,36 +192,84 @@ module BlueFeather
|
|
184
192
|
alias text= body=
|
185
193
|
|
186
194
|
class << self
|
187
|
-
def
|
188
|
-
s = StringScanner.new(source)
|
195
|
+
def parse_io(input, default_enc = EncodingType::UTF8)
|
189
196
|
headers = {}
|
197
|
+
body = nil
|
198
|
+
first_pos = input.pos
|
190
199
|
|
191
|
-
Util.change_kcode(
|
200
|
+
Util.change_kcode(EncodingType.type_to_kcode(default_enc)){
|
201
|
+
# default encoding
|
202
|
+
if defined?(Encoding) then
|
203
|
+
input.set_encoding(Encoding.find(default_enc))
|
204
|
+
end
|
205
|
+
|
206
|
+
|
207
|
+
|
192
208
|
# get headers
|
193
|
-
|
194
|
-
|
195
|
-
|
209
|
+
pos_before_gets = nil
|
210
|
+
|
211
|
+
loop do
|
212
|
+
pos_before_gets = input.pos
|
196
213
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
214
|
+
line = input.gets
|
215
|
+
if line and line.chomp =~ HEADER_PATTERN then
|
216
|
+
key = $1.downcase; value = $2
|
217
|
+
|
218
|
+
if key == 'encoding' and not headers.include?('encoding') then
|
219
|
+
kc = EncodingType.type_to_kcode(value.downcase)
|
220
|
+
if input.respond_to?(:set_encoding) then
|
221
|
+
input.set_encoding(value.downcase)
|
222
|
+
|
223
|
+
# rewind (reason => [ruby-list:45988])
|
224
|
+
input.pos = first_pos
|
225
|
+
else
|
226
|
+
$KCODE = kc
|
227
|
+
end
|
202
228
|
end
|
229
|
+
|
230
|
+
headers[key] = value
|
231
|
+
else
|
232
|
+
# EOF or Metadata end
|
233
|
+
break
|
203
234
|
end
|
204
235
|
end
|
205
236
|
|
237
|
+
# back
|
238
|
+
input.pos = pos_before_gets
|
239
|
+
|
240
|
+
|
241
|
+
|
206
242
|
# skip blank lines
|
207
|
-
|
243
|
+
loop do
|
244
|
+
pos_before_gets = input.pos
|
245
|
+
|
246
|
+
line = input.gets
|
247
|
+
if line.nil? or not line =~ BLANK_LINE_PATTERN then
|
248
|
+
break
|
249
|
+
end
|
208
250
|
end
|
251
|
+
|
252
|
+
# back
|
253
|
+
input.pos = pos_before_gets
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
# get body
|
258
|
+
body = input.read
|
259
|
+
|
209
260
|
}
|
210
261
|
|
211
|
-
|
262
|
+
|
212
263
|
return self.new(headers, body)
|
213
264
|
end
|
214
265
|
|
266
|
+
def parse(str, default_enc = EncodingType::UTF8)
|
267
|
+
parse_io(StringIO.new(str), default_enc)
|
268
|
+
end
|
269
|
+
|
215
270
|
end
|
216
271
|
|
272
|
+
|
217
273
|
def initialize(headers = {}, body = '')
|
218
274
|
@headers = headers
|
219
275
|
@body = body
|
@@ -437,12 +493,19 @@ module BlueFeather
|
|
437
493
|
alias parse_file parse_text_file
|
438
494
|
|
439
495
|
|
440
|
-
def parse_document(source)
|
441
|
-
|
496
|
+
def parse_document(source, default_enc = EncodingType::UTF8)
|
497
|
+
doc = Document.parse_io(source, default_enc)
|
498
|
+
|
499
|
+
return document_to_html(doc)
|
442
500
|
end
|
443
501
|
|
444
|
-
def parse_document_file(path)
|
445
|
-
|
502
|
+
def parse_document_file(path, default_enc = EncodingType::UTF8)
|
503
|
+
doc = nil
|
504
|
+
open(path){|f|
|
505
|
+
doc = Document.parse_io(f, default_enc)
|
506
|
+
}
|
507
|
+
|
508
|
+
return document_to_html(doc)
|
446
509
|
end
|
447
510
|
|
448
511
|
|
@@ -453,11 +516,6 @@ module BlueFeather
|
|
453
516
|
|
454
517
|
if doc.encoding_type then
|
455
518
|
Util.change_kcode(doc.kcode){
|
456
|
-
# for scene when doc.encoding changed after Document.parse
|
457
|
-
if doc.body.respond_to?(:force_encoding) then
|
458
|
-
doc.body.force_encoding(doc.encoding_type)
|
459
|
-
end
|
460
|
-
|
461
519
|
body_html = parse_text(doc.body, rs)
|
462
520
|
}
|
463
521
|
else
|
@@ -855,7 +913,22 @@ module BlueFeather
|
|
855
913
|
[ ]*$ # optional space on line-foot
|
856
914
|
}ix
|
857
915
|
|
858
|
-
TOCStartLevelRegexp =
|
916
|
+
TOCStartLevelRegexp = %r{
|
917
|
+
^
|
918
|
+
(?: # optional start
|
919
|
+
h
|
920
|
+
([1-6]) # $1 = start level
|
921
|
+
)?
|
922
|
+
|
923
|
+
(?: # range symbol
|
924
|
+
[.]{2,}|[-] # .. or -
|
925
|
+
)
|
926
|
+
|
927
|
+
(?: # optional end
|
928
|
+
h? # optional 'h'
|
929
|
+
([1-6]) # $2 = end level
|
930
|
+
)?$
|
931
|
+
}ix
|
859
932
|
|
860
933
|
### Transform any Markdown-style horizontal rules in a copy of the specified
|
861
934
|
### +str+ and return it.
|
@@ -863,19 +936,25 @@ module BlueFeather
|
|
863
936
|
@log.debug " Transforming tables of contents"
|
864
937
|
str.gsub(TOCRegexp){
|
865
938
|
start_level = 2 # default
|
939
|
+
end_level = 6
|
866
940
|
|
867
941
|
param = $1
|
868
942
|
if param then
|
869
943
|
if param =~ TOCStartLevelRegexp then
|
870
|
-
|
944
|
+
if !($1) and !($2) then
|
945
|
+
rs.warnings << "illegal TOC parameter - #{param} (valid example: 'h2..h4')"
|
946
|
+
else
|
947
|
+
start_level = ($1 ? $1.to_i : 2)
|
948
|
+
end_level = ($2 ? $2.to_i : 6)
|
949
|
+
end
|
871
950
|
else
|
872
|
-
rs.warnings << "illegal TOC parameter - #{param} (valid example: 'h2..')"
|
951
|
+
rs.warnings << "illegal TOC parameter - #{param} (valid example: 'h2..h4')"
|
873
952
|
end
|
874
953
|
end
|
875
954
|
|
876
955
|
ul_text = "\n\n"
|
877
956
|
rs.headers.each do |header|
|
878
|
-
if header.level >= start_level then
|
957
|
+
if header.level >= start_level and header.level <= end_level then
|
879
958
|
ul_text << ' ' * TabWidth * (header.level - start_level)
|
880
959
|
ul_text << '* '
|
881
960
|
ul_text << %Q|<a href="##{header.id}" rel="toc">#{header.content_html}</a>|
|
@@ -1212,9 +1291,17 @@ module BlueFeather
|
|
1212
1291
|
codeblock = $1
|
1213
1292
|
remainder = $2
|
1214
1293
|
|
1294
|
+
|
1295
|
+
tmpl = %{\n\n<pre><code>%s\n</code></pre>\n\n%s}
|
1296
|
+
|
1297
|
+
# patch for ruby 1.9.1 bug
|
1298
|
+
if tmpl.respond_to?(:force_encoding) then
|
1299
|
+
tmpl.force_encoding(str.encoding)
|
1300
|
+
end
|
1301
|
+
args = [ encode_code( outdent(codeblock), rs ).rstrip, remainder ]
|
1215
1302
|
# Generate the codeblock
|
1216
|
-
|
1217
|
-
|
1303
|
+
|
1304
|
+
tmpl % args
|
1218
1305
|
}
|
1219
1306
|
end
|
1220
1307
|
|
data/lib/bluefeather/cui.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
#
|
1
2
|
# BlueFeather Command-line Interface
|
3
|
+
#
|
2
4
|
require 'optparse'
|
3
5
|
require 'benchmark'
|
4
6
|
require 'stringio'
|
@@ -108,6 +110,7 @@ More info:
|
|
108
110
|
return false
|
109
111
|
end
|
110
112
|
|
113
|
+
message_out.puts "default encoding: #{encoding}"
|
111
114
|
|
112
115
|
unless defined?(Encoding) then
|
113
116
|
# ruby 1.8 or earlier
|
@@ -129,7 +132,7 @@ More info:
|
|
129
132
|
|
130
133
|
# default: text
|
131
134
|
if format == DOCUMENT then
|
132
|
-
@stdout.write(BlueFeather.parse_document(src))
|
135
|
+
@stdout.write(BlueFeather.parse_document(src, encoding))
|
133
136
|
else
|
134
137
|
@stdout.write(BlueFeather.parse_text(src))
|
135
138
|
end
|
@@ -173,17 +176,15 @@ More info:
|
|
173
176
|
end
|
174
177
|
end
|
175
178
|
|
176
|
-
open_mode = (defined?(Encoding) ? "r:#{encoding}" : 'r')
|
177
|
-
|
178
179
|
# parse
|
179
180
|
parsing_sec = Benchmark.realtime{
|
180
181
|
case current_format
|
181
182
|
when DOCUMENT
|
182
183
|
message_out.puts "[document] #{src}" if verbose
|
183
|
-
|
184
|
-
html = BlueFeather.parse_document(text)
|
184
|
+
html = BlueFeather.parse_document_file(src, encoding)
|
185
185
|
when TEXT
|
186
186
|
message_out.puts "[text] #{src}" if verbose
|
187
|
+
open_mode = (defined?(Encoding) ? "r:#{encoding}" : 'r')
|
187
188
|
text = src.open(open_mode){|x| x.read}
|
188
189
|
html = BlueFeather.parse_text(text)
|
189
190
|
end
|
@@ -196,7 +197,7 @@ More info:
|
|
196
197
|
message_out.puts "#{src} => #{dest} (#{File.size(dest)} byte)"
|
197
198
|
|
198
199
|
if verbose then
|
199
|
-
message_out.puts sprintf('(parsing time: %g sec)', parsing_sec)
|
200
|
+
message_out.puts sprintf(' (parsing time: %g sec)', parsing_sec)
|
200
201
|
end
|
201
202
|
end # if html
|
202
203
|
end # if ext == suffix
|
data/spec/toc.rb
CHANGED
@@ -3,18 +3,8 @@ require(Pathname.new(__FILE__).parent + 'lib/common.rb')
|
|
3
3
|
|
4
4
|
|
5
5
|
describe 'TOC:' do
|
6
|
-
before(:
|
7
|
-
@
|
8
|
-
@html = @bf.parse_text(@src)
|
9
|
-
@doc = Hpricot(@html)
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
|
-
describe 'basic:' do
|
14
|
-
before(:all) do
|
15
|
-
@src = <<-MARKDOWN
|
16
|
-
{toc}
|
17
|
-
|
6
|
+
before(:all) do
|
7
|
+
@header_part = <<MARKDOWN
|
18
8
|
# h1 #
|
19
9
|
## h2a ##
|
20
10
|
## h2b ##
|
@@ -22,15 +12,32 @@ describe 'TOC:' do
|
|
22
12
|
### h3b ###
|
23
13
|
### h3c ###
|
24
14
|
## h2c ##
|
25
|
-
|
26
|
-
|
27
|
-
|
15
|
+
MARKDOWN
|
16
|
+
end
|
17
|
+
|
18
|
+
before(:each) do
|
19
|
+
@bf = BlueFeather::Parser.new
|
20
|
+
@html = @bf.parse_text(@src)
|
21
|
+
@doc = Hpricot(@html)
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
share_as :ContentOverview do
|
28
26
|
specify 'overview' do
|
29
27
|
@doc.should have_element('ul')
|
30
28
|
@doc.should have_elements(1, 'h1')
|
31
29
|
@doc.should have_elements(3, 'h2')
|
32
30
|
@doc.should have_elements(3, 'h3')
|
33
31
|
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
describe 'basic:' do
|
36
|
+
include ContentOverview
|
37
|
+
before(:all) do
|
38
|
+
@src = "{toc}\n\n" + @header_part
|
39
|
+
end
|
40
|
+
|
34
41
|
|
35
42
|
specify 'list structure' do
|
36
43
|
toc = @doc.at('ul')
|
@@ -57,7 +64,33 @@ describe 'TOC:' do
|
|
57
64
|
|
58
65
|
end
|
59
66
|
|
60
|
-
|
67
|
+
describe 'range:' do
|
68
|
+
include ContentOverview
|
69
|
+
before(:all) do
|
70
|
+
@src = "{toc:h1..h2}\n\n" + @header_part
|
71
|
+
end
|
72
|
+
|
73
|
+
specify 'list structure' do
|
74
|
+
toc = @doc.at('ul')
|
75
|
+
toc['class'] = 'toc'
|
76
|
+
|
77
|
+
@doc.should have_elements(1, 'ul.toc > li')
|
78
|
+
@doc.should have_elements(1, 'ul.toc > li > ul')
|
79
|
+
@doc.should have_elements(3, 'ul.toc > li > ul > li')
|
80
|
+
end
|
81
|
+
|
82
|
+
specify 'list content' do
|
83
|
+
toc = @doc.at('ul')
|
84
|
+
toc['class'] = 'toc'
|
85
|
+
|
86
|
+
items2 = @doc.search('ul.toc > li > ul > li')
|
87
|
+
items2[0].inner_text.should == 'h2a'
|
88
|
+
items2[1].inner_text.should == 'h2b'
|
89
|
+
items2[2].inner_text.should == 'h2c'
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
61
94
|
|
62
95
|
|
63
96
|
|
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.20"
|
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-
|
12
|
+
date: 2009-05-04 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -34,6 +34,9 @@ files:
|
|
34
34
|
- spec/code-block.rb
|
35
35
|
- spec/cui.rb
|
36
36
|
- spec/dl.rb
|
37
|
+
- spec/encoding_sample_eucjp.bfdoc
|
38
|
+
- spec/encoding_sample_sjis.bfdoc
|
39
|
+
- spec/encoding_sample_utf8.bfdoc
|
37
40
|
- spec/escape-char.rb
|
38
41
|
- spec/footnote.rb
|
39
42
|
- spec/header-id.rb
|
@@ -72,12 +75,16 @@ files:
|
|
72
75
|
- doc/en/class-reference.html
|
73
76
|
- doc/en/difference.bfdoc
|
74
77
|
- doc/en/difference.html
|
78
|
+
- doc/en/encoding-rule.bfdoc
|
79
|
+
- doc/en/encoding-rule.html
|
75
80
|
- doc/en/format-extension.bfdoc
|
76
81
|
- doc/en/format-extension.html
|
77
82
|
- doc/en/index.bfdoc
|
78
83
|
- doc/en/index.html
|
79
84
|
- doc/en/metadata-reference.bfdoc
|
80
85
|
- doc/en/metadata-reference.html
|
86
|
+
- doc/encoding-rule.bfdoc
|
87
|
+
- doc/encoding-rule.html
|
81
88
|
- doc/format-extension.bfdoc
|
82
89
|
- doc/format-extension.html
|
83
90
|
- doc/index.bfdoc
|