d-mark 1.0.0a3 → 1.0.0a4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1542c550fe7394de16bd088b2b0adc7bc369419
4
- data.tar.gz: 6601aacc0e5d8c9b5aae40309b8802acef9652dc
3
+ metadata.gz: bd186ea6e5e8fb14c4c424b8a58793026a0a650b
4
+ data.tar.gz: cd847b7b9029f0098b3e10b3a7ba74f3b97aaad3
5
5
  SHA512:
6
- metadata.gz: f5775a149e72d08f1ca5f24b3a2fd9f1ce78084fc790d6aa562db07912d0d19d62de09b1e1c3ff66636465bcf657ffb063345ddb6fa52a5bbce3ac1e989a0a55
7
- data.tar.gz: c91e5b502cb9950561c257ba6f765d04d5b125c6f7ce965b336f843561a864050fcd217adb2b658b37f05c5ffbb70a56f8ca410159eabc72811f2639d34f5e1e
6
+ metadata.gz: 19198cab18de6924374fddeb55f0bec8e4db2e78b62caa7417ec9d6dec5189d9b5c275ab1bc58712fa39db00ef66993aa2e1b5c85cd10222492746655dff5d1f
7
+ data.tar.gz: 5256a0b8ac59bdf95891d4135a5ee2f6b9002e5bd5975aa1c9561f7def7a9453e90e00c007cbb4f14c45be2bf2f08e229ec0ed36602232e67ad67448fcbae631
@@ -6,19 +6,19 @@ PATH
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- ast (2.2.0)
10
- codecov (0.1.4)
9
+ ast (2.3.0)
10
+ codecov (0.1.10)
11
11
  json
12
12
  simplecov
13
13
  url
14
14
  coderay (1.1.1)
15
- diff-lcs (1.2.5)
15
+ diff-lcs (1.3)
16
16
  docile (1.1.5)
17
- ffi (1.9.10)
17
+ ffi (1.9.18)
18
18
  formatador (0.2.5)
19
- guard (2.13.0)
19
+ guard (2.14.1)
20
20
  formatador (>= 0.2.4)
21
- listen (>= 2.7, <= 4.0)
21
+ listen (>= 2.7, < 4.0)
22
22
  lumberjack (~> 1.0)
23
23
  nenv (~> 0.1)
24
24
  notiffany (~> 0.0)
@@ -28,57 +28,62 @@ GEM
28
28
  guard-rake (1.0.0)
29
29
  guard
30
30
  rake
31
- json (1.8.3)
32
- listen (3.0.6)
33
- rb-fsevent (>= 0.9.3)
34
- rb-inotify (>= 0.9.7)
35
- lumberjack (1.0.10)
31
+ json (2.1.0)
32
+ listen (3.1.5)
33
+ rb-fsevent (~> 0.9, >= 0.9.4)
34
+ rb-inotify (~> 0.9, >= 0.9.7)
35
+ ruby_dep (~> 1.2)
36
+ lumberjack (1.0.12)
36
37
  method_source (0.8.2)
37
38
  nenv (0.3.0)
38
- notiffany (0.0.8)
39
+ notiffany (0.1.1)
39
40
  nenv (~> 0.1)
40
41
  shellany (~> 0.0)
41
- parser (2.3.0.6)
42
+ parallel (1.12.0)
43
+ parser (2.4.0.0)
42
44
  ast (~> 2.2)
43
45
  powerpack (0.1.1)
44
- pry (0.10.3)
46
+ pry (0.10.4)
45
47
  coderay (~> 1.1.0)
46
48
  method_source (~> 0.8.1)
47
49
  slop (~> 3.4)
48
- rainbow (2.1.0)
49
- rake (11.1.0)
50
- rb-fsevent (0.9.7)
51
- rb-inotify (0.9.7)
52
- ffi (>= 0.5.0)
53
- rspec (3.4.0)
54
- rspec-core (~> 3.4.0)
55
- rspec-expectations (~> 3.4.0)
56
- rspec-mocks (~> 3.4.0)
57
- rspec-core (3.4.4)
58
- rspec-support (~> 3.4.0)
59
- rspec-expectations (3.4.0)
50
+ rainbow (2.2.2)
51
+ rake
52
+ rake (12.0.0)
53
+ rb-fsevent (0.10.2)
54
+ rb-inotify (0.9.10)
55
+ ffi (>= 0.5.0, < 2)
56
+ rspec (3.6.0)
57
+ rspec-core (~> 3.6.0)
58
+ rspec-expectations (~> 3.6.0)
59
+ rspec-mocks (~> 3.6.0)
60
+ rspec-core (3.6.0)
61
+ rspec-support (~> 3.6.0)
62
+ rspec-expectations (3.6.0)
60
63
  diff-lcs (>= 1.2.0, < 2.0)
61
- rspec-support (~> 3.4.0)
62
- rspec-mocks (3.4.1)
64
+ rspec-support (~> 3.6.0)
65
+ rspec-mocks (3.6.0)
63
66
  diff-lcs (>= 1.2.0, < 2.0)
64
- rspec-support (~> 3.4.0)
65
- rspec-support (3.4.1)
66
- rubocop (0.38.0)
67
- parser (>= 2.3.0.6, < 3.0)
67
+ rspec-support (~> 3.6.0)
68
+ rspec-support (3.6.0)
69
+ rubocop (0.49.1)
70
+ parallel (~> 1.10)
71
+ parser (>= 2.3.3.1, < 3.0)
68
72
  powerpack (~> 0.1)
69
73
  rainbow (>= 1.99.1, < 3.0)
70
74
  ruby-progressbar (~> 1.7)
71
75
  unicode-display_width (~> 1.0, >= 1.0.1)
72
- ruby-progressbar (1.7.5)
76
+ ruby-progressbar (1.8.1)
77
+ ruby_dep (1.5.0)
73
78
  shellany (0.0.1)
74
- simplecov (0.11.2)
79
+ simplecov (0.15.0)
75
80
  docile (~> 1.1.0)
76
- json (~> 1.8)
81
+ json (>= 1.8, < 3)
77
82
  simplecov-html (~> 0.10.0)
78
- simplecov-html (0.10.0)
83
+ simplecov-html (0.10.2)
79
84
  slop (3.6.0)
80
- thor (0.19.1)
81
- unicode-display_width (1.0.2)
85
+ thor (0.20.0)
86
+ unicode-display_width (1.3.0)
82
87
  url (0.3.2)
83
88
 
84
89
  PLATFORMS
@@ -94,4 +99,4 @@ DEPENDENCIES
94
99
  rubocop
95
100
 
96
101
  BUNDLED WITH
97
- 1.12.5
102
+ 1.15.3
data/NEWS.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # D★Mark news
2
2
 
3
+ ## 1.0.0a4 (2017-08-19)
4
+
5
+ Changes:
6
+
7
+ * Relaxed identifier restrictions (#16, #17)
8
+
9
+ Enhancements:
10
+
11
+ * Made various speed improvements
12
+
3
13
  ## 1.0.0a3 (2016-07-03)
4
14
 
5
15
  Changes:
data/Rakefile CHANGED
@@ -7,8 +7,8 @@ RSpec::Core::RakeTask.new(:spec) do |t|
7
7
  end
8
8
 
9
9
  RuboCop::RakeTask.new(:rubocop) do |task|
10
- task.options = %w( --display-cop-names --format simple )
11
- task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
10
+ task.options = %w[--display-cop-names --format simple]
11
+ task.patterns = ['lib/**/*.rb', 'spec/**/*.rb', 'Gemfile*', '*.gemspec', 'Rakefile']
12
12
  end
13
13
 
14
- task default: [:spec, :rubocop]
14
+ task default: %i[spec rubocop]
@@ -16,8 +16,8 @@ module DMark
16
16
  attr_reader :pos
17
17
 
18
18
  def initialize(input)
19
- @input = input
20
- @input_chars = @input.chars
19
+ @input_chars = input.chars
20
+ @length = @input_chars.size
21
21
 
22
22
  @pos = 0
23
23
  @col_nr = 0
@@ -48,20 +48,12 @@ module DMark
48
48
 
49
49
  ##########
50
50
 
51
- def peek_char(pos = @pos)
52
- if eof?
53
- nil
54
- else
55
- @input_chars[pos]
56
- end
57
- end
58
-
59
51
  def eof?(pos = @pos)
60
- pos >= @input_chars.size
52
+ pos >= @length
61
53
  end
62
54
 
63
55
  def advance
64
- if !eof? && @input_chars[@pos] == "\n"
56
+ if @input_chars[@pos] == "\n"
65
57
  @line_nr += 1
66
58
  @col_nr = 0
67
59
  end
@@ -71,7 +63,7 @@ module DMark
71
63
  end
72
64
 
73
65
  def read_char(c)
74
- char = peek_char
66
+ char = @input_chars[@pos]
75
67
  if char != c
76
68
  raise_parse_error("expected #{c.inspect}, but got #{char.nil? ? 'EOF' : char.inspect}")
77
69
  else
@@ -118,7 +110,7 @@ module DMark
118
110
  pos = @pos
119
111
 
120
112
  loop do
121
- case peek_char(pos)
113
+ case @input_chars[pos]
122
114
  when ' '
123
115
  pos += 1
124
116
  when nil
@@ -133,8 +125,8 @@ module DMark
133
125
 
134
126
  # FIXME: ugly and duplicated
135
127
  def try_read_block_start
136
- if peek_char == '#'
137
- next_char = peek_char(@pos + 1)
128
+ if @input_chars[@pos] == '#'
129
+ next_char = @input_chars[@pos + 1]
138
130
  ('a'..'z').cover?(next_char)
139
131
  else
140
132
  false
@@ -146,7 +138,7 @@ module DMark
146
138
  pos = @pos
147
139
 
148
140
  loop do
149
- case peek_char(pos)
141
+ case @input_chars[pos]
150
142
  when ' '
151
143
  pos += 1
152
144
  indentation_chars += 1
@@ -170,13 +162,13 @@ module DMark
170
162
  identifier = read_identifier
171
163
 
172
164
  attributes =
173
- if peek_char == '['
165
+ if @input_chars[@pos] == '['
174
166
  read_attributes
175
167
  else
176
168
  {}
177
169
  end
178
170
 
179
- case peek_char
171
+ case @input_chars[@pos]
180
172
  when nil, "\n"
181
173
  advance
182
174
  ElementNode.new(identifier, attributes, [])
@@ -189,7 +181,7 @@ module DMark
189
181
  end
190
182
 
191
183
  def read_end_of_inline_content
192
- char = peek_char
184
+ char = @input_chars[@pos]
193
185
  case char
194
186
  when "\n", nil
195
187
  advance
@@ -207,9 +199,9 @@ module DMark
207
199
  end
208
200
 
209
201
  def read_identifier_head
210
- char = peek_char
202
+ char = @input_chars[@pos]
211
203
  case char
212
- when 'a'..'z'
204
+ when 'a'..'z', 'A'..'Z'
213
205
  advance
214
206
  char
215
207
  else
@@ -217,18 +209,16 @@ module DMark
217
209
  end
218
210
  end
219
211
 
212
+ IDENTIFIER_CHARS = Set.new(['a'..'z', 'A'..'Z', ['-', '_'], '0'..'9'].map(&:to_a).flatten)
213
+
220
214
  def read_identifier_tail
221
215
  res = ''
222
216
 
223
217
  loop do
224
- char = peek_char
225
- case char
226
- when 'a'..'z', '-', '0'..'9'
227
- advance
228
- res << char
229
- else
230
- break
231
- end
218
+ char = @input_chars[@pos]
219
+ break unless IDENTIFIER_CHARS.include?(char)
220
+ advance
221
+ res << char
232
222
  end
233
223
 
234
224
  res.to_s
@@ -241,7 +231,7 @@ module DMark
241
231
 
242
232
  at_start = true
243
233
  loop do
244
- char = peek_char
234
+ char = @input_chars[@pos]
245
235
  case char
246
236
  when ']'
247
237
  advance
@@ -250,7 +240,7 @@ module DMark
250
240
  read_char(',') unless at_start
251
241
 
252
242
  key = read_attribute_key
253
- if peek_char == '='
243
+ if @input_chars[@pos] == '='
254
244
  read_char('=')
255
245
  value = read_attribute_value
256
246
  else
@@ -275,7 +265,7 @@ module DMark
275
265
 
276
266
  is_escaping = false
277
267
  loop do
278
- char = peek_char
268
+ char = @input_chars[@pos]
279
269
 
280
270
  if is_escaping
281
271
  case char
@@ -315,7 +305,7 @@ module DMark
315
305
  res = []
316
306
 
317
307
  loop do
318
- char = peek_char
308
+ char = @input_chars[@pos]
319
309
  case char
320
310
  when "\n", nil
321
311
  break
@@ -336,7 +326,7 @@ module DMark
336
326
  res = ''
337
327
 
338
328
  loop do
339
- char = peek_char
329
+ char = @input_chars[@pos]
340
330
  case char
341
331
  when nil, "\n", '%', '}'
342
332
  break
@@ -346,15 +336,15 @@ module DMark
346
336
  end
347
337
  end
348
338
 
349
- res.to_s
339
+ res
350
340
  end
351
341
 
352
342
  def read_percent_body
353
- char = peek_char
343
+ char = @input_chars[@pos]
354
344
  case char
355
345
  when '%', '}', '#'
356
346
  advance
357
- char.to_s
347
+ char
358
348
  when nil, "\n"
359
349
  raise_parse_error('expected something after %')
360
350
  else
@@ -365,7 +355,7 @@ module DMark
365
355
  def read_inline_element
366
356
  name = read_identifier
367
357
  attributes =
368
- if peek_char == '['
358
+ if @input_chars[@pos] == '['
369
359
  read_attributes
370
360
  else
371
361
  {}
@@ -1,3 +1,3 @@
1
1
  module DMark
2
- VERSION = '1.0.0a3'.freeze
2
+ VERSION = '1.0.0a4'.freeze
3
3
  end
@@ -15,6 +15,36 @@ describe 'DMark::Parser#parser' do
15
15
  expect(parse('#p hi %}')).to eq [element('p', {}, ['hi ', '}'])]
16
16
  end
17
17
 
18
+ it 'parses element with name containing dash' do
19
+ expect(parse('#intro-para hi')).to eq [
20
+ element('intro-para', {}, ['hi'])
21
+ ]
22
+ end
23
+
24
+ it 'parses element with name containing underscore' do
25
+ expect(parse('#intro_para hi')).to eq [
26
+ element('intro_para', {}, ['hi'])
27
+ ]
28
+ end
29
+
30
+ it 'parses element with name containing uppercase letters' do
31
+ expect(parse('#IntroPara hi')).to eq [
32
+ element('IntroPara', {}, ['hi'])
33
+ ]
34
+ end
35
+
36
+ it 'does not parse element with name starting with a dash' do
37
+ expect { parse('#-intro hi there') }.to raise_error(DMark::Parser::ParserError)
38
+ end
39
+
40
+ it 'does not parse element with name starting with an underscore' do
41
+ expect { parse('#_intro hi there') }.to raise_error(DMark::Parser::ParserError)
42
+ end
43
+
44
+ it 'does not parse element with name starting with a digit' do
45
+ expect { parse('#4ever best friends') }.to raise_error(DMark::Parser::ParserError)
46
+ end
47
+
18
48
  it 'parses escaped % in block' do
19
49
  expect(parse('#p %%')).to eq [
20
50
  element('p', {}, ['%'])
@@ -133,7 +163,7 @@ describe 'DMark::Parser#parser' do
133
163
 
134
164
  it 'includes raw content' do
135
165
  expect(parse("#p foo\n donkey")).to eq [
136
- element('p', {}, %W(foo \n donkey))
166
+ element('p', {}, %W[foo \n donkey])
137
167
  ]
138
168
  end
139
169
 
@@ -179,6 +209,42 @@ describe 'DMark::Parser#parser' do
179
209
  ]
180
210
  end
181
211
 
212
+ it 'parses attribute with dash' do
213
+ expect(parse('#p[intended-audience=learner] hi')).to eq [
214
+ element('p', { 'intended-audience' => 'learner' }, ['hi'])
215
+ ]
216
+ end
217
+
218
+ it 'parses attribute with numbers' do
219
+ expect(parse('#p[is-over-9000=yup] hi')).to eq [
220
+ element('p', { 'is-over-9000' => 'yup' }, ['hi'])
221
+ ]
222
+ end
223
+
224
+ it 'parses attribute with underscore' do
225
+ expect(parse('#p[intended_audience=learner] hi')).to eq [
226
+ element('p', { 'intended_audience' => 'learner' }, ['hi'])
227
+ ]
228
+ end
229
+
230
+ it 'parses attribute with uppercase letters' do
231
+ expect(parse('#p[IntendedAudience=learner] hi')).to eq [
232
+ element('p', { 'IntendedAudience' => 'learner' }, ['hi'])
233
+ ]
234
+ end
235
+
236
+ it 'does not parse atttributes starting with -' do
237
+ expect { parse('#p[-this=is dog] hello yes') }.to raise_error(DMark::Parser::ParserError)
238
+ end
239
+
240
+ it 'does not parse atttributes starting with _' do
241
+ expect { parse('#p[_this=is dog] hello yes') }.to raise_error(DMark::Parser::ParserError)
242
+ end
243
+
244
+ it 'does not parse atttributes starting with a digit' do
245
+ expect { parse('#p[4this=is dog] hello yes') }.to raise_error(DMark::Parser::ParserError)
246
+ end
247
+
182
248
  it 'parses single value-less attribute' do
183
249
  expect(parse('#p[foo] hi')).to eq [
184
250
  element('p', { 'foo' => 'foo' }, ['hi'])
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: d-mark
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0a3
4
+ version: 1.0.0a4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Defreyne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-03 00:00:00.000000000 Z
11
+ date: 2017-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,7 +53,6 @@ files:
53
53
  - lib/d-mark/parser.rb
54
54
  - lib/d-mark/translator.rb
55
55
  - lib/d-mark/version.rb
56
- - samples/test.rb
57
56
  - samples/trivial.dmark
58
57
  - samples/trivial.rb
59
58
  - spec/d-mark/element_node_spec.rb
@@ -82,9 +81,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
81
  version: 1.3.1
83
82
  requirements: []
84
83
  rubyforge_project:
85
- rubygems_version: 2.6.6
84
+ rubygems_version: 2.6.12
86
85
  signing_key:
87
86
  specification_version: 4
88
87
  summary: markup language for writing text
89
88
  test_files: []
90
- has_rdoc:
@@ -1,65 +0,0 @@
1
- require 'd-mark'
2
-
3
- module DMarkBook
4
- module Translators
5
- class HTML < DMark::Translator
6
- def handle_string(node)
7
- [html_escape(node)]
8
- end
9
-
10
- def handle_element(node, path)
11
- case node.name
12
- when 'p', 'dl', 'dt', 'dd', 'ol', 'ul', 'li', 'code', 'kbd', 'blockquote'
13
- wrap(node.name) { handle_children(node, path) }
14
- when 'h'
15
- depth = path.count { |node| node.name == 'section' } + 1
16
- wrap("h#{depth}") { handle_children(node, path) }
17
- when 'section'
18
- wrap('section', id: id_for_section(node)) { handle_children(node, path) }
19
- when 'em'
20
- wrap('em') { handle_children(node, path) }
21
- when 'link'
22
- wrap('a', href: node.attributes['target']) { handle_children(node, path) }
23
- when 'listing'
24
- wrap('pre') { wrap('code') { handle_children(node, path) } }
25
- else
26
- raise DMark::Translator::UnhandledNode.new(node)
27
- end
28
- end
29
-
30
- def wrap(name, params = {})
31
- params_string = params.map { |k, v| " #{k}=\"#{html_escape(v)}\"" }.join('')
32
- ["<#{name}#{params_string}>", yield, "</#{name}>"]
33
- end
34
-
35
- def html_escape(s)
36
- s.gsub('&', '&amp;').gsub('<', '&lt;')
37
- end
38
-
39
- def id_for_section(node)
40
- header = node.children.find { |c| c.name == 'h' }
41
- text = header.children.join('')
42
- text.downcase.gsub(/[^a-zA-Z-]/, '-')
43
- end
44
- end
45
- end
46
- end
47
-
48
- class SpecialHTML < DMarkBook::Translators::HTML
49
- def handle_element(node, depths)
50
- case node.name
51
- when 'firstterm', 'prompt', 'filename'
52
- wrap('span', class: node.name) { handle_children(node, depths) }
53
- when 'note', 'todo'
54
- wrap('div', class: node.name) { handle_children(node, depths) }
55
- else
56
- super
57
- end
58
- end
59
- end
60
-
61
- content = File.readlines('site/content/index.dmark').drop(4).join
62
- parser = DMark::Parser.new(content)
63
- tree = parser.parse
64
-
65
- puts SpecialHTML.new.translate(tree)