File: basic-usage.html

package info (click to toggle)
ruby-bluefeather 0.41-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 632 kB
  • ctags: 167
  • sloc: ruby: 4,195; makefile: 7
file content (307 lines) | stat: -rw-r--r-- 10,032 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Installing and Basic Usage - BlueFeather Manual</title>
<link rel="stylesheet" type="text/css" href="black.css" />
</head>
<body>

<div class="back"><a href="index.html">BlueFeather Manual</a></div>

<h1 id="bfheader-1a89f3bf198317c0b4f86253e0bdecd3">Installing and Basic Usage</h1>

<p>This document describes only usage of the software. If you want to know about
syntax, see <a href="format-extension.html">Markdown Syntax Extension</a>.</p>

<ul>
<li><a href="#bfheader-349838fb1d851d3e2014b9fe39203275" rel="toc">Install</a></li>
<li><a href="#bfheader-5a1a4bf445864249197159704f61a362" rel="toc">Use by Command-line</a>
<ul>
<li><a href="#bfheader-972e73b7a882d0802a4e3a16946a2f94" rel="toc">Basic</a></li>
<li><a href="#bfheader-f8a5ceba4ab3ef0272c92fbcece80dd8" rel="toc">Option for Forcing to Convert (<code>--force</code>)</a></li>
<li><a href="#bfheader-3af22b762da471e997070a49f8982292" rel="toc">Extname Switch</a></li>
<li><a href="#bfheader-e009128587b41717d006d612146b32a8" rel="toc">Document Metadata</a></li>
<li><a href="#bfheader-525ec2a4890848edb94043d7c1bcfd12" rel="toc">stdin-mode</a></li>
<li><a href="#commandline-options" rel="toc">Command-line Options</a></li>
</ul></li>
<li><a href="#bfheader-ea4b8233c187e9e87b21ba52d38720e8" rel="toc">Use in Ruby Script</a>
<ul>
<li><a href="#bfheader-972e73b7a882d0802a4e3a16946a2f94" rel="toc">Basic</a></li>
<li><a href="#bfheader-6567398110bdf1f81916b86d04f3e1e3" rel="toc">Generate HTML Document</a></li>
<li><a href="#bfheader-c2d7181a11dd80ca24bcfab69176f3c2" rel="toc">Get document metadata</a></li>
</ul></li>
</ul>

<h2 id="bfheader-349838fb1d851d3e2014b9fe39203275">Install</h2>

<p>Run setup.rb. Then required files will be copied and installing will be complete.</p>

<pre><code>% ruby setup.rb
</code></pre>

<p>Or use RubyGems.</p>

<pre><code>% gem install bluefeather
</code></pre>

<h2 id="bfheader-5a1a4bf445864249197159704f61a362">Use by Command-line</h2>

<h3 id="bfheader-972e73b7a882d0802a4e3a16946a2f94">Basic</h3>

<p>If installing is correctly completed, you can use <code>bluefeather</code> command. This
command convert Markdown text to html.</p>

<pre><code>bluefeather [options] file1 [file2] [file3] ...
</code></pre>



<pre><code>% bluefeather *.bftext
example1.bftext =&gt; example1.html (4240 byte)
example2.bftext =&gt; example2.html (5613 byte)
example3.bftext =&gt; example3.html (10499 byte)
%
</code></pre>

<h3 id="bfheader-f8a5ceba4ab3ef0272c92fbcece80dd8">Option for Forcing to Convert (<code>--force</code>)</h3>

<p>In default, <code>bluefeather</code> command converts only input files that were modified.</p>

<pre><code>% bluefeather example1.bftext
example1.bftext =&gt; example1.html (4240 byte)
% bluefeather example1.bftext
%
</code></pre>

<p>If you want to convert all files despite modified time of them, use <code>--force</code> option.</p>

<pre><code>% bluefeather example1.bftext
example1.bftext =&gt; example1.html (4240 byte)
% bluefeather --force example1.bftext
example1.bftext =&gt; example1.html (4240 byte)
%
</code></pre>

<p>If you know better about other options, see the section of <a href="#commandline-options">Command-line Option</a>.</p>

<h3 id="bfheader-3af22b762da471e997070a49f8982292">Extname Switch</h3>

<p><code>bluefeather</code> command switches by extname of an input file how generate a html file.</p>

<dl>
  <dt><code>.md</code>, <code>.bfdoc</code></dt>
  <dd>generate html document</dd>
  <dt>others</dt>
  <dd>generate html part</dd>
</dl>

<p>For example, see the text.</p>

<pre><code>test paragraph.
</code></pre>

<p>If this text is named '<code>test1.bftext</code>', <code>bluefeather</code> generates <code>test1.html</code> such as this.</p>

<pre><code>&lt;p&gt;test paragraph.&lt;/p&gt;
</code></pre>

<p>But this text is named '<code>test1.bfdoc</code>', generated html is changed.</p>

<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;no title (Generated by BlueFeather)&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;p&gt;test paragraph.&lt;/p&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>If the converted document is include h1 element, BlueFeather use it's content for title of html document. </p>

<dl>
  <dt>test2.bfdoc</dt>
  <dd><pre><code>Test Document
=============

test paragraph.
</code></pre></dd>
  <dt>test2.html (output)</dt>
  <dd><pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Test Document&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;h1 id="bfheader-a5decd745d43af4aa8cf62eef5be43ac"&gt;Test Document&lt;/h1&gt;

&lt;p&gt;test paragraph.&lt;/p&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre></dd>
</dl>

<h3 id="bfheader-e009128587b41717d006d612146b32a8">Document Metadata</h3>

<p>You can add <em>document metadata</em> to files which have extname <code>.bfdoc</code> or <code>.md</code></p>

<dl>
  <dt>test3.bfdoc</dt>
  <dd><pre><code>Title: Test Document
CSS: style.css

Test paragraph.
</code></pre></dd>
  <dt>test3.html</dt>
  <dd><pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Test Document&lt;/title&gt;
&lt;link rel="stylesheet" type="text/css" href="style.css" /&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;p&gt;Test paragraph.&lt;/p&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre></dd>
</dl>

<p>If you know better about metadata, see the section of <a href="metadata-reference.html">Metadata Reference</a>.</p>

<h3 id="bfheader-525ec2a4890848edb94043d7c1bcfd12">stdin-mode</h3>

<p>If you use stdin and stdout, specify a parameter only <code>-</code>. This mode is useful for pipe-line.</p>

<pre><code>% bluefeather -
</code></pre>

<h3 id="commandline-options">Command-line Options</h3>



<pre><code>% bluefeather --help
bluefeather - Extended Markdown Converter

Usage: bluefeather [options] file1 [file2 file3 ..]

Options:
  -e, --encoding NAME   parse input files as encoding of NAME.
                        (s[hift-jis] / e[uc-jp] / u[tf-8] / a[scii]
                         default: 'utf-8')
  -f, --format TYPE     specify format.
                        (t[ext]      =&gt; text mode
                         d[ocument]  =&gt; document mode)
      --force           write even if target files have not changed.
                        (default: only if target files have changed)
  -h, --help            show this help.
  -o, --output DIR      output files to DIR. (default: same as input file)
  -q, --quiet           no output to stderr.
      --suffix .SUF     specify suffix of output files. (default: '.html')
  -v, --verbose         verbose mode - output detail of operation.
      --version         show BlueFeather version.

Advanced Usage:
  * If specify files only '-', bluefeather read from stdin and write to stdout.


Example:
  bluefeather *.bftext *.bfdoc
  bluefeather -v --sufix .xhtml -o ../ sample.markdown
  bluefeather -

More info:
  see &lt;http://ruby.morphball.net/bluefeather/&gt;
%
</code></pre>



<h2 id="bfheader-ea4b8233c187e9e87b21ba52d38720e8">Use in Ruby Script</h2>

<h3 id="bfheader-972e73b7a882d0802a4e3a16946a2f94">Basic</h3>

<p>Most basic method is <code>BlueFeather.parse</code>.</p>

<pre><code>require 'bluefeather'

str = "most basic example."
puts BlueFeather.parse(str)      #=&gt; "&lt;p&gt;most basic example.&lt;/p&gt;"
</code></pre>

<p>And you can use <code>BlueFeather.parse_file</code>.</p>

<pre><code>BlueFeather.parse_file('test1.txt')
BlueFeather.parse_file('test2.markdown')
BlueFeather.parse_file('test3.bftext')
</code></pre>

<h3 id="bfheader-6567398110bdf1f81916b86d04f3e1e3">Generate HTML Document</h3>

<p>If you want a html document not html fragment, you may use <code>parse_document</code> or <code>parse_document_file</code>.</p>

<dl>
  <dt>test.bfdoc</dt>
  <dd><pre><code>The sentence is expected as HTML.
</code></pre></dd>
  <dt>test.rb</dt>
  <dd><pre><code>require 'bluefeather'

puts '-- parse_file --'
puts BlueFeather.parse_file('test.bfdoc')

puts '-- parse_document_file --'
puts BlueFeather.parse_document_file('test.bfdoc')
</code></pre></dd>
  <dt>Result</dt>
  <dd><pre><code>-- parse_file --
&lt;p&gt;The sentence is expected as HTML.&lt;/p&gt;

-- parse_document_file --
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;no title (Generated by BlueFeather)&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;p&gt;The sentence is expected as HTML.&lt;/p&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre></dd>
</dl>

<h3 id="bfheader-c2d7181a11dd80ca24bcfab69176f3c2">Get document metadata</h3>

<p>If you want to get directly metadata of document, instead of BlueFeather module method, you should use <code>BlueFeather::Document</code> class.</p>

<pre><code>doc = BlueFeather::Document.parse(&lt;&lt;EOS)
Title: test document
CSS: style.css

test paragraph.
EOS

p doc['title']     # =&gt; "test document"
p doc['css']       # =&gt; "style.css"
p doc[:css]        # =&gt; "style.css"
p doc['undefined'] # =&gt; nil

p doc.body         # =&gt; "test paragraph."
</code></pre>

<p><code>to_html</code> parses the text and generates an html document actually.</p>

<pre><code>doc.to_html
</code></pre>

</body>
</html>