md_edit 0.1.7 → 0.1.8

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: 6ed6b33250079d8a899f4a70695b67e5296235b1
4
- data.tar.gz: db9e8a43942863088a36ac1d4a18836b17009426
3
+ metadata.gz: 7debd29ac658eca499f30c1f1128471a696120d4
4
+ data.tar.gz: fb74b5f245eac464562084d966e222a2f324ccbc
5
5
  SHA512:
6
- metadata.gz: 8fb40f29041a519f35e92e3e6293dc73c286c075fd8a1c72e54f354d28764705944b7ff8d316ce91619933878453883270233202ffdebaf111a90f52463b1c7a
7
- data.tar.gz: df17764df07161bccec2f49fd8e114c4e47570693865d12a03af5baa35aabba227ff3bf371c17dbd1d58df8617261a7bcaa034941292dd6c10de6ba5f28657cf
6
+ metadata.gz: ae23a23fbf24e3510e3584e0d875c816ec528128c4386bc409d5644ccfedece774eaae824264290c28fea40e1c3220a7b8424c3437973c36f6b5e8dc4d083697
7
+ data.tar.gz: e133f7c095239b7f4deaeed3ec454ac31c689a4342b938c53db72fb57ace9d300349a30cd49163950f2a3a958c6b6e8cee997292023069e3eb6add27b98a73a0
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/md_edit.rb CHANGED
@@ -13,7 +13,9 @@ class MdEdit
13
13
 
14
14
  # pass in an MD document
15
15
  #
16
- def initialize(md)
16
+ def initialize(md, debug: false)
17
+
18
+ @debug = debug
17
19
 
18
20
  s, @filename = if md.lines.length == 1 then
19
21
 
@@ -45,8 +47,8 @@ class MdEdit
45
47
  def delete(s)
46
48
 
47
49
  key = @sections.keys.grep(/#{s.downcase}/i).first
48
- old_value = @sections[key].flatten.join("\n\n")
49
- old_section = key + "\n\n" + old_value
50
+ old_value = @sections[key].flatten.join
51
+ old_section = key + old_value
50
52
 
51
53
  @s.sub!(old_section, '')
52
54
  load_sections(@s)
@@ -57,16 +59,19 @@ class MdEdit
57
59
 
58
60
  def update(raw_value, heading: nil )
59
61
 
60
- value = raw_value.gsub(/\r/,'') + "\n"
62
+ value = raw_value.gsub(/\r/,'')
61
63
 
62
64
  title = heading ? heading : value.lines.first.chomp
63
65
  key = @sections.keys.grep(/#{title.downcase}/i).first
64
66
  return unless key
65
67
 
66
- old_value = @sections[key].flatten.join("\n\n")
67
- old_section = value =~ /^#+/ ? key + "\n\n" + old_value : old_value
68
-
69
- @s.sub!(old_section, value)
68
+ old_value = @sections[key].flatten.join
69
+ puts 'old_value: ' + old_value.inspect if @debug
70
+ old_section = value =~ /^#+/ ? key + old_value : old_value
71
+ puts 'old_section: ' + old_section.inspect if @debug
72
+
73
+ @s.sub!(old_section, value + "\n")
74
+ puts '@s: ' + @s.inspect if @debug
70
75
  load_sections(@s)
71
76
 
72
77
  save()
@@ -80,8 +85,8 @@ class MdEdit
80
85
  def find(s, heading: true)
81
86
  key = @sections.keys.reverse.grep(/#{s.downcase}/i).first
82
87
  return unless key
83
- a = [key, @sections[key]]
84
- heading ? a.join("\n\n") : a
88
+ a = [key, @sections[key].join]
89
+ heading ? a.join : a
85
90
  end
86
91
 
87
92
  def query(s)
@@ -103,7 +108,7 @@ class MdEdit
103
108
  def load_sections(raw_s)
104
109
 
105
110
  # strip out any new lines gaps which are greater than 1
106
- s = raw_s.strip.gsub(/\n\s*\n\s*\n\s*/,"\n\n")
111
+ s = raw_s #.strip.gsub(/\n\s*\n\s*\n\s*/,"\n\n")
107
112
 
108
113
  @sections = parse s
109
114
 
@@ -127,14 +132,14 @@ class MdEdit
127
132
 
128
133
  lines = x.lstrip.lines
129
134
  lines.first.prepend(' ' * indent) +
130
- lines[1..-1].map {|y| (' ' * indent) + ' ' + y}.join + "\n"
135
+ lines[1..-1].map {|y| (' ' * indent) + ' ' + y}.join
131
136
  end
132
137
 
133
- a3 = LineTree.new(a2.join).to_a
138
+ a3 = LineTree.new(a2.join, ignore_blank_lines: false, ignore_newline: false).to_a
134
139
 
135
140
  h = {}
136
141
  a4 = scan a3, h
137
-
142
+
138
143
  return h
139
144
 
140
145
  end
@@ -147,16 +152,16 @@ class MdEdit
147
152
 
148
153
  a.map do |x|
149
154
 
150
- head = x.first
155
+ head = x.flatten.join[/^[^\n]+/]
151
156
 
152
157
  if head =~ /#/ then
153
158
 
154
159
  r = scan(x[1..-1], h)
155
- h[head] = r
160
+ h[head] = ["\n"] + r
156
161
  [head, r]
157
-
162
+
158
163
  else
159
- x.first
164
+ x.flatten.join
160
165
  end
161
166
 
162
167
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: md_edit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  R5r1JjTBaaHOaqI14bIkwUSY5q1cO4Wl7HWly80kX2AD8o/tPHvyF9Tx3pBvaboU
32
32
  etnSPHbQwmBvFQ==
33
33
  -----END CERTIFICATE-----
34
- date: 2017-12-21 00:00:00.000000000 Z
34
+ date: 2017-12-23 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: line-tree
@@ -39,20 +39,20 @@ dependencies:
39
39
  requirements:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: '0.5'
42
+ version: '0.6'
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- version: 0.5.8
45
+ version: 0.6.1
46
46
  type: :runtime
47
47
  prerelease: false
48
48
  version_requirements: !ruby/object:Gem::Requirement
49
49
  requirements:
50
50
  - - "~>"
51
51
  - !ruby/object:Gem::Version
52
- version: '0.5'
52
+ version: '0.6'
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
- version: 0.5.8
55
+ version: 0.6.1
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: phrase_lookup
58
58
  requirement: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
Binary file