hikidoc 0.0.6 → 0.1.1

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.
@@ -0,0 +1,388 @@
1
+ # Paragraphs
2
+
3
+ Consecutive lines are concatenated into a single paragraph.
4
+
5
+ Blank lines (ones with only a carriage return or with only spaces and tabs) mark the end of a paragraph.
6
+
7
+ * Example statement
8
+
9
+ ```
10
+ For example,
11
+ if I write like this, these lines
12
+ will be formatted as one paragraph.
13
+ ```
14
+
15
+ * Example output
16
+
17
+ <p>For example,
18
+ if I write like this, these lines
19
+ will be formatted as one paragraph.</p>
20
+
21
+ # Links
22
+
23
+ ## [WikiNames](WikiNames)
24
+
25
+ [WikiNames](WikiNames) are comprised of two or more words put together; each word begins with an uppercase letter, and is followed by at least one lowercase letter or number.
26
+
27
+ Words in which this condition is met become a [WikiName](WikiName), and a link is automatically attached.
28
+
29
+ * Example statement
30
+
31
+ ```
32
+ WikiName - WikiName
33
+ HogeRule1 - WikiName
34
+ NOTWIKINAME - All of the letters are uppercase, so this is not a WikiName
35
+ WikiNAME - All of the letters in NAME are uppercase, so this is not a WikiName
36
+ fooWikiName - This begins with "foo", which is in all lowercase, so this is not a WikiName
37
+ ```
38
+
39
+ * Example output
40
+
41
+ <ul>
42
+ <li><ul>
43
+ <li><a href="WikiName">WikiName</a> - <a href="WikiName">WikiName</a></li>
44
+ <li><a href="HogeRule1">HogeRule1</a> - <a href="WikiName">WikiName</a></li>
45
+ <li>NOTWIKINAME - All of the letters are uppercase, so this is not a <a href="WikiName">WikiName</a></li>
46
+ <li>WikiNAME - All of the letters in NAME are uppercase, so this is not a <a href="WikiName">WikiName</a></li>
47
+ <li>fooWikiName - This begins with "foo", which is in all lowercase, so this is not a <a href="WikiName">WikiName</a></li>
48
+ </ul></li>
49
+ </ul>
50
+
51
+ You can disable an auto [WikiName](WikiName) link by putting _^_ to the [WikiName](WikiName).
52
+
53
+ * Example statement
54
+
55
+ ```
56
+ WikiName - WikiName
57
+ ^WikiName - Disable WikiName link
58
+ ```
59
+
60
+ * Example output
61
+
62
+ <ul>
63
+ <li><ul>
64
+ <li><a href="WikiName">WikiName</a> - <a href="WikiName">WikiName</a></li>
65
+ <li>WikiName - Disable <a href="WikiName">WikiName</a> link</li>
66
+ </ul></li>
67
+ </ul>
68
+
69
+ ## Linking to other Wiki pages
70
+
71
+ If a page name is surrounded with two pairs of brackets, it becomes a link to that page.
72
+
73
+ * Example statement
74
+
75
+ ```
76
+ For example, if you write [[TextFormattingRules]], it becomes a link to that page.
77
+ ```
78
+
79
+ * Example output
80
+
81
+ <p>For example, if you write <a href="TextFormattingRules">TextFormattingRules</a>, it becomes a link to that page.</p>
82
+
83
+ ## Linking to an arbitrary URL
84
+
85
+ If a phrase and URL, separated by a vertical line, are surrounded with two pairs of brackets, it becomes a link to an arbitrary URL.
86
+
87
+ * Example statement
88
+
89
+ ```
90
+ Links like [[Yahoo!|http://www.yahoo.com/]] are also possible.
91
+ ```
92
+
93
+ * Example output
94
+
95
+ <p>Links like <a href="http://www.yahoo.com/">Yahoo!</a> are also possible.</p>
96
+
97
+ Text in a paragraph that looks like a URL will automatically become a link.
98
+
99
+ * Example statement
100
+
101
+ ```
102
+ Hiki's home page is http://hikiwiki.org/en/ (English).
103
+ ```
104
+
105
+ * Example output
106
+
107
+ <p>Hiki's home page is <a href="http://hikiwiki.org/en/">http://hikiwiki.org/en/</a> (English).</p>
108
+
109
+ In this case, if the URL ends with jpg., .jpeg, .png, or .gif, the image is displayed on the page.
110
+
111
+ * Example statement
112
+
113
+ ```
114
+ http://jp.rubyist.net/theme/clover/clover_h1.png
115
+ ```
116
+
117
+ * Example output
118
+
119
+ <p><img src="http://jp.rubyist.net/theme/clover/clover_h1.png" alt="clover_h1.png"></p>
120
+
121
+ #Preformatted text
122
+
123
+ Lines beginning with spaces or tabs will be treated as preformatted text.
124
+
125
+ * Example output
126
+
127
+ <pre>require 'cgi'
128
+
129
+ cgi = CGI::new
130
+ cgi.header
131
+
132
+ puts &lt;&lt;EOS
133
+ &lt;html&gt;
134
+ &lt;head&gt;
135
+ &lt;title&gt;Hello!&lt;/title&gt;
136
+ &lt;/head&gt;
137
+ &lt;body&gt;
138
+ &lt;p&gt;Hello!&lt;/p&gt;
139
+ &lt;/body&gt;
140
+ &lt;/html&gt;
141
+ EOS</pre>
142
+
143
+ # Text decoration
144
+
145
+ Text surrounded by sets of two single quotes ('') is emphasised.
146
+
147
+ Text surrounded by sets of three single quotes (''') is strongly emphasised.
148
+
149
+ Text surrounded by sets of double equal signs (===) is struck out.
150
+
151
+ Text surrounded by sets of double backquotes (``) is inline literal.
152
+
153
+ * Example statement
154
+
155
+ ```
156
+ If you write like this, it becomes ''emphasised''.
157
+ And if you write like this, it becomes '''strongly emphasised'''.
158
+ ==This is dull, but== And struck-out text is supported, too!
159
+ If you write like this, it becomes ``monospaced text``.
160
+ ```
161
+
162
+ * Example output
163
+
164
+ <p>If you write like this, it becomes <em>emphasised</em>.
165
+ And if you write like this, it becomes <strong>strongly emphasised</strong>.
166
+ <del>This is dull, but</del> And struck-out text is supported, too!
167
+ If you write like this, it becomes <tt>monospaced text</tt>.</p>
168
+
169
+ # Headings
170
+
171
+ Lines with exclamation marks at the beginning become headings.
172
+
173
+ One can use up to six exclamation marks; they will be converted to \<h1\> to \<h6\> tags.
174
+
175
+ * Example statement
176
+
177
+ ```
178
+ !Heading1
179
+ !!Heading2
180
+ !!!Heading3
181
+ !!!!Heading4
182
+ !!!!!Heading5
183
+ ```
184
+
185
+ * Example output
186
+
187
+ <h1>Heading1</h1>
188
+ <h2>Heading2</h2>
189
+ <h3>Heading3</h3>
190
+ <h4>Heading4</h4>
191
+ <h5>Heading5</h5>
192
+
193
+ # Horizontal lines
194
+
195
+ Four hyphens at the beginning of the line (----) become a horizontal rule.
196
+
197
+ * Example statement
198
+
199
+ ```
200
+ A B C D E
201
+ ----
202
+ F G H I J
203
+ ```
204
+
205
+ * Example output
206
+
207
+ <p>A B C D E</p>
208
+ <hr>
209
+ <p>F G H I J</p>
210
+
211
+ # Lists
212
+
213
+ Lines beginning with asterisks become list items.
214
+
215
+ It is possible to use up to three asterisks; it is also possible to create nested lists.
216
+
217
+ Lines beginning with a # become numbered lists.
218
+
219
+ * Example statement
220
+
221
+ ```
222
+ *Item 1
223
+ **Item 1.1
224
+ **Item 1.2
225
+ ***Item 1.2.1
226
+ ***Item 1.2.2
227
+ ***Item 1.2.3
228
+ **Item 1.3
229
+ **Item 1.4
230
+ *Item 2
231
+ ```
232
+
233
+ ```
234
+ #Item 1
235
+ #Item 2
236
+ ##Item 2.1
237
+ ##Item 2.2
238
+ ##Item 2.3
239
+ #Item 3
240
+ ##Item 3.1
241
+ ###Item 3.1.1
242
+ ###Item 3.1.2
243
+ ```
244
+
245
+ * Example output
246
+
247
+ <ul>
248
+ <li>Item 1<ul>
249
+ <li>Item 1.1</li>
250
+ <li>Item 1.2<ul>
251
+ <li>Item 1.2.1</li>
252
+ <li>Item 1.2.2</li>
253
+ <li>Item 1.2.3</li>
254
+ </ul></li>
255
+ <li>Item 1.3</li>
256
+ <li>Item 1.4</li>
257
+ </ul></li>
258
+ <li>Item 2</li>
259
+ </ul>
260
+ <ol>
261
+ <li>Item 1</li>
262
+ <li>Item 2<ol>
263
+ <li>Item 2.1</li>
264
+ <li>Item 2.2</li>
265
+ <li>Item 2.3</li>
266
+ </ol></li>
267
+ <li>Item 3<ol>
268
+ <li>Item 3.1<ol>
269
+ <li>Item 3.1.1</li>
270
+ <li>Item 3.1.2</li>
271
+ </ol></li>
272
+ </ol></li>
273
+ </ol>
274
+
275
+ # Quotations
276
+
277
+ Lines beginning with two double quotes become quotations.
278
+
279
+ * Example statement
280
+
281
+ ```
282
+ ""This is a quotation.
283
+ ""This is another quote.
284
+ ""This is a continued quote. When there are consecutive quotations,
285
+ ""they are displayed as one quote,
286
+ ""like this.
287
+ ```
288
+
289
+ * Example output
290
+
291
+ <blockquote><p>This is a quotation.
292
+ This is another quote.
293
+ This is a continued quote. When there are consecutive quotations,
294
+ they are displayed as one quote,
295
+ like this.</p>
296
+ </blockquote>
297
+
298
+ # Definitions
299
+
300
+ Lines beginning with a colon and have a phrase and explanation separated by another colon will become a definition.
301
+
302
+ * Example statement
303
+
304
+ ```
305
+ :ringo:apple
306
+ :gorira:gorilla
307
+ :rakuda:camel
308
+ ```
309
+
310
+ * Example output
311
+
312
+ <dl>
313
+ <dt>ringo</dt>
314
+ <dd>apple
315
+ </dd>
316
+ <dt>gorira</dt>
317
+ <dd>gorilla
318
+ </dd>
319
+ <dt>rakuda</dt>
320
+ <dd>camel
321
+ </dd>
322
+ </dl>
323
+
324
+ # Tables
325
+
326
+ Tables begin with two vertical bars.
327
+
328
+ Leading `!' in a cell means that it is a heading cell.
329
+
330
+ To concatenate columns or rows, put `\>'(columns) or `^'(rows) at head of
331
+ the cell.
332
+
333
+ * Example statement
334
+
335
+ ```
336
+ ||!row heading \ column heading||!column A||!column B||!column C||!>column D-E (horizontal concatenation)
337
+ ||!row 1||A1||B1||^C1-C2 (vertical concatenation)||D1||E1
338
+ ||!row 2||A2||B2||^>D2-E2-D3-E3 (vertical and horizontal concatenation)
339
+ ||!row 3||>>A3-C3 (horizontal concatenation)
340
+ ```
341
+
342
+ * Example output
343
+
344
+ <table border="1">
345
+ <tr><th>row heading \ column heading</th><th>column A</th><th>column B</th><th>column C</th><th colspan="2">column D-E (horizontal concatenation)
346
+ </th></tr>
347
+ <tr><th>row 1</th><td>A1</td><td>B1</td><td rowspan="2">C1-C2 (vertical concatenation)</td><td>D1</td><td>E1
348
+ </td></tr>
349
+ <tr><th>row 2</th><td>A2</td><td>B2</td><td rowspan="2" colspan="2">D2-E2-D3-E3 (vertical and horizontal concatenation)
350
+ </td></tr>
351
+ <tr><th>row 3</th><td colspan="3">A3-C3 (horizontal concatenation)
352
+ </td></tr>
353
+ </table>
354
+
355
+ # Comments
356
+
357
+ Lines starting with `//' becomes a comment line.
358
+ Comment lines is not outputted.
359
+
360
+ * Example statement
361
+
362
+ ```
363
+ // This is a comment line.
364
+ ```
365
+
366
+ * Example output (not displayed)
367
+
368
+ #Plugins
369
+
370
+ One can use a plugin by surrounding text with two pairs of brackets.
371
+ Multiple lines parameter is supported.
372
+ When a line contains plugin only, it becomes a block plugin,
373
+ which is not surrounded by \<p\> ... \</p\>.
374
+
375
+ * Example statement
376
+
377
+ ```
378
+ {{recent(3)}}
379
+ ```
380
+
381
+ * Example statement of multiple lines
382
+
383
+ ```
384
+ {{pre('
385
+ ...
386
+ ')}}
387
+ ```
388
+
data/bin/hikidoc CHANGED
@@ -16,10 +16,14 @@ HTML_TEMPLATE = <<EOS
16
16
  </html>
17
17
  EOS
18
18
 
19
+ def usage
20
+ "Usage: #$0 [OPTIONS] FILE"
21
+ end
22
+
19
23
  options = {}
20
24
  format_options = {}
21
25
  ARGV.options do |opts|
22
- opts.banner = "Usage: #$0 [OPTIONS] FILE"
26
+ opts.banner = usage
23
27
 
24
28
  opts.on('-f', '--fragment',
25
29
  'Output HTML fragments only') do
@@ -42,7 +46,7 @@ when 0
42
46
  when 1
43
47
  title, text = ARGV[0], File.read(ARGV[0])
44
48
  else
45
- usage
49
+ abort ARGV.options.help
46
50
  end
47
51
 
48
52
  body = HikiDoc.to_html(text, format_options)
data/hikidoc.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.description = %q{'HikiDoc' is a text-to-HTML conversion tool for web writers.}
12
12
  spec.summary = %q{'HikiDoc' is a text-to-HTML conversion tool for web writers. HikiDoc allows you to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid HTML (or XHTML).}
13
13
  spec.homepage = "https://github.com/hiki/hikidoc"
14
- spec.license = "MIT"
14
+ spec.license = "BSD-3-clause"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "test-unit"
23
24
  end
data/lib/hikidoc.rb CHANGED
@@ -2,11 +2,11 @@
2
2
  # Copyright (c) 2005, Kazuhiko <kazuhiko@fdiary.net>
3
3
  # Copyright (c) 2007 Minero Aoki
4
4
  # All rights reserved.
5
- #
5
+ #
6
6
  # Redistribution and use in source and binary forms, with or without
7
7
  # modification, are permitted provided that the following conditions are
8
8
  # met:
9
- #
9
+ #
10
10
  # * Redistributions of source code must retain the above copyright
11
11
  # notice, this list of conditions and the following disclaimer.
12
12
  # * Redistributions in binary form must reproduce the above
@@ -16,7 +16,7 @@
16
16
  # * Neither the name of the HikiDoc nor the names of its
17
17
  # contributors may be used to endorse or promote products derived
18
18
  # from this software without specific prior written permission.
19
- #
19
+ #
20
20
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
21
  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
22
  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -38,7 +38,7 @@ rescue LoadError
38
38
  end
39
39
 
40
40
  class HikiDoc
41
- VERSION = "0.0.6" # FIXME
41
+ VERSION = "0.1.1"
42
42
 
43
43
  class Error < StandardError
44
44
  end
@@ -80,9 +80,9 @@ class HikiDoc
80
80
 
81
81
  def default_options
82
82
  {
83
- :allow_bracket_inline_image => true,
84
- :use_wiki_name => true,
85
- :use_not_wiki_name => true,
83
+ allow_bracket_inline_image: true,
84
+ use_wiki_name: true,
85
+ use_not_wiki_name: true,
86
86
  }
87
87
  end
88
88
 
@@ -96,13 +96,11 @@ class HikiDoc
96
96
 
97
97
  def escape_plugin_blocks(text)
98
98
  s = StringScanner.new(text)
99
- buf = ""
99
+ buf = +""
100
100
  @plugin_blocks = []
101
101
  while chunk = s.scan_until(/\{\{/)
102
- tail = chunk[-2, 2]
103
102
  chunk[-2, 2] = ""
104
103
  buf << chunk
105
- # plugin
106
104
  if block = extract_plugin_block(s)
107
105
  @plugin_blocks.push block
108
106
  buf << "\0#{@plugin_blocks.size - 1}\0"
@@ -138,7 +136,7 @@ class HikiDoc
138
136
 
139
137
  def extract_plugin_block(s)
140
138
  pos = s.pos
141
- buf = ""
139
+ buf = +""
142
140
  while chunk = s.scan_until(/\}\}/)
143
141
  buf << chunk
144
142
  buf.chomp!("}}")
@@ -402,22 +400,22 @@ class HikiDoc
402
400
  def compile_inline(str, buf = nil)
403
401
  buf ||= @output.container
404
402
  re = inline_syntax_re
405
- pending_str = nil
403
+ pending_str = ""
406
404
  while m = re.match(str)
407
405
  str = m.post_match
408
406
 
409
407
  link, uri, mod, wiki_name = m[1, 4]
410
- if wiki_name and wiki_name[0, 1] == "^"
411
- pending_str = m.pre_match + wiki_name[1..-1] + str
408
+ if wiki_name and wiki_name.start_with? "^"
409
+ pending_str += m.pre_match + wiki_name[1..-1]
412
410
  next
413
411
  end
414
412
 
415
413
  pre_str = "#{pending_str}#{m.pre_match}"
416
- pending_str = nil
414
+ pending_str = ""
417
415
  evaluate_plugin_block(pre_str, buf)
418
416
  compile_inline_markup(buf, link, uri, mod, wiki_name)
419
417
  end
420
- evaluate_plugin_block(pending_str || str, buf)
418
+ evaluate_plugin_block(pending_str + str, buf)
421
419
  buf
422
420
  end
423
421
 
@@ -567,7 +565,7 @@ class HikiDoc
567
565
  when :paragraph
568
566
  []
569
567
  else
570
- ""
568
+ +""
571
569
  end
572
570
  end
573
571
 
@@ -655,7 +653,7 @@ class HikiDoc
655
653
  end
656
654
 
657
655
  def tdattr(rs, cs)
658
- buf = ""
656
+ buf = +""
659
657
  buf << %Q( rowspan="#{rs}") if rs
660
658
  buf << %Q( colspan="#{cs}") if cs
661
659
  buf
data/test/hikidoc_test.rb CHANGED
@@ -61,7 +61,7 @@ class HikiDocTestCase < Test::Unit::TestCase
61
61
  assert_convert("<p>{{&lt;&lt;\"End\"\nfoo's bar\nEnd\n}}</p>\n",
62
62
  "{{<<\"End\"\nfoo's bar\nEnd\n}}")
63
63
 
64
- options = {:plugin_syntax => method(:custom_valid_plugin_syntax?)}
64
+ options = {plugin_syntax: method(:custom_valid_plugin_syntax?)}
65
65
  assert_convert(%Q|<div class="plugin">{{&lt;&lt;"End"\nfoo's bar\nEnd\n}}</div>\n|,
66
66
  %Q!{{<<"End"\nfoo's bar\nEnd\n}}!,
67
67
  options)
@@ -291,16 +291,24 @@ TEST}}
291
291
  "^WikiName")
292
292
  assert_convert("<p>^<a href=\"WikiName\">WikiName</a></p>\n",
293
293
  "^WikiName",
294
- :use_not_wiki_name => false)
294
+ use_not_wiki_name: false)
295
295
  assert_convert("<p>^WikiName</p>\n",
296
296
  "^WikiName",
297
- :use_wiki_name => false)
297
+ use_wiki_name: false)
298
298
  assert_convert("<p>^WikiName</p>\n",
299
299
  "^WikiName",
300
- :use_wiki_name => false,
301
- :use_not_wiki_name => false)
300
+ use_wiki_name: false,
301
+ use_not_wiki_name: false)
302
302
  assert_convert("<p>foo WikiName bar</p>\n",
303
303
  "foo ^WikiName bar")
304
+ assert_convert("<p>WikiName - Disable <a href=\"WikiName\">WikiName</a> link</p>\n",
305
+ "^WikiName - Disable WikiName link")
306
+ assert_convert("<p><a href=\"WikiName\">WikiName</a> - Disable DisabledWikiName link</p>\n",
307
+ "WikiName - Disable ^DisabledWikiName link")
308
+ assert_convert("<p><a href=\"WikiName\">WikiName</a> - Disable <a href=\"WikiName\">WikiName</a> link</p>\n",
309
+ "WikiName - Disable WikiName link")
310
+ assert_convert("<p>DisabledWikiName - Disable DisabledWikiName link</p>\n",
311
+ "^DisabledWikiName - Disable ^DisabledWikiName link")
304
312
  end
305
313
 
306
314
  def test_use_wiki_name_option
@@ -308,7 +316,7 @@ TEST}}
308
316
  "WikiName")
309
317
  assert_convert("<p>WikiName</p>\n",
310
318
  "WikiName",
311
- :use_wiki_name => false)
319
+ use_wiki_name: false)
312
320
  end
313
321
 
314
322
  def test_image_link
@@ -316,13 +324,13 @@ TEST}}
316
324
  "[[http://hikiwiki.org/img.png]]")
317
325
  assert_convert(%Q|<p><a href="http://hikiwiki.org/img.png">http://hikiwiki.org/img.png</a></p>\n|,
318
326
  "[[http://hikiwiki.org/img.png]]",
319
- :allow_bracket_inline_image => false)
327
+ allow_bracket_inline_image: false)
320
328
 
321
329
  assert_convert(%Q|<p><img src="http://hikiwiki.org/img.png" alt="img" /></p>\n|,
322
330
  "[[img|http://hikiwiki.org/img.png]]")
323
331
  assert_convert(%Q|<p><a href="http://hikiwiki.org/img.png">img</a></p>\n|,
324
332
  "[[img|http://hikiwiki.org/img.png]]",
325
- :allow_bracket_inline_image => false)
333
+ allow_bracket_inline_image: false)
326
334
  end
327
335
 
328
336
  def test_definition