bluefeather 0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile.rb +168 -0
- data/bin/bluefeather +4 -0
- data/doc/author-and-license.bfdoc +16 -0
- data/doc/base.css +135 -0
- data/doc/basic-usage.bfdoc +265 -0
- data/doc/black.css +130 -0
- data/doc/class-reference.bfdoc +105 -0
- data/doc/difference.bfdoc +63 -0
- data/doc/en/author-and-license.bfdoc +20 -0
- data/doc/en/base.css +136 -0
- data/doc/en/basic-usage.bfdoc +266 -0
- data/doc/en/black.css +130 -0
- data/doc/en/class-reference.bfdoc +6 -0
- data/doc/en/difference.bfdoc +72 -0
- data/doc/en/format-extension.bfdoc +324 -0
- data/doc/en/index.bfdoc +41 -0
- data/doc/en/metadata-reference.bfdoc +7 -0
- data/doc/format-extension.bfdoc +325 -0
- data/doc/index.bfdoc +36 -0
- data/doc/metadata-reference.bfdoc +86 -0
- data/lib/bluefeather.rb +1872 -0
- data/lib/bluefeather/cui.rb +207 -0
- data/license/gpl-2.0.txt +339 -0
- data/license/gpl.ja.txt +416 -0
- data/original-tests/00_Class.tests.rb +42 -0
- data/original-tests/05_Markdown.tests.rb +1530 -0
- data/original-tests/10_Bug.tests.rb +44 -0
- data/original-tests/15_Contrib.tests.rb +130 -0
- data/original-tests/bftestcase.rb +278 -0
- data/original-tests/data/antsugar.txt +34 -0
- data/original-tests/data/ml-announce.txt +17 -0
- data/original-tests/data/re-overflow.txt +67 -0
- data/original-tests/data/re-overflow2.txt +281 -0
- data/readme_en.txt +37 -0
- data/readme_ja.txt +33 -0
- data/spec/auto-link.rb +100 -0
- data/spec/code-block.rb +91 -0
- data/spec/dl.rb +182 -0
- data/spec/escape-char.rb +18 -0
- data/spec/footnote.rb +34 -0
- data/spec/header-id.rb +38 -0
- data/spec/lib/common.rb +103 -0
- data/spec/table.rb +70 -0
- data/spec/toc.rb +64 -0
- data/spec/warning.rb +61 -0
- metadata +99 -0
data/Rakefile.rb
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
# encoding: us-ascii
|
2
|
+
#-----------------------------------------------------------
|
3
|
+
# BlueFeather rakefile
|
4
|
+
#
|
5
|
+
# Requirement:
|
6
|
+
# Ruby (1.8.1 later)
|
7
|
+
# Rake - <http://rake.rubyforge.org/> or `gem install rake` with RubyGems
|
8
|
+
# Exerb - <http://exerb.sourceforge.jp/>
|
9
|
+
# Info-Zip - If you use Windows, you can get it from GnuWin32
|
10
|
+
# <http://gnuwin32.sourceforge.net/>
|
11
|
+
# Rspec - `gem install rspec` with RubyGems
|
12
|
+
#-----------------------------------------------------------
|
13
|
+
|
14
|
+
require 'rake/testtask'
|
15
|
+
require 'rake/gempackagetask'
|
16
|
+
require 'spec/rake/spectask'
|
17
|
+
require 'rake/clean'
|
18
|
+
|
19
|
+
$KCODE = 'u'
|
20
|
+
$LOAD_PATH.unshift './lib'
|
21
|
+
require 'bluefeather'
|
22
|
+
|
23
|
+
ZIP_NAME = "pkg/bluefeather-#{BlueFeather::VERSION}.zip"
|
24
|
+
|
25
|
+
CLOBBER.include 'sample/*.html'
|
26
|
+
CLOBBER.include 'doc/**/*.html'
|
27
|
+
|
28
|
+
# setup.rb
|
29
|
+
CLEAN.include('InstalledFiles', '.config', 'bin/bluefeather.bat')
|
30
|
+
|
31
|
+
PACKAGED = FileList.new
|
32
|
+
PACKAGED.include('readme*.txt')
|
33
|
+
PACKAGED.include('setup.rb')
|
34
|
+
PACKAGED.include('Rakefile.rb')
|
35
|
+
PACKAGED.include('bin/**/*')
|
36
|
+
PACKAGED.include('lib/bluefeather.rb')
|
37
|
+
PACKAGED.include('lib/bluefeather/*.rb')
|
38
|
+
PACKAGED.include('license/**/*')
|
39
|
+
PACKAGED.include('spec/**/*')
|
40
|
+
PACKAGED.include('original-tests/**/*')
|
41
|
+
PACKAGED.include('doc/**/*.*')
|
42
|
+
PACKAGED.exclude('doc/**/format-extension-spec.*')
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
task :default => :package
|
47
|
+
|
48
|
+
desc 'Package to zip.'
|
49
|
+
task :package => [:doc, ZIP_NAME]
|
50
|
+
|
51
|
+
desc 'Clobber and package.'
|
52
|
+
task :repackage => [:clobber, :package]
|
53
|
+
|
54
|
+
file ZIP_NAME => PACKAGED do |task|
|
55
|
+
mkpath 'pkg'
|
56
|
+
src_list = task.prerequisites.map{|x| %Q|"#{x}"|}.join(' ')
|
57
|
+
sh "zip -q #{task.name} #{src_list}"
|
58
|
+
puts "#{task.name} maked. (#{File.size(task.name) / 1024} KB)"
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
DOCS = []
|
65
|
+
Dir.glob('doc/**/*.bfdoc').each do |src|
|
66
|
+
dest = src.sub(/\.bfdoc$/, '.html')
|
67
|
+
DOCS << dest
|
68
|
+
|
69
|
+
file dest => src do
|
70
|
+
html = BlueFeather.parse_document_file(src)
|
71
|
+
open(dest, 'w'){|f| f.write(html)}
|
72
|
+
puts "#{src} => #{dest}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
desc 'Convert documents, bfdoc -> html'
|
77
|
+
task :doc => DOCS
|
78
|
+
|
79
|
+
task :sample => 'sample/sample.html'
|
80
|
+
|
81
|
+
file 'sample/sample.html' => 'sample/sample.bfdoc' do |task|
|
82
|
+
html = BlueFeather.parse_document_file(task.prerequisites.first)
|
83
|
+
open(task.name, 'w'){|f| f.write(html)}
|
84
|
+
puts "#{task.prerequisites.first} => #{task.name}"
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
GEM_PACKAGED = PACKAGED.dup
|
91
|
+
GEM_PACKAGED.exclude('setup.rb')
|
92
|
+
|
93
|
+
spec = Gem::Specification.new do |s|
|
94
|
+
s.platform = Gem::Platform::RUBY
|
95
|
+
s.summary = "Extend Markdown Converter"
|
96
|
+
s.author = 'Dice'
|
97
|
+
s.email = 'tetradice@gmail.com'
|
98
|
+
s.homepage = 'http://ruby.morphball.net/bluefeather/'
|
99
|
+
s.name = 'bluefeather'
|
100
|
+
s.rubyforge_project = 'bluefeather'
|
101
|
+
s.has_rdoc = false
|
102
|
+
s.required_ruby_version = '>= 1.8.1'
|
103
|
+
s.version = BlueFeather::VERSION
|
104
|
+
s.files = GEM_PACKAGED
|
105
|
+
s.executables = ['bluefeather']
|
106
|
+
s.description = <<EOF
|
107
|
+
BlueFeather is software for converting text written by extended Markdown to
|
108
|
+
html. It is pair of command-line tool and pure Ruby library.
|
109
|
+
EOF
|
110
|
+
end
|
111
|
+
|
112
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
desc 'Run tests of original BlueCloth.'
|
121
|
+
Rake::TestTask.new('original-test') do |tasklib|
|
122
|
+
tasklib.test_files = FileList['original-tests/*.tests.rb']
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
# Proc for initializing each spec-tasks by common parameters
|
127
|
+
setting = proc do |st|
|
128
|
+
st.libs << ['./lib']
|
129
|
+
st.ruby_opts = %w(-Ku)
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
desc "Verify all spec files."
|
134
|
+
Spec::Rake::SpecTask.new do |st|
|
135
|
+
setting.call(st)
|
136
|
+
st.spec_files = FileList['spec/*.rb']
|
137
|
+
end
|
138
|
+
|
139
|
+
desc "Verify all spec files with specdocs."
|
140
|
+
Spec::Rake::SpecTask.new(:specd) do |st|
|
141
|
+
setting.call(st)
|
142
|
+
st.spec_opts << '-fs'
|
143
|
+
st.spec_files = FileList['spec/*.rb']
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
namespace :spec do
|
149
|
+
Dir.glob('spec/*.rb') do |path|
|
150
|
+
desc "Verify '#{path}'"
|
151
|
+
Spec::Rake::SpecTask.new(File.basename(path, '.rb')) do |st|
|
152
|
+
setting.call(st)
|
153
|
+
st.spec_files = FileList[path]
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
namespace :specd do
|
159
|
+
Dir.glob('spec/*.rb') do |path|
|
160
|
+
desc "Verify '#{path}' with specdocs."
|
161
|
+
Spec::Rake::SpecTask.new(File.basename(path, '.rb')) do |st|
|
162
|
+
setting.call(st)
|
163
|
+
st.spec_opts << '-fs'
|
164
|
+
st.spec_files = FileList[path]
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
data/bin/bluefeather
ADDED
@@ -0,0 +1,16 @@
|
|
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
|
+
BlueFeather は、改変元である BlueCloth のライセンス(利用条件)に基づき、General Public License(GPL)バージョン 2 の元で配布されるフリーソフトウェアです。
|
11
|
+
詳しくは、`bluefeather.rb` のファイル頭にある著作権表示、および同梱の `license/` ディレクトリ内にある GPL 公衆利用許諾契約書を参照してください。
|
12
|
+
|
13
|
+
* [Wikipedia - GNU General Public License](http://ja.wikipedia.org/wiki/GNU_General_Public_License)
|
14
|
+
|
15
|
+
|
16
|
+
BlueFeather への要望、ご意見、バグ報告などがありましたら、[BlueFeather 配布サイト](http://ruby.morphball.net/bluefeather/)よりメッセージを送信していただくか、もしくは Dice(<tetradice@gmail.com>)までメールでご連絡していただけるよう、よろしくお願いします。
|
data/doc/base.css
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
body {
|
2
|
+
font-size : medium;
|
3
|
+
line-height : 1.4em;
|
4
|
+
margin : 3em 10%;
|
5
|
+
}
|
6
|
+
|
7
|
+
|
8
|
+
div.back{
|
9
|
+
text-align: right;
|
10
|
+
}
|
11
|
+
|
12
|
+
/* �\ */
|
13
|
+
|
14
|
+
table{
|
15
|
+
font-size : 1.0em;
|
16
|
+
margin-left : 1.0em;
|
17
|
+
}
|
18
|
+
|
19
|
+
th {
|
20
|
+
border-style : outset;
|
21
|
+
}
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
/* ���o���E�i�� */
|
26
|
+
|
27
|
+
h1,h2,h3,h4,h5,h6 {
|
28
|
+
line-height : 1.0em;
|
29
|
+
}
|
30
|
+
|
31
|
+
h1 {
|
32
|
+
font-size : xx-large;
|
33
|
+
}
|
34
|
+
|
35
|
+
h2 {
|
36
|
+
font-size : x-large;
|
37
|
+
margin-top : 4em;
|
38
|
+
}
|
39
|
+
|
40
|
+
h3 {
|
41
|
+
font-size : large;
|
42
|
+
margin-top: 3em;
|
43
|
+
}
|
44
|
+
|
45
|
+
/* ���\�b�h�ꗗ�p */
|
46
|
+
h2 + h2, h3 + h3{
|
47
|
+
margin-top: 0.2em;
|
48
|
+
}
|
49
|
+
|
50
|
+
p {
|
51
|
+
margin-left : 2em;
|
52
|
+
}
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
/* ���X�g */
|
57
|
+
li {
|
58
|
+
margin-bottom : 0.6em;
|
59
|
+
}
|
60
|
+
|
61
|
+
|
62
|
+
dl {
|
63
|
+
margin-left : 2.0em;
|
64
|
+
}
|
65
|
+
|
66
|
+
dt {
|
67
|
+
font-weight : bold;
|
68
|
+
}
|
69
|
+
|
70
|
+
dd {
|
71
|
+
margin-left : 2.0em;
|
72
|
+
margin-bottom : 0.5em;
|
73
|
+
}
|
74
|
+
|
75
|
+
ul, ol, dl{
|
76
|
+
margin: 2.0em;
|
77
|
+
}
|
78
|
+
|
79
|
+
ul ul{
|
80
|
+
margin: 0.5em;
|
81
|
+
}
|
82
|
+
|
83
|
+
li p{
|
84
|
+
margin-left: 0.1em;
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
/* ���p���ׂ����� */
|
89
|
+
|
90
|
+
blockquote, pre{
|
91
|
+
margin-left: 3em;
|
92
|
+
margin-bottom: 3em;
|
93
|
+
}
|
94
|
+
|
95
|
+
blockquote p{
|
96
|
+
margin-left: 0.5em;
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
pre {
|
101
|
+
padding: 1em;
|
102
|
+
}
|
103
|
+
|
104
|
+
address {
|
105
|
+
text-align : right;
|
106
|
+
font-style: normal;
|
107
|
+
}
|
108
|
+
|
109
|
+
em {
|
110
|
+
font-weight : bold;
|
111
|
+
font-style : normal;
|
112
|
+
}
|
113
|
+
|
114
|
+
|
115
|
+
pre code{
|
116
|
+
margin: 0;
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
hr {
|
121
|
+
}
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
div.layer {
|
127
|
+
padding-left : 1.5em;
|
128
|
+
}
|
129
|
+
|
130
|
+
div.link {
|
131
|
+
font-size : 1.2em;
|
132
|
+
font-weight : bold;
|
133
|
+
margin-top : 2.0em;
|
134
|
+
margin-left : 0.5em;
|
135
|
+
}
|
@@ -0,0 +1,265 @@
|
|
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
|
+
|
11
|
+
この文書では、BlueFeather そのものの使い方について記述しています。
|
12
|
+
BlueFeather が解釈する Markdown 記法への独自拡張については、[Markdown 記法の拡張](format-extension.html)を参照してください。
|
13
|
+
|
14
|
+
{toc}
|
15
|
+
|
16
|
+
|
17
|
+
インストール
|
18
|
+
----
|
19
|
+
同梱の setup.rb を実行することにより、ファイルが適切な位置にコピーされ、インストールが完了します。
|
20
|
+
|
21
|
+
% ruby setup.rb
|
22
|
+
|
23
|
+
もしくは、RubyGems がインストールされていれば、インターネットに接続されたPCから次のように打ち込むことでインストールすることも可能です。
|
24
|
+
|
25
|
+
% gem install bluefeather
|
26
|
+
|
27
|
+
|
28
|
+
コマンドラインから使う
|
29
|
+
----
|
30
|
+
|
31
|
+
### 基本
|
32
|
+
|
33
|
+
インストールが正常に終了していれば、`bluefeather` コマンドを使って、Markdown記法で書かれたファイルを変換することができます。
|
34
|
+
インターフェースは以下の通りです。
|
35
|
+
|
36
|
+
bluefeather [options] file1 [file2] [file3] ...
|
37
|
+
|
38
|
+
たとえば、次のように入力することで、拡張子が `.bftext` のファイル全てをhtmlファイルに変換することができます。
|
39
|
+
|
40
|
+
% bluefeather *.bftext
|
41
|
+
example1.bftext => example1.html (4240 byte)
|
42
|
+
example2.bftext => example2.html (5613 byte)
|
43
|
+
example3.bftext => example3.html (10499 byte)
|
44
|
+
%
|
45
|
+
|
46
|
+
オプションの種類については、この文書内の[コマンドラインオプション](#commandline-options)の項を参照してください。
|
47
|
+
|
48
|
+
### 拡張子による出力htmlの違い
|
49
|
+
|
50
|
+
`bluefeather` コマンドでは、変換対象のファイルの拡張子によって、どのようなhtmlファイルを出力するかが異なります。
|
51
|
+
|
52
|
+
`.md`, `.bfdoc`
|
53
|
+
:DTD宣言やhead要素などを含んだ、完全なHTML文書を生成する
|
54
|
+
|
55
|
+
それ以外
|
56
|
+
:HTML片を生成する(DTD宣言やhead要素は含まない)
|
57
|
+
|
58
|
+
|
59
|
+
たとえば、次のような一文だけが書かれたテキストファイルがあるとします。
|
60
|
+
|
61
|
+
test paragraph.
|
62
|
+
|
63
|
+
このテキストファイルが `test1.bftext` という名前であれば、変換結果(`test1.html`)はこのようになります。
|
64
|
+
|
65
|
+
<p>test paragraph.</p>
|
66
|
+
|
67
|
+
しかし、もしこのファイルが `test1.bfdoc` という名前であれば、上記の例と異なり_完全なHTML文書を生成します。_
|
68
|
+
|
69
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
70
|
+
<html>
|
71
|
+
<head>
|
72
|
+
<title>no title (Generated by BlueFeather)</title>
|
73
|
+
</head>
|
74
|
+
<body>
|
75
|
+
|
76
|
+
<p>test paragraph.</p>
|
77
|
+
|
78
|
+
</body>
|
79
|
+
</html>
|
80
|
+
|
81
|
+
|
82
|
+
なお、このとき変換する文書にレベル1の見出しが含まれていれば、_その見出しが自動的にhtml文書のtitleとして使われます。_
|
83
|
+
|
84
|
+
test2.bfdoc
|
85
|
+
|
86
|
+
:
|
87
|
+
|
88
|
+
Test Document
|
89
|
+
=============
|
90
|
+
|
91
|
+
test paragraph.
|
92
|
+
|
93
|
+
test2.html(出力結果)
|
94
|
+
|
95
|
+
:
|
96
|
+
|
97
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
98
|
+
<html>
|
99
|
+
<head>
|
100
|
+
<title>Test Document</title>
|
101
|
+
</head>
|
102
|
+
<body>
|
103
|
+
|
104
|
+
<h1 id="bfheader-a5decd745d43af4aa8cf62eef5be43ac">Test Document</h1>
|
105
|
+
|
106
|
+
<p>test paragraph.</p>
|
107
|
+
|
108
|
+
</body>
|
109
|
+
</html>
|
110
|
+
|
111
|
+
|
112
|
+
### 文書メタデータ
|
113
|
+
|
114
|
+
拡張子が `.bfdoc` や `.md` のファイルには、文書メタデータを付け加えることが出来ます。
|
115
|
+
|
116
|
+
test3.bfdoc
|
117
|
+
|
118
|
+
:
|
119
|
+
|
120
|
+
Title: Test Document
|
121
|
+
CSS: style.css
|
122
|
+
|
123
|
+
Test paragraph.
|
124
|
+
|
125
|
+
test3.html
|
126
|
+
|
127
|
+
:
|
128
|
+
|
129
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
130
|
+
<html>
|
131
|
+
<head>
|
132
|
+
<title>Test Document</title>
|
133
|
+
<link rel="stylesheet" type="text/css" href="style.css" />
|
134
|
+
</head>
|
135
|
+
<body>
|
136
|
+
|
137
|
+
<p>Test paragraph.</p>
|
138
|
+
|
139
|
+
</body>
|
140
|
+
</html>
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
メタデータについての詳細は、[メタデータリファレンス](metadata-reference.html)を参照してください。
|
145
|
+
|
146
|
+
### 標準入力からの読み込み(stdin-mode)
|
147
|
+
|
148
|
+
ファイル名を `-` とだけ指定すると特殊な動作モードになり、標準入力からテキストを読み込み、変換結果のhtmlを標準出力へ書き込みます。
|
149
|
+
パイプラインを用いるときなどに便利です。
|
150
|
+
|
151
|
+
% bluefeather -
|
152
|
+
|
153
|
+
|
154
|
+
### コマンドラインオプション {#commandline-options}
|
155
|
+
|
156
|
+
`-e NAME`, `--encoding NAME`
|
157
|
+
:
|
158
|
+
変換するテキストファイルのエンコーディングを、指定したエンコーディングとして解釈します。
|
159
|
+
(`shift-jis` / `euc-jp` / `utf-8` / `none` のうちいずれか、もしくは最初の数文字。標準では `utf-8`)
|
160
|
+
|
161
|
+
`-f TYPE`, `--format TYPE`
|
162
|
+
:
|
163
|
+
出力するhtmlの種別を特定します。
|
164
|
+
`text`, `bftext` ならhtml片を、 `document`, `bfdoc` なら完全なhtml文書を出力します。
|
165
|
+
(標準ではファイルの拡張子から自動判別)
|
166
|
+
|
167
|
+
`-h`, `--help`
|
168
|
+
: `bluefeather` コマンドの解説を表示します。
|
169
|
+
|
170
|
+
`-o DIR`, `--output DIR`
|
171
|
+
: 指定したディレクトリに全てのファイルを生成します。(標準ではパース対象のファイルと同じ位置に生成)
|
172
|
+
|
173
|
+
`-q`, `--quiet`
|
174
|
+
: 動作時に作業の状況や結果を表示しません。
|
175
|
+
|
176
|
+
`--suffix .SUF`
|
177
|
+
: 出力するファイルの拡張子を指定します。(標準は.html)
|
178
|
+
|
179
|
+
`-v`, `--verbose`
|
180
|
+
: 冗長フラグ。作業内容を詳細に表示します。
|
181
|
+
|
182
|
+
`--version`
|
183
|
+
: BlueFeather のバージョンを表示します。
|
184
|
+
|
185
|
+
Rubyスクリプト内で使う
|
186
|
+
----
|
187
|
+
|
188
|
+
### 基本
|
189
|
+
|
190
|
+
もっとも基本的なメソッドは、`BlueFeather.parse` です。
|
191
|
+
このメソッドにより、BlueFeatherを用いて文字列をパースし、htmlに変換することができます。
|
192
|
+
|
193
|
+
require 'bluefeather'
|
194
|
+
|
195
|
+
str = "もっとも基本的な例です。"
|
196
|
+
puts BlueFeather.parse(str) #=> "<p>もっとも基本的な例です。</p>"
|
197
|
+
|
198
|
+
また、`BlueFeather.parse_file` を使えば、ファイルの中にある文字列を読み込んでパースすることができます。
|
199
|
+
|
200
|
+
BlueFeather.parse_file('test1.txt')
|
201
|
+
BlueFeather.parse_file('test2.markdown')
|
202
|
+
BlueFeather.parse_file('test3.bftext')
|
203
|
+
|
204
|
+
|
205
|
+
### HTML文書の生成 ###
|
206
|
+
|
207
|
+
`parse` や `parse_file` メソッドの代わりに、`parse_document` や `parse_document_file` メソッドを用いることによって、HTML片ではなく_完全なHTML文書を生成する_ことが可能です。
|
208
|
+
|
209
|
+
test.bfdoc
|
210
|
+
|
211
|
+
: The sentence is expected as HTML.
|
212
|
+
|
213
|
+
test.rb
|
214
|
+
|
215
|
+
:
|
216
|
+
|
217
|
+
require 'bluefeather'
|
218
|
+
|
219
|
+
puts '-- parse_file --'
|
220
|
+
puts BlueFeather.parse_file('test.bfdoc')
|
221
|
+
|
222
|
+
puts '-- parse_document_file --'
|
223
|
+
puts BlueFeather.parse_document_file('test.bfdoc')
|
224
|
+
|
225
|
+
実行結果
|
226
|
+
|
227
|
+
:
|
228
|
+
|
229
|
+
-- parse_file --
|
230
|
+
<p>The sentence is expected as HTML.</p>
|
231
|
+
|
232
|
+
-- parse_document_file --
|
233
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
234
|
+
<html>
|
235
|
+
<head>
|
236
|
+
<title>no title (Generated by BlueFeather)</title>
|
237
|
+
</head>
|
238
|
+
<body>
|
239
|
+
|
240
|
+
<p>The sentence is expected as HTML.</p>
|
241
|
+
|
242
|
+
</body>
|
243
|
+
</html>
|
244
|
+
|
245
|
+
### 文書のメタデータ取得 ###
|
246
|
+
|
247
|
+
文書をパースして直接 html を生成するのではなく、`BlueFeather::Document` オブジェクトを生成することにより、その文書のメタデータを取得することができます。
|
248
|
+
|
249
|
+
doc = BlueFeather::Document.parse(<<EOS)
|
250
|
+
Title: test document
|
251
|
+
CSS: style.css
|
252
|
+
|
253
|
+
test paragraph.
|
254
|
+
EOS
|
255
|
+
|
256
|
+
p doc['title'] # => "test document"
|
257
|
+
p doc['css'] # => "style.css"
|
258
|
+
p doc[:css] # => "style.css"
|
259
|
+
p doc['undefined'] # => nil
|
260
|
+
|
261
|
+
p doc.body # => "test paragraph."
|
262
|
+
|
263
|
+
この `BlueFeather::Document` オブジェクトから実際に html を生成するには、 `to_html` メソッドを呼んでください。
|
264
|
+
|
265
|
+
doc.to_html
|