pseudohikiparser 0.0.0.5.develop → 0.0.0.6.develop

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0cd301fcbf579cecea32ac473e1bffd351cb9e21
4
+ data.tar.gz: 5871802bd7b9dc0e71df8f3a5c4805339caf1833
5
+ SHA512:
6
+ metadata.gz: 411eeb634503a5f79d9f563ddcfcfa45140e2889c78463a494275d044c3fb7bbbaa50591a9a27d61604bda7adaf8e5ff43cdacd1b52c7b10bda672729b98d394
7
+ data.tar.gz: 9d58afc0b126a74e1b2ba1e9fc32efff8262a1a248e98037cb0c18371144bc3420bfd5b72a58d4a219dbcb48ff61653dca0b4a4abfb194bbe974fccd0c9be303
@@ -17,8 +17,8 @@ class HtmlTemplate
17
17
  @content_language = create_meta("Content-Language", language)
18
18
  @base = set_path_to_base(base_uri)
19
19
  @content_type = set_charset_in_meta(charset)
20
- @content_style_type = create_meta("Content-Style-Type","text/css")
21
- @content_script_type = create_meta("Content-Script-Type","text/javascript")
20
+ @content_style_type = create_meta("Content-Style-Type", "text/css")
21
+ @content_script_type = create_meta("Content-Script-Type", "text/javascript")
22
22
  @default_css_link = create_css_link(css_link)
23
23
  @title = nil
24
24
  @title_element = create_element("title")
@@ -105,7 +105,7 @@ class HtmlTemplate
105
105
 
106
106
  private
107
107
 
108
- def create_meta(type,content)
108
+ def create_meta(type, content)
109
109
  create_element("meta", nil,
110
110
  "http-equiv" => type,
111
111
  "content" => content)
@@ -119,7 +119,7 @@ class HtmlTemplate
119
119
  end
120
120
 
121
121
  def set_charset_in_meta(charset)
122
- create_meta("Content-Type",META_CHARSET%[charset])
122
+ create_meta("Content-Type", META_CHARSET%[charset])
123
123
  end
124
124
 
125
125
  def set_path_to_base(base_uri)
@@ -183,33 +183,19 @@ module PseudoHiki
183
183
  end
184
184
 
185
185
  module BlockElement
186
- class DescLeaf < BlockLeaf; end
187
- class VerbatimLeaf < BlockLeaf; end
188
- class QuoteLeaf < NonNestedBlockLeaf; end
189
- class TableLeaf < BlockLeaf; end
190
- class CommentOutLeaf < BlockLeaf; end
191
- class HeadingLeaf < NestedBlockLeaf; end
192
- class ParagraphLeaf < NonNestedBlockLeaf; end
193
- class HrLeaf < BlockLeaf; end
194
- class BlockNodeEnd < BlockLeaf; end
195
-
196
- class ListLeaf < ListTypeLeaf; end
197
- class EnumLeaf < ListTypeLeaf; end
198
-
199
- class DescNode < BlockNode; end
200
- class VerbatimNode < BlockNode; end
201
- class QuoteNode < NonNestedBlockNode; end
202
- class TableNode < BlockNode; end
203
- class CommentOutNode < BlockNode; end
204
- class HeadingNode < NestedBlockNode; end
205
- class ParagraphNode < NonNestedBlockNode; end
206
- class HrNode < BlockNode; end
207
-
208
- class ListNode < ListTypeBlockNode; end
209
- class EnumNode < ListTypeBlockNode; end
210
-
211
- class ListWrapNode < ListLeafNode; end
212
- class EnumWrapNode < ListLeafNode; end
186
+ {
187
+ BlockLeaf => %w(DescLeaf VerbatimLeaf TableLeaf CommentOutLeaf BlockNodeEnd HrLeaf),
188
+ NonNestedBlockLeaf => %w(QuoteLeaf ParagraphLeaf),
189
+ NestedBlockLeaf => %w(HeadingLeaf),
190
+ ListTypeLeaf => %w(ListLeaf EnumLeaf),
191
+ BlockNode => %w(DescNode VerbatimNode TableNode CommentOutNode HrNode),
192
+ NonNestedBlockNode => %w(QuoteNode ParagraphNode),
193
+ NestedBlockNode => %w(HeadingNode),
194
+ ListTypeBlockNode => %w(ListNode EnumNode),
195
+ ListLeafNode => %w(ListWrapNode EnumWrapNode)
196
+ }.each do |parent_class, children|
197
+ PseudoHiki.subclass_of(parent_class, binding, children)
198
+ end
213
199
  end
214
200
  include BlockElement
215
201
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'pseudohiki/inlineparser'
4
4
  require 'pseudohiki/blockparser'
5
+ require 'htmlelement'
5
6
 
6
7
  module PseudoHiki
7
8
  class HtmlFormat
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'pseudohiki/treestack'
4
- require 'htmlelement'
5
4
 
6
5
  module PseudoHiki
7
6
  PROTOCOL = /^((https?|file|ftp):|\.?\/)/
@@ -10,6 +9,10 @@ module PseudoHiki
10
9
  FILE_MARK = "file:///"
11
10
  ImageSuffix = /\.(jpg|jpeg|gif|png|bmp)$/io
12
11
 
12
+ def self.subclass_of(parent_class, bound_env, subclass_names)
13
+ subclass_names. each {|name| eval "class #{name} < #{parent_class}; end", bound_env }
14
+ end
15
+
13
16
  def self.compile_token_pat(*token_sets)
14
17
  tokens = token_sets.flatten.uniq.sort do |x,y|
15
18
  [y.length, y] <=> [x.length, x]
@@ -23,12 +26,8 @@ module PseudoHiki
23
26
  class InlineLeaf < InlineParser::Leaf; end
24
27
  # class LinkSepLeaf < InlineLeaf; end
25
28
 
26
- class LinkNode < InlineNode; end
27
- class EmNode < InlineNode; end
28
- class StrongNode < InlineNode; end
29
- class DelNode < InlineNode; end
30
- class PlainNode < InlineNode; end
31
- class PluginNode < InlineNode; end
29
+ PseudoHiki.subclass_of(InlineNode, binding,
30
+ %w(LinkNode EmNode StrongNode DelNode PlainNode PluginNode))
32
31
 
33
32
  LinkSep, TableSep, DescSep = %w(| || :)
34
33
  end
@@ -125,6 +124,7 @@ module PseudoHiki
125
124
  class InlineElement::TableCellNode
126
125
  def parse_first_token(token)
127
126
  @cell_type, @rowspan, @colspan, parsed_token = TD, 1, 1, token.dup
127
+ return token if token.kind_of? InlineParser::InlineNode
128
128
  token_str = parsed_token[0]
129
129
  m = MODIFIED_CELL_PAT.match(token_str) #if token.kind_of? String
130
130
 
@@ -12,9 +12,7 @@ module PseudoHiki
12
12
  DescSep = [InlineParser::DescSep]
13
13
 
14
14
  class Node < Array
15
- def to_s
16
- self.join("")
17
- end
15
+ alias to_s join
18
16
  end
19
17
 
20
18
  def create_self_element(tree=nil)
@@ -95,14 +93,14 @@ module PseudoHiki
95
93
 
96
94
  def format(tree)
97
95
  formatter = get_plain
98
- tree.accept(formatter).join("")
96
+ tree.accept(formatter).join
99
97
  end
100
98
 
101
99
  ## Definitions of subclasses of PlainTextFormat begins here.
102
100
 
103
101
  class InlineLeafFormatter < self
104
102
  def visit(leaf)
105
- leaf.join("")
103
+ leaf.join
106
104
  end
107
105
  end
108
106
 
@@ -112,15 +110,15 @@ module PseudoHiki
112
110
  element = Node.new
113
111
  caption = get_caption(tree)
114
112
  begin
115
- ref = tree.last.join("")
113
+ ref = tree.last.join
116
114
  rescue NoMethodError
117
115
  raise NoMethodError unless tree.empty?
118
116
  STDERR.puts "No uri is specified for #{caption}"
119
117
  end
120
118
  if ImageSuffix =~ ref
121
- element.push (caption||tree).join("")
119
+ element.push (caption||tree).join
122
120
  else
123
- element.push caption||tree.join("")
121
+ element.push caption||tree.join
124
122
  element.push " (#{tree.join('')})" if @options.verbose_mode and caption
125
123
  end
126
124
  element
@@ -151,7 +149,7 @@ module PseudoHiki
151
149
  push_visited_results(element, tree.shift(dt_sep_index))
152
150
  tree.shift
153
151
  end
154
- dd = tree.map {|token| visited_result(token) }.join("").lstrip
152
+ dd = tree.map {|token| visited_result(token) }.join.lstrip
155
153
  unless dd.empty?
156
154
  element.push element.empty? ? "\t" : ":\t"
157
155
  element.push dd
@@ -162,7 +160,7 @@ module PseudoHiki
162
160
 
163
161
  class VerbatimNodeFormatter < self
164
162
  def visit(tree)
165
- tree.join("")
163
+ tree.join
166
164
  end
167
165
  end
168
166
 
@@ -195,7 +193,7 @@ ERROR_TEXT
195
193
  end
196
194
  end
197
195
  end
198
- table.map {|row| row.join("\t")+$/ }.join("")
196
+ table.map {|row| row.join("\t")+$/ }.join
199
197
  end
200
198
 
201
199
  def each_cell_with_index(table, max_row, max_col, initial_row=0, initial_col=0)
@@ -1,3 +1,3 @@
1
1
  module PseudoHiki
2
- VERSION = "0.0.0.5.develop"
2
+ VERSION = "0.0.0.6.develop"
3
3
  end
@@ -146,6 +146,45 @@ HTML
146
146
  assert_equal(html,convert_text_to_html(text))
147
147
  end
148
148
 
149
+ def test_table_with_link
150
+ text = <<TEXT
151
+ ||[[a link|http://www.example.org/]]||another cell
152
+ TEXT
153
+
154
+ html = <<HTML
155
+ <table>
156
+ <tr><td><a href="http://www.example.org/">a link</a></td><td>another cell</td></tr>
157
+ </table>
158
+ HTML
159
+ assert_equal(html,convert_text_to_html(text))
160
+ end
161
+
162
+ def test_table_with_emphasis
163
+ text = <<TEXT
164
+ ||''put'' emphasis on the first word||another cell
165
+ TEXT
166
+
167
+ html = <<HTML
168
+ <table>
169
+ <tr><td><em>put</em> emphasis on the first word</td><td>another cell</td></tr>
170
+ </table>
171
+ HTML
172
+ assert_equal(html,convert_text_to_html(text))
173
+ end
174
+
175
+ def test_table_with_strong
176
+ text = <<TEXT
177
+ ||'''strong''' is used for the first word.||another cell
178
+ TEXT
179
+
180
+ html = <<HTML
181
+ <table>
182
+ <tr><td><strong>strong</strong> is used for the first word.</td><td>another cell</td></tr>
183
+ </table>
184
+ HTML
185
+ assert_equal(html,convert_text_to_html(text))
186
+ end
187
+
149
188
  def test_hr
150
189
  text = <<TEXT
151
190
  paragraph
metadata CHANGED
@@ -1,46 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pseudohikiparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.5.develop
5
- prerelease: 8
4
+ version: 0.0.0.6.develop
6
5
  platform: ruby
7
6
  authors:
8
7
  - HASHIMOTO, Naoki
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-10-19 00:00:00.000000000 Z
11
+ date: 2013-12-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.3'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.3'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  description: PseudoHikiParser is a parser of texts written in a Hiki like notation,
@@ -52,52 +47,51 @@ executables:
52
47
  extensions: []
53
48
  extra_rdoc_files: []
54
49
  files:
55
- - README.md
56
50
  - LICENSE
57
- - lib/pseudohikiparser.rb
58
- - lib/pseudohiki/treestack.rb
59
- - lib/pseudohiki/inlineparser.rb
51
+ - README.md
52
+ - bin/pseudohiki2html.rb
53
+ - lib/htmlelement.rb
54
+ - lib/htmlelement/htmltemplate.rb
60
55
  - lib/pseudohiki/blockparser.rb
61
56
  - lib/pseudohiki/htmlformat.rb
57
+ - lib/pseudohiki/htmlplugin.rb
58
+ - lib/pseudohiki/inlineparser.rb
62
59
  - lib/pseudohiki/plaintextformat.rb
60
+ - lib/pseudohiki/treestack.rb
63
61
  - lib/pseudohiki/version.rb
64
- - lib/pseudohiki/htmlplugin.rb
65
- - lib/htmlelement.rb
66
- - lib/htmlelement/htmltemplate.rb
67
- - test/test_htmltemplate.rb
62
+ - lib/pseudohikiparser.rb
68
63
  - test/test_blockparser.rb
69
- - test/test_plaintextformat.rb
70
64
  - test/test_htmlelement.rb
71
- - test/test_treestack.rb
72
- - test/test_inlineparser.rb
73
65
  - test/test_htmlformat.rb
74
66
  - test/test_htmlplugin.rb
75
- - bin/pseudohiki2html.rb
67
+ - test/test_htmltemplate.rb
68
+ - test/test_inlineparser.rb
69
+ - test/test_plaintextformat.rb
70
+ - test/test_treestack.rb
76
71
  homepage: https://github.com/nico-hn/PseudoHikiParser/wiki
77
72
  licenses:
78
73
  - BSD 2-Clause license
74
+ metadata: {}
79
75
  post_install_message:
80
76
  rdoc_options: []
81
77
  require_paths:
82
78
  - lib
83
79
  required_ruby_version: !ruby/object:Gem::Requirement
84
- none: false
85
80
  requirements:
86
- - - ! '>='
81
+ - - ">="
87
82
  - !ruby/object:Gem::Version
88
83
  version: 1.8.7
89
84
  required_rubygems_version: !ruby/object:Gem::Requirement
90
- none: false
91
85
  requirements:
92
- - - ! '>'
86
+ - - ">"
93
87
  - !ruby/object:Gem::Version
94
88
  version: 1.3.1
95
89
  requirements: []
96
90
  rubyforge_project:
97
- rubygems_version: 1.8.23
91
+ rubygems_version: 2.2.0
98
92
  signing_key:
99
- specification_version: 3
100
- summary: ! 'PseudoHikiParser: a parser of texts in a Hiki like notation.'
93
+ specification_version: 4
94
+ summary: 'PseudoHikiParser: a parser of texts in a Hiki like notation.'
101
95
  test_files:
102
96
  - test/test_htmltemplate.rb
103
97
  - test/test_blockparser.rb