pseudohikiparser 0.0.0.14.develop → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.ja.md +435 -0
- data/README.md +187 -79
- data/lib/pseudohiki/blockparser.rb +27 -64
- data/lib/pseudohiki/htmlformat.rb +0 -24
- data/lib/pseudohiki/markdownformat.rb +3 -9
- data/lib/pseudohiki/version.rb +1 -1
- data/lib/pseudohikiparser.rb +0 -2
- data/test/test_blockparser.rb +0 -29
- data/test/test_htmlformat.rb +0 -63
- data/test/test_markdownformat.rb +7 -60
- metadata +5 -5
- data/lib/pseudohiki/sinatra_helpers.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7908f80b410e064b7380cee7982c351257e578cd
|
4
|
+
data.tar.gz: 193bb4b76c97e2936a87f1f6da83cbc42ee788db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02659c1d1e708819e9b1ed50cf65a89c348ff2c92a840daee52bb8e32d70dd0c6b4af2ab8a090ecce06557811274a9f763fec897da174193603421de3e736ff8
|
7
|
+
data.tar.gz: 24e068590d29996d995de41bac263451a4eb994d1241a61d27626934914ad59de3286466b0c135ac7cf634ac220c984800574efa59124d712a7beb4f9bbf717d
|
data/README.ja.md
ADDED
@@ -0,0 +1,435 @@
|
|
1
|
+
PseudoHikiParser
|
2
|
+
================
|
3
|
+
|
4
|
+
PseudoHikiParserは[Hiki](http://hikiwiki.org/en/)に似た記法で書かれたテキストをHTMLその他のファイル形式に変換するコンバータです。
|
5
|
+
|
6
|
+
このツールは次の目的を念頭において作成中です。
|
7
|
+
|
8
|
+
* オリジナルのHiki記法にはない特徴を付け加える
|
9
|
+
* より行指向を徹底する
|
10
|
+
* 見出しのような要素にid属性を付けられるようにする
|
11
|
+
* HTML以外のファイル形式をサポートする
|
12
|
+
* 実装にあたってVisitorパターンを採用したため、新たなファイル形式を追加するのに必要なのは(願わくは)Visitorクラスを用意することだけです。
|
13
|
+
|
14
|
+
なお、オリジナルのHiki記法との互換性はなくなります。
|
15
|
+
|
16
|
+
## ライセンス
|
17
|
+
|
18
|
+
2条項BSDライセンスです。
|
19
|
+
|
20
|
+
## インストール
|
21
|
+
|
22
|
+
```
|
23
|
+
gem install pseudohikiparser
|
24
|
+
```
|
25
|
+
|
26
|
+
もし実験的な機能も試してみたければ、
|
27
|
+
|
28
|
+
```
|
29
|
+
gem install pseudohikiparser --pre
|
30
|
+
```
|
31
|
+
|
32
|
+
## 使い方
|
33
|
+
|
34
|
+
### サンプル
|
35
|
+
|
36
|
+
* Hiki記法で書かれた[テキストのサンプル](https://github.com/nico-hn/PseudoHikiParser/blob/develop/samples/wikipage.txt)
|
37
|
+
|
38
|
+
その変換結果:
|
39
|
+
|
40
|
+
* [HTML 4.01](http://htmlpreview.github.com/?https://github.com/nico-hn/PseudoHikiParser/blob/develop/samples/wikipage.html)
|
41
|
+
* [XHTML 1.0](http://htmlpreview.github.com/?https://github.com/nico-hn/PseudoHikiParser/blob/develop/samples/wikipage_with_toc.html)
|
42
|
+
* [HTML5](http://htmlpreview.github.com/?https://github.com/nico-hn/PseudoHikiParser/blob/develop/samples/wikipage_html5_with_toc.html)
|
43
|
+
* [GFM](https://github.com/nico-hn/PseudoHikiParser/blob/develop/samples/wikipage.md)
|
44
|
+
|
45
|
+
このサンプルは[develop branch](https://github.com/nico-hn/PseudoHikiParser/tree/develop/samples)に置いてあります。
|
46
|
+
|
47
|
+
### pseudohiki2html.rb
|
48
|
+
|
49
|
+
_(pseudohiki2html.rbは現時点ではPseudoHikiParserの利用例として提供されており、現段階ではオプションも継続的に変更されることにご注意ください。)_
|
50
|
+
|
51
|
+
インストールが終わると**pseudohiki2html.rb**というコマンドが使えるようになります。
|
52
|
+
|
53
|
+
コマンドラインで次のように入力すると
|
54
|
+
|
55
|
+
```
|
56
|
+
pseudohiki2html.rb <<TEXT
|
57
|
+
!! The first heading
|
58
|
+
The first paragraph
|
59
|
+
TEXT
|
60
|
+
```
|
61
|
+
|
62
|
+
下のような結果が返ってくるはずです。
|
63
|
+
|
64
|
+
```html
|
65
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
66
|
+
"http://www.w3.org/TR/html4/loose.dtd">
|
67
|
+
<html lang="en">
|
68
|
+
<head>
|
69
|
+
<meta content="en" http-equiv="Content-Language">
|
70
|
+
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
|
71
|
+
<meta content="text/javascript" http-equiv="Content-Script-Type">
|
72
|
+
<title>-</title>
|
73
|
+
<link href="default.css" rel="stylesheet" type="text/css">
|
74
|
+
</head>
|
75
|
+
<body>
|
76
|
+
<div class="section h2">
|
77
|
+
<h2> The first heading
|
78
|
+
</h2>
|
79
|
+
<p>
|
80
|
+
The first paragraph
|
81
|
+
</p>
|
82
|
+
<!-- end of section h2 -->
|
83
|
+
</div>
|
84
|
+
</body>
|
85
|
+
</html>
|
86
|
+
```
|
87
|
+
|
88
|
+
`--output`オプションを使ってファイル名を指定した場合は
|
89
|
+
|
90
|
+
```
|
91
|
+
pseudohiki2html.rb --output first_example.html <<TEXT
|
92
|
+
!! The first heading
|
93
|
+
The first paragraph
|
94
|
+
TEXT
|
95
|
+
```
|
96
|
+
|
97
|
+
で、結果がfirst\_example.htmlに保存されます。
|
98
|
+
|
99
|
+
その他のオプションについては`pseudohiki2html.rb --help`でご参照ください。
|
100
|
+
|
101
|
+
#### 非互換な変更
|
102
|
+
|
103
|
+
version 0.0.0.9.developから、コマンドラインのオプション名を以下の通り変更しています。
|
104
|
+
|
105
|
+
|元の名前 |新しい名前 |注記 |
|
106
|
+
|---------------|-----------------|-----------------------------------------------------------|
|
107
|
+
|-f |-F |'-f' is now used as the short version of '--format-version'|
|
108
|
+
|-h |-f |'-h' is now used as the short version of '--help' |
|
109
|
+
|--html\_version|--format-version |other formats than html should be supported |
|
110
|
+
|--encoding |--format-encoding|'--encoding' is now used as the long version of '-E' option|
|
111
|
+
|- |--encoding |now same as '-E' option of MRI |
|
112
|
+
|
113
|
+
### PseudoHiki::BlockParserクラス
|
114
|
+
|
115
|
+
PseudoHiki::BlockParserのクラスメソッド parseは入力から構文木を生成し、Visitorクラスでその木を別の形式に変換します。
|
116
|
+
|
117
|
+
以下の内容をファイルに保存・実行すると
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
#!/usr/bin/env ruby
|
121
|
+
|
122
|
+
require 'pseudohikiparser'
|
123
|
+
|
124
|
+
hiki_text = <<TEXT
|
125
|
+
!! The first heading
|
126
|
+
The first paragraph
|
127
|
+
TEXT
|
128
|
+
|
129
|
+
tree = PseudoHiki::BlockParser.parse(hiki_text)
|
130
|
+
html = PseudoHiki::HtmlFormat.format(tree)
|
131
|
+
puts html
|
132
|
+
```
|
133
|
+
|
134
|
+
次のように出力されます。
|
135
|
+
|
136
|
+
```html
|
137
|
+
<div class="section h2">
|
138
|
+
<h2> The first heading
|
139
|
+
</h2>
|
140
|
+
<p>
|
141
|
+
The first paragraph
|
142
|
+
</p>
|
143
|
+
<!-- end of section h2 -->
|
144
|
+
</div>
|
145
|
+
```
|
146
|
+
|
147
|
+
この例では、HtmlFormatがVisitorクラスで、構文木をHTML4.01形式に変換しています。
|
148
|
+
|
149
|
+
HtmlFormat以外にはXhtmlFormat、Xhtml5Format、PlainTextFormat、MarkDownFormatが用意されています。
|
150
|
+
|
151
|
+
### PseudoHiki::Formatクラス
|
152
|
+
|
153
|
+
PseudoHiki::BlockParser.parseで作られた構文木を使い回す必要がなければ、以下のPseudoHiki::Formatのクラスメソッドも利用可能です。
|
154
|
+
|
155
|
+
|メソッド名 |変換結果 |
|
156
|
+
|------------|------------------------|
|
157
|
+
|to\_html |HTML 4.01 |
|
158
|
+
|to\_xhtml |XHTML 1.0 |
|
159
|
+
|to\_html5 |HTML 5 |
|
160
|
+
|to\_plain |修飾なしのテキスト |
|
161
|
+
|to\_markdown|Markdown |
|
162
|
+
|to\_gfm |Github Flavored Markdown|
|
163
|
+
|
164
|
+
例えば次のスクリプトは[PseudoHiki::BlockParserクラス](#pseudohikiblockparserクラス)の例と同じ結果を返します。
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
#!/usr/bin/env ruby
|
168
|
+
|
169
|
+
require 'pseudohikiparser'
|
170
|
+
|
171
|
+
hiki_text = <<TEXT
|
172
|
+
!! The first heading
|
173
|
+
The first paragraph
|
174
|
+
TEXT
|
175
|
+
|
176
|
+
puts PseudoHiki::Format.to_html(hiki_text)
|
177
|
+
```
|
178
|
+
|
179
|
+
## オリジナルの[Hiki記法](http://rabbit-shocker.org/en/hiki.html)にある機能の実装状況
|
180
|
+
|
181
|
+
* パラグラフ - 使いものになる
|
182
|
+
* リンク
|
183
|
+
* WikiNames - 未サポート(実装予定なし)
|
184
|
+
* ページへのリンク - これも未サポート
|
185
|
+
* 任意のURLへのリンク - 一応使えるはず
|
186
|
+
* 整形済みテキスト - 使いものになる
|
187
|
+
* 文字の修飾 - 一部をサポート
|
188
|
+
* インライン修飾用タグのエスケープ手段は実験的なもの
|
189
|
+
* バッククォートタグ(``)による等幅表示の記法は\<tt\>要素ではなく\<code\>要素に変換される
|
190
|
+
* 見出し - 使いものになる
|
191
|
+
* 水平線 - 使いものになる
|
192
|
+
* 箇条書き - 使いものになる
|
193
|
+
* 引用 - 使いものになる
|
194
|
+
* 用語解説 - 使いものになる
|
195
|
+
* 表 - 使いものになる
|
196
|
+
* コメント行 - 使いものになる
|
197
|
+
* プラグイン - 未サポート (オリジナルのHikiとは非互換になる予定)
|
198
|
+
|
199
|
+
## オリジナルのHiki記法にはない特徴
|
200
|
+
|
201
|
+
### id属性の付与
|
202
|
+
|
203
|
+
下の例のように、見出しもしくはリストを示す記号の直後に[name\_of\_id]を付けると、その値が変換後のHTML要素のid属性になります。
|
204
|
+
|
205
|
+
```
|
206
|
+
!![heading_id]heading
|
207
|
+
|
208
|
+
*[list_id]list
|
209
|
+
```
|
210
|
+
|
211
|
+
は次のように変換されます。
|
212
|
+
|
213
|
+
```html
|
214
|
+
<div class="section h2">
|
215
|
+
<h2 id="HEADING_ID">heading
|
216
|
+
</h2>
|
217
|
+
<ul>
|
218
|
+
<li id="LIST_ID">list
|
219
|
+
</li>
|
220
|
+
</ul>
|
221
|
+
<!-- end of section h2 -->
|
222
|
+
</div>
|
223
|
+
```
|
224
|
+
|
225
|
+
### インライン修飾用タグのエスケープ
|
226
|
+
|
227
|
+
_(これは実験的な機能ですのでご注意ください。)_
|
228
|
+
|
229
|
+
インライン修飾用のタグはプラグイン用のタグに入れることでエスケープできます。
|
230
|
+
|
231
|
+
```
|
232
|
+
For example, {{''}} and {{==}} can be escaped.
|
233
|
+
And {{ {}} and {{} }} should be rendered as two left curly braces and two right curly braces respectively.
|
234
|
+
```
|
235
|
+
|
236
|
+
は次のように変換されます。
|
237
|
+
|
238
|
+
```
|
239
|
+
For example, '' or == can be escaped.
|
240
|
+
And {{ and }} sould be rendered as two left curly braces and two right curly braces respectively.
|
241
|
+
```
|
242
|
+
|
243
|
+
### リンク用タグの入れ子
|
244
|
+
|
245
|
+
リンク用タグが他のリンク用タグの中に入れ子になっている場合、外側のタグは画像へのurlを指定していても常にリンクとして扱われます。
|
246
|
+
|
247
|
+
そのため下の例のように、サムネイル画像からリンクを張ることも可能です。
|
248
|
+
|
249
|
+
```
|
250
|
+
[[[[thumbnail of an image|http://www.example.org/image_thumb.png]]|http://www.example.org/image.png]]
|
251
|
+
```
|
252
|
+
|
253
|
+
は次のように変換されます。
|
254
|
+
|
255
|
+
```html
|
256
|
+
<a href="http://www.example.org/image.png"><img alt="thumbnail of an image" src="http://www.example.org/image_thumb.png">
|
257
|
+
</a></p>
|
258
|
+
```
|
259
|
+
|
260
|
+
### 実験的な機能
|
261
|
+
|
262
|
+
以下の機能は実験的なもので、[developブランチ](https://github.com/nico-hn/PseudoHikiParser/tree/develop)でのみ利用可能です。
|
263
|
+
|
264
|
+
#### ブロック用のデコレータ
|
265
|
+
|
266
|
+
'//@'で始まる行を使って、その後に続くブロックに属性を付与することができます。
|
267
|
+
|
268
|
+
例えば
|
269
|
+
|
270
|
+
```
|
271
|
+
//@class[class_name]
|
272
|
+
!!A section with a class name
|
273
|
+
|
274
|
+
paragraph
|
275
|
+
```
|
276
|
+
|
277
|
+
は次のように変換されます。
|
278
|
+
|
279
|
+
```html
|
280
|
+
<div class="class_name">
|
281
|
+
<h2>A section with a class name
|
282
|
+
</h2>
|
283
|
+
<p>
|
284
|
+
paragraph
|
285
|
+
</p>
|
286
|
+
<!-- end of class_name -->
|
287
|
+
</div>
|
288
|
+
```
|
289
|
+
|
290
|
+
### 未実装の機能
|
291
|
+
|
292
|
+
## Visitorクラス
|
293
|
+
|
294
|
+
以下のクラスのうちの一部は、部分的にしか実装されていないかテストが十分ではないことにご注意ください。
|
295
|
+
|
296
|
+
### [HtmlFormat](https://github.com/nico-hn/PseudoHikiParser/blob/develop/lib/pseudohiki/htmlformat.rb#L8), [XhtmlFormat](https://github.com/nico-hn/PseudoHikiParser/blob/develop/lib/pseudohiki/htmlformat.rb#L263)
|
297
|
+
|
298
|
+
これらのクラスのクラスメソッド(HtmlFormat|XhtmlFormat).formatは[HtmlElement](https://github.com/nico-hn/PseudoHikiParser/blob/develop/lib/htmlelement.rb)オブジェクトを木にしたものを返すため、以下の例のように後から手を加えることができます。
|
299
|
+
|
300
|
+
```ruby
|
301
|
+
#!/usr/bin/env ruby
|
302
|
+
|
303
|
+
require 'pseudohikiparser'
|
304
|
+
|
305
|
+
hiki_text = <<HIKI
|
306
|
+
!! heading
|
307
|
+
|
308
|
+
paragraph 1 that contains [[a link to a html file|http://www.example.org/example.html]]
|
309
|
+
|
310
|
+
paragraph 2 that contains [[a link to a pdf file|http://www.example.org/example.pdf]]
|
311
|
+
HIKI
|
312
|
+
|
313
|
+
html = HtmlFormat.format(hiki_text)
|
314
|
+
|
315
|
+
html.traverse do |elm|
|
316
|
+
if elm.kind_of? HtmlElement and elm.tagname == "a"
|
317
|
+
elm["class"] = "pdf" if /\.pdf\Z/o =~ elm["href"]
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
puts html.to_s
|
322
|
+
```
|
323
|
+
|
324
|
+
は次のように出力します。
|
325
|
+
|
326
|
+
```html
|
327
|
+
<div class="section h2">
|
328
|
+
<h2> heading
|
329
|
+
</h2>
|
330
|
+
<p>
|
331
|
+
paragraph 1 that contains <a href="http://www.example.org/example.html">a link to a html file</a>
|
332
|
+
</p>
|
333
|
+
<p>
|
334
|
+
paragraph 2 that contains <a class="pdf" href="http://www.example.org/example.pdf">a link to a pdf file</a>
|
335
|
+
</p>
|
336
|
+
<!-- end of section h2 -->
|
337
|
+
</div>
|
338
|
+
```
|
339
|
+
|
340
|
+
### [Xhtml5Format](https://github.com/nico-hn/PseudoHikiParser/blob/develop/lib/pseudohiki/htmlformat.rb#L268)
|
341
|
+
|
342
|
+
HTML5への変換用のVisitorクラスです。
|
343
|
+
|
344
|
+
現時点では\<section\>要素の扱い以外に[XhtmlFormat](https://github.com/nico-hn/PseudoHikiParser/blob/develop/lib/pseudohiki/htmlformat.rb#L263)との違いは余りありません。
|
345
|
+
|
346
|
+
### [PlainTextFormat](https://github.com/nico-hn/PseudoHikiParser/blob/develop/lib/pseudohiki/plaintextformat.rb)
|
347
|
+
|
348
|
+
Hiki記法のマークアップを除去するためのVisitorクラスで、使用例は以下の通りです。
|
349
|
+
|
350
|
+
```
|
351
|
+
:tel:03-xxxx-xxxx
|
352
|
+
::03-yyyy-yyyy
|
353
|
+
:fax:03-xxxx-xxxx
|
354
|
+
```
|
355
|
+
|
356
|
+
will be rendered as
|
357
|
+
|
358
|
+
```
|
359
|
+
tel: 03-xxxx-xxxx
|
360
|
+
03-yyyy-yyyy
|
361
|
+
fax: 03-xxxx-xxxx
|
362
|
+
```
|
363
|
+
|
364
|
+
また
|
365
|
+
|
366
|
+
```
|
367
|
+
||cell 1-1||>>cell 1-2,3,4||cell 1-5
|
368
|
+
||cell 2-1||^>cell 2-2,3 3-2,3||cell 2-4||cell 2-5
|
369
|
+
||cell 3-1||cell 3-4||cell 3-5
|
370
|
+
||cell 4-1||cell 4-2||cell 4-3||cell 4-4||cell 4-5
|
371
|
+
```
|
372
|
+
|
373
|
+
は次のように変換されます。
|
374
|
+
|
375
|
+
```
|
376
|
+
cell 1-1 cell 1-2,3,4 == == cell 1-5
|
377
|
+
cell 2-1 cell 2-2,3 3-2,3 == cell 2-4 cell 2-5
|
378
|
+
cell 3-1 || || cell 3-4 cell 3-5
|
379
|
+
cell 4-1 cell 4-2 cell 4-3 cell 4-4 cell 4-5
|
380
|
+
```
|
381
|
+
|
382
|
+
### [MarkDownFormat](https://github.com/nico-hn/PseudoHikiParser/blob/develop/lib/pseudohiki/markdownformat.rb)
|
383
|
+
|
384
|
+
(Git Flavored) Markdownへの変換用のVisitorクラスですが、まだ実験段階です。
|
385
|
+
|
386
|
+
以下がサンプルのスクリプトとその出力結果です。
|
387
|
+
|
388
|
+
```ruby
|
389
|
+
#!/usr/bin/env ruby
|
390
|
+
|
391
|
+
require 'pseudohiki/markdownformat'
|
392
|
+
|
393
|
+
md = PseudoHiki::MarkDownFormat.create
|
394
|
+
gfm = PseudoHiki::MarkDownFormat.create(gfm_style: true)
|
395
|
+
|
396
|
+
hiki = <<TEXT
|
397
|
+
!! The first heading
|
398
|
+
|
399
|
+
The first paragraph
|
400
|
+
|
401
|
+
||!header 1||!header 2
|
402
|
+
||''cell 1''||cell2
|
403
|
+
|
404
|
+
TEXT
|
405
|
+
|
406
|
+
tree = PseudoHiki::BlockParser.parse(hiki)
|
407
|
+
md_text = md.format(tree).to_s
|
408
|
+
gfm_text = gfm.format(tree).to_s
|
409
|
+
puts md_text
|
410
|
+
puts "--------------------"
|
411
|
+
puts gfm_text
|
412
|
+
```
|
413
|
+
|
414
|
+
(出力結果)
|
415
|
+
|
416
|
+
```
|
417
|
+
## The first heading
|
418
|
+
|
419
|
+
The first paragraph
|
420
|
+
|
421
|
+
<table>
|
422
|
+
<tr><th>header 1</th><th>header 2</th></tr>
|
423
|
+
<tr><td><em>cell 1</em></td><td>cell2</td></tr>
|
424
|
+
</table>
|
425
|
+
|
426
|
+
--------------------
|
427
|
+
## The first heading
|
428
|
+
|
429
|
+
The first paragraph
|
430
|
+
|
431
|
+
|header 1|header 2|
|
432
|
+
|--------|--------|
|
433
|
+
|_cell 1_|cell2 |
|
434
|
+
```
|
435
|
+
|
data/README.md
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
PseudoHikiParser
|
2
2
|
================
|
3
3
|
|
4
|
-
PseudoHikiParser is a converter of texts written in a [Hiki](http://hikiwiki.org/en/) like notation, into
|
5
|
-
|
6
|
-
Currently, only a limited range of notations can be converted into HTML4 or XHTML1.0.
|
4
|
+
PseudoHikiParser is a converter of texts written in a [Hiki](http://hikiwiki.org/en/) like notation, into HTML or other formats.
|
7
5
|
|
8
6
|
I am writing this tool with following objectives in mind,
|
9
7
|
|
@@ -21,6 +19,12 @@ BSD 2-Clause License
|
|
21
19
|
|
22
20
|
## Installation
|
23
21
|
|
22
|
+
```
|
23
|
+
gem install pseudohikiparser
|
24
|
+
```
|
25
|
+
|
26
|
+
or if you also want to try out experimental features,
|
27
|
+
|
24
28
|
```
|
25
29
|
gem install pseudohikiparser --pre
|
26
30
|
```
|
@@ -29,17 +33,24 @@ gem install pseudohikiparser --pre
|
|
29
33
|
|
30
34
|
### Samples
|
31
35
|
|
32
|
-
[A sample text](https://github.com/nico-hn/PseudoHikiParser/blob/develop/samples/wikipage.txt) in Hiki notation
|
36
|
+
* [A sample text](https://github.com/nico-hn/PseudoHikiParser/blob/develop/samples/wikipage.txt) in Hiki notation
|
37
|
+
|
38
|
+
And results of conversion
|
33
39
|
|
34
|
-
|
40
|
+
* [HTML 4.01](http://htmlpreview.github.com/?https://github.com/nico-hn/PseudoHikiParser/blob/develop/samples/wikipage.html)
|
41
|
+
* [XHTML 1.0](http://htmlpreview.github.com/?https://github.com/nico-hn/PseudoHikiParser/blob/develop/samples/wikipage_with_toc.html)
|
42
|
+
* [HTML5](http://htmlpreview.github.com/?https://github.com/nico-hn/PseudoHikiParser/blob/develop/samples/wikipage_html5_with_toc.html)
|
43
|
+
* [GFM](https://github.com/nico-hn/PseudoHikiParser/blob/develop/samples/wikipage.md)
|
44
|
+
|
45
|
+
You will find these samples in [develop branch](https://github.com/nico-hn/PseudoHikiParser/tree/develop/samples).
|
35
46
|
|
36
47
|
### pseudohiki2html.rb
|
37
48
|
|
38
|
-
|
49
|
+
_(Please note that pseudohiki2html.rb is currently provided as a showcase of PseudoHikiParser, and the options will be continuously changed at this stage of development.)_
|
39
50
|
|
40
|
-
|
51
|
+
After the installation of PseudoHikiParser, you can use a command: **pseudohiki2html.rb**.
|
41
52
|
|
42
|
-
|
53
|
+
Type the following lines at the command prompt:
|
43
54
|
|
44
55
|
```
|
45
56
|
pseudohiki2html.rb <<TEXT
|
@@ -48,7 +59,7 @@ The first paragraph
|
|
48
59
|
TEXT
|
49
60
|
```
|
50
61
|
|
51
|
-
will return the following result to stdout:
|
62
|
+
And it will return the following result to stdout:
|
52
63
|
|
53
64
|
```html
|
54
65
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
@@ -83,13 +94,13 @@ The first paragraph
|
|
83
94
|
TEXT
|
84
95
|
```
|
85
96
|
|
86
|
-
the result will be saved in
|
97
|
+
the result will be saved in first\_example.html.
|
87
98
|
|
88
99
|
For more options, please try `pseudohiki2html.rb --help`
|
89
100
|
|
90
101
|
#### Incompatible changes
|
91
102
|
|
92
|
-
From version 0.0.0.9, command line options are renamed as follows:
|
103
|
+
From version 0.0.0.9.develop, command line options are renamed as follows:
|
93
104
|
|
94
105
|
|old name |new name |note |
|
95
106
|
|---------------|-----------------|-----------------------------------------------------------|
|
@@ -99,7 +110,9 @@ From version 0.0.0.9, command line options are renamed as follows:
|
|
99
110
|
|--encoding |--format-encoding|'--encoding' is now used as the long version of '-E' option|
|
100
111
|
|- |--encoding |now same as '-E' option of MRI |
|
101
112
|
|
102
|
-
###
|
113
|
+
### class PseudoHiki::BlockParser
|
114
|
+
|
115
|
+
A class method PseudoHiki::BlockParser.parse composes a syntax tree from its input, and a visitor class converts the tree into a certain format.
|
103
116
|
|
104
117
|
If you save the lines below as a ruby script and execute it:
|
105
118
|
|
@@ -108,12 +121,12 @@ If you save the lines below as a ruby script and execute it:
|
|
108
121
|
|
109
122
|
require 'pseudohikiparser'
|
110
123
|
|
111
|
-
|
124
|
+
hiki_text = <<TEXT
|
112
125
|
!! The first heading
|
113
126
|
The first paragraph
|
114
127
|
TEXT
|
115
128
|
|
116
|
-
tree = PseudoHiki::BlockParser.parse(
|
129
|
+
tree = PseudoHiki::BlockParser.parse(hiki_text)
|
117
130
|
html = PseudoHiki::HtmlFormat.format(tree)
|
118
131
|
puts html
|
119
132
|
```
|
@@ -131,7 +144,37 @@ The first paragraph
|
|
131
144
|
</div>
|
132
145
|
```
|
133
146
|
|
134
|
-
|
147
|
+
In the example above, HtmlFormat is a visitor class that converts the parsed text into HTML 4.01 format.
|
148
|
+
|
149
|
+
Other than HtmlFormat, XhtmlFormat, Xhtml5Format, PlainTextFormat and MarkDownFormat are available.
|
150
|
+
|
151
|
+
### class PseudoHiki::Format
|
152
|
+
|
153
|
+
If you don't need to reuse a tree parsed by PseudoHiki::BlockParser.parse, you can use following class methods of PseudoHiki::Format.
|
154
|
+
|
155
|
+
|Method name |Result of conversion |
|
156
|
+
|------------|------------------------|
|
157
|
+
|to\_html |HTML 4.01 |
|
158
|
+
|to\_xhtml |XHTML 1.0 |
|
159
|
+
|to\_html5 |HTML 5 |
|
160
|
+
|to\_plain |plain text |
|
161
|
+
|to\_markdown|Markdown |
|
162
|
+
|to\_gfm |Github Flavored Markdown|
|
163
|
+
|
164
|
+
For example, the script below returns the same result as the example of [PseudoHiki::BlockParser](#class-pseudohikiblockparser)
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
#!/usr/bin/env ruby
|
168
|
+
|
169
|
+
require 'pseudohikiparser'
|
170
|
+
|
171
|
+
hiki_text = <<TEXT
|
172
|
+
!! The first heading
|
173
|
+
The first paragraph
|
174
|
+
TEXT
|
175
|
+
|
176
|
+
puts PseudoHiki::Format.to_html(hiki_text)
|
177
|
+
```
|
135
178
|
|
136
179
|
## Development status of features from the original [Hiki notation](http://rabbit-shocker.org/en/hiki.html)
|
137
180
|
|
@@ -142,7 +185,7 @@ Other than PseudoHiki::HtmlFormat, you can choose PseudoHiki::XhtmlFormat, Pseud
|
|
142
185
|
* Linking to an arbitrary URL - Maybe usable
|
143
186
|
* Preformatted text - Usable
|
144
187
|
* Text decoration - Partly supported
|
145
|
-
* Means of escaping tags for inline decorations is
|
188
|
+
* Means of escaping tags for inline decorations is just experimetal.
|
146
189
|
* The notation for inline literals by backquote tags(``) is converted into not \<tt\> element but \<code\> element.
|
147
190
|
* Headings - Usable
|
148
191
|
* Horizontal lines - Usable
|
@@ -155,11 +198,9 @@ Other than PseudoHiki::HtmlFormat, you can choose PseudoHiki::XhtmlFormat, Pseud
|
|
155
198
|
|
156
199
|
## Additional Features
|
157
200
|
|
158
|
-
###
|
201
|
+
### Assigning ids
|
159
202
|
|
160
|
-
|
161
|
-
|
162
|
-
If you add [name_of_id], just after the marks that denote heading or list type items, it becomes the id attribute of resulting html elements. Below is an example.
|
203
|
+
If you add [name\_of\_id], just after the marks that denote heading or list type items, it becomes the id attribute of resulting html elements. Below is an example.
|
163
204
|
|
164
205
|
```
|
165
206
|
!![heading_id]heading
|
@@ -181,11 +222,130 @@ will be rendered as
|
|
181
222
|
</div>
|
182
223
|
```
|
183
224
|
|
184
|
-
###
|
225
|
+
### Escaping tags for inline decorations
|
226
|
+
|
227
|
+
_(Please note that this is just an experimental feature.)_
|
228
|
+
|
229
|
+
Tags for inline decorations are escaped when they are enclosed in plugin tags:
|
230
|
+
|
231
|
+
```
|
232
|
+
For example, {{''}} and {{==}} can be escaped.
|
233
|
+
And {{ {}} and {{} }} should be rendered as two left curly braces and two right curly braces respectively.
|
234
|
+
```
|
235
|
+
|
236
|
+
will be rendered as
|
237
|
+
|
238
|
+
```
|
239
|
+
For example, '' or == can be escaped.
|
240
|
+
And {{ and }} sould be rendered as two left curly braces and two right curly braces respectively.
|
241
|
+
```
|
242
|
+
|
243
|
+
### Nesting of link tags
|
185
244
|
|
186
|
-
|
245
|
+
If a link tag is nested inside another link tag, the outer tag is always treated as a link even when its url is for an image.
|
187
246
|
|
188
|
-
|
247
|
+
So you can make a link from a thumbnail as in the following example.
|
248
|
+
|
249
|
+
```
|
250
|
+
[[[[thumbnail of an image|http://www.example.org/image_thumb.png]]|http://www.example.org/image.png]]
|
251
|
+
```
|
252
|
+
|
253
|
+
will be rendered as
|
254
|
+
|
255
|
+
```html
|
256
|
+
<a href="http://www.example.org/image.png"><img alt="thumbnail of an image" src="http://www.example.org/image_thumb.png">
|
257
|
+
</a></p>
|
258
|
+
```
|
259
|
+
|
260
|
+
### Experimental
|
261
|
+
|
262
|
+
The following feature is just experimental and available only in [develop branch](https://github.com/nico-hn/PseudoHikiParser/tree/develop).
|
263
|
+
|
264
|
+
#### Decorator for blocks
|
265
|
+
|
266
|
+
By lines that begin with '//@', you can assign certain attributes to its succeeding block.
|
267
|
+
|
268
|
+
For example,
|
269
|
+
|
270
|
+
```
|
271
|
+
//@class[class_name]
|
272
|
+
!!A section with a class name
|
273
|
+
|
274
|
+
paragraph
|
275
|
+
```
|
276
|
+
|
277
|
+
will be renderes as
|
278
|
+
|
279
|
+
```html
|
280
|
+
<div class="class_name">
|
281
|
+
<h2>A section with a class name
|
282
|
+
</h2>
|
283
|
+
<p>
|
284
|
+
paragraph
|
285
|
+
</p>
|
286
|
+
<!-- end of class_name -->
|
287
|
+
</div>
|
288
|
+
```
|
289
|
+
|
290
|
+
### Not Implemented Yet
|
291
|
+
|
292
|
+
## Visitor classes
|
293
|
+
|
294
|
+
Please note that some of the following classes are implemented partly or not tested well.
|
295
|
+
|
296
|
+
### [HtmlFormat](https://github.com/nico-hn/PseudoHikiParser/blob/develop/lib/pseudohiki/htmlformat.rb#L8), [XhtmlFormat](https://github.com/nico-hn/PseudoHikiParser/blob/develop/lib/pseudohiki/htmlformat.rb#L263)
|
297
|
+
|
298
|
+
Their class method (HtmlFormat|XhtmlFormat).format returns a tree of [HtmlElement](https://github.com/nico-hn/PseudoHikiParser/blob/develop/lib/htmlelement.rb) objects, and you can traverse the tree as in the following example.
|
299
|
+
|
300
|
+
```ruby
|
301
|
+
#!/usr/bin/env ruby
|
302
|
+
|
303
|
+
require 'pseudohikiparser'
|
304
|
+
|
305
|
+
hiki_text = <<HIKI
|
306
|
+
!! heading
|
307
|
+
|
308
|
+
paragraph 1 that contains [[a link to a html file|http://www.example.org/example.html]]
|
309
|
+
|
310
|
+
paragraph 2 that contains [[a link to a pdf file|http://www.example.org/example.pdf]]
|
311
|
+
HIKI
|
312
|
+
|
313
|
+
html = HtmlFormat.format(hiki_text)
|
314
|
+
|
315
|
+
html.traverse do |elm|
|
316
|
+
if elm.kind_of? HtmlElement and elm.tagname == "a"
|
317
|
+
elm["class"] = "pdf" if /\.pdf\Z/o =~ elm["href"]
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
puts html.to_s
|
322
|
+
```
|
323
|
+
|
324
|
+
will print
|
325
|
+
|
326
|
+
```html
|
327
|
+
<div class="section h2">
|
328
|
+
<h2> heading
|
329
|
+
</h2>
|
330
|
+
<p>
|
331
|
+
paragraph 1 that contains <a href="http://www.example.org/example.html">a link to a html file</a>
|
332
|
+
</p>
|
333
|
+
<p>
|
334
|
+
paragraph 2 that contains <a class="pdf" href="http://www.example.org/example.pdf">a link to a pdf file</a>
|
335
|
+
</p>
|
336
|
+
<!-- end of section h2 -->
|
337
|
+
</div>
|
338
|
+
```
|
339
|
+
|
340
|
+
### [Xhtml5Format](https://github.com/nico-hn/PseudoHikiParser/blob/develop/lib/pseudohiki/htmlformat.rb#L268)
|
341
|
+
|
342
|
+
This visitor is for HTML5.
|
343
|
+
|
344
|
+
Currently there aren't many differences with [XhtmlFormat](https://github.com/nico-hn/PseudoHikiParser/blob/develop/lib/pseudohiki/htmlformat.rb#L263) exept for the treatment of \<section\> elements.
|
345
|
+
|
346
|
+
### [PlainTextFormat](https://github.com/nico-hn/PseudoHikiParser/blob/develop/lib/pseudohiki/plaintextformat.rb)
|
347
|
+
|
348
|
+
This visitor removes markups from its input and returns plain texts. Below are examples
|
189
349
|
|
190
350
|
```
|
191
351
|
:tel:03-xxxx-xxxx
|
@@ -219,15 +379,9 @@ cell 3-1 || || cell 3-4 cell 3-5
|
|
219
379
|
cell 4-1 cell 4-2 cell 4-3 cell 4-4 cell 4-5
|
220
380
|
```
|
221
381
|
|
222
|
-
|
223
|
-
|
224
|
-
The visitor, [Xhtml5Format](https://github.com/nico-hn/PseudoHikiParser/blob/develop/lib/pseudohiki/htmlformat.rb#L239) is currently available only in the [develop branch](https://github.com/nico-hn/PseudoHikiParser/tree/develop).
|
225
|
-
|
226
|
-
#### A visitor for (Git Flavored) Markdown
|
227
|
-
|
228
|
-
The visitor, [MarkDownFormat](https://github.com/nico-hn/PseudoHikiParser/blob/develop/lib/pseudohiki/markdownformat.rb) too, is currently available only in the [develop branch](https://github.com/nico-hn/PseudoHikiParser/tree/develop/).
|
382
|
+
### [MarkDownFormat](https://github.com/nico-hn/PseudoHikiParser/blob/develop/lib/pseudohiki/markdownformat.rb)
|
229
383
|
|
230
|
-
|
384
|
+
This visitor is for (Git Flavored) Markdown and just in experimental stage.
|
231
385
|
|
232
386
|
The following are a sample script and its output:
|
233
387
|
|
@@ -253,7 +407,7 @@ tree = PseudoHiki::BlockParser.parse(hiki)
|
|
253
407
|
md_text = md.format(tree).to_s
|
254
408
|
gfm_text = gfm.format(tree).to_s
|
255
409
|
puts md_text
|
256
|
-
puts "
|
410
|
+
puts "--------------------"
|
257
411
|
puts gfm_text
|
258
412
|
```
|
259
413
|
|
@@ -269,7 +423,7 @@ The first paragraph
|
|
269
423
|
<tr><td><em>cell 1</em></td><td>cell2</td></tr>
|
270
424
|
</table>
|
271
425
|
|
272
|
-
|
426
|
+
--------------------
|
273
427
|
## The first heading
|
274
428
|
|
275
429
|
The first paragraph
|
@@ -279,49 +433,3 @@ The first paragraph
|
|
279
433
|
|_cell 1_|cell2 |
|
280
434
|
```
|
281
435
|
|
282
|
-
### Experimental
|
283
|
-
|
284
|
-
#### Escaping tags for inline decorations
|
285
|
-
|
286
|
-
Tags for inline decorations are escaped when they are enclosed in plugin tags:
|
287
|
-
|
288
|
-
```
|
289
|
-
For example, {{''}} and {{==}} can be escaped.
|
290
|
-
And {{ {}} and {{} }} should be rendered as two left curly braces and two right curly braces respectively.
|
291
|
-
```
|
292
|
-
|
293
|
-
will be rendered as
|
294
|
-
|
295
|
-
```
|
296
|
-
For example, '' or == can be escaped.
|
297
|
-
And {{ and }} sould be rendered as two left curly braces and two right curly braces respectively.
|
298
|
-
```
|
299
|
-
|
300
|
-
#### Decorator for blocks
|
301
|
-
|
302
|
-
By lines that begin with '//@', you can assign certain attributes to its succeeding block.
|
303
|
-
|
304
|
-
For example,
|
305
|
-
|
306
|
-
```
|
307
|
-
//@class[class_name]
|
308
|
-
!!A section with a class name
|
309
|
-
|
310
|
-
paragraph
|
311
|
-
```
|
312
|
-
|
313
|
-
will be renderes as
|
314
|
-
|
315
|
-
```html
|
316
|
-
<div class="class_name">
|
317
|
-
<h2>A section with a class name
|
318
|
-
</h2>
|
319
|
-
<p>
|
320
|
-
paragraph
|
321
|
-
</p>
|
322
|
-
<!-- end of class_name -->
|
323
|
-
</div>
|
324
|
-
```
|
325
|
-
|
326
|
-
### Not Implemented Yet
|
327
|
-
|