md_edit 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/md_edit.rb +20 -12
- data.tar.gz.sig +1 -3
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 546abacabfcd21d682abb75886ec1d7c3b51f7d7
|
4
|
+
data.tar.gz: 4c7e4d6c504182140095af692cba1fded5f8da82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3f7c3d5cd4a7c529784d253ba1c69f08266d38cfb1f3eaaa16112e5f7f93227d004e94911e56b165d85a18e926b417a885d5decff3b73a4e9477a4b3bf7a276
|
7
|
+
data.tar.gz: 2cdb3fbc4f67e924bae4552178fbf911c7d897aee9ed2dfd0d4537a8dccaec6704140e4db139afb0d922806985d9707dba3a861563584333ab9e97510663124d
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/md_edit.rb
CHANGED
@@ -11,7 +11,7 @@ class MdEdit
|
|
11
11
|
|
12
12
|
attr_reader :sections
|
13
13
|
|
14
|
-
# pass in
|
14
|
+
# pass in a Markdown document or a Markdown filename
|
15
15
|
#
|
16
16
|
def initialize(md, debug: false)
|
17
17
|
|
@@ -57,6 +57,8 @@ class MdEdit
|
|
57
57
|
:deleted
|
58
58
|
end
|
59
59
|
|
60
|
+
# update a section by heading title e.g. ## To-do\n\n[ ] Vacuum the bedroom
|
61
|
+
#
|
60
62
|
def update(raw_value, heading: nil )
|
61
63
|
|
62
64
|
value = raw_value.gsub(/\r/,'')
|
@@ -70,7 +72,7 @@ class MdEdit
|
|
70
72
|
old_section = value =~ /^#+/ ? key + old_value : old_value
|
71
73
|
puts 'old_section: ' + old_section.inspect if @debug
|
72
74
|
|
73
|
-
@s.sub!(old_section, value
|
75
|
+
@s.sub!(old_section, value)
|
74
76
|
puts '@s: ' + @s.inspect if @debug
|
75
77
|
load_sections(@s)
|
76
78
|
|
@@ -117,26 +119,27 @@ class MdEdit
|
|
117
119
|
end
|
118
120
|
|
119
121
|
@pl = PhraseLookup.new @h
|
120
|
-
@s = s
|
122
|
+
@s = s
|
121
123
|
|
122
124
|
end
|
123
125
|
|
124
126
|
def parse(s)
|
125
|
-
|
126
|
-
a = s.split(/(
|
127
|
+
|
128
|
+
a = s.split(/(?<=\n)(?=#+)/)
|
127
129
|
|
128
130
|
a2 = a.map.with_index do |x, i|
|
129
131
|
|
130
132
|
# get the indentation level
|
131
133
|
indent = x[/^#+/].count('#') - 1
|
132
134
|
|
133
|
-
lines = x.
|
135
|
+
lines = x.lines
|
134
136
|
lines.first.prepend(' ' * indent) +
|
135
137
|
lines[1..-1].map {|y| (' ' * indent) + ' ' + y}.join
|
136
138
|
end
|
137
139
|
|
140
|
+
puts "a2.join: \n" + a2.join if @debug
|
138
141
|
a3 = LineTree.new(a2.join, ignore_blank_lines: false, ignore_newline: false).to_a
|
139
|
-
|
142
|
+
puts 'a3: ' + a3.inspect if @debug
|
140
143
|
h = {}
|
141
144
|
a4 = scan a3, h
|
142
145
|
|
@@ -149,22 +152,27 @@ class MdEdit
|
|
149
152
|
end
|
150
153
|
|
151
154
|
def scan(a, h={})
|
152
|
-
|
155
|
+
|
153
156
|
a.map do |x|
|
154
157
|
|
155
|
-
head = x.
|
158
|
+
head = x.first
|
156
159
|
|
157
|
-
if head =~
|
158
|
-
|
160
|
+
if head =~ /^#/ then
|
161
|
+
|
159
162
|
r = scan(x[1..-1], h)
|
160
|
-
|
163
|
+
|
164
|
+
h[head[/^[^\n]+/]] = ["\n"] + r
|
165
|
+
|
161
166
|
[head, r]
|
162
167
|
|
168
|
+
elsif x.length > 1
|
169
|
+
[head] + scan(x[1..-1])
|
163
170
|
else
|
164
171
|
x.flatten.join
|
165
172
|
end
|
166
173
|
|
167
174
|
end
|
175
|
+
|
168
176
|
end
|
169
177
|
|
170
178
|
end
|
data.tar.gz.sig
CHANGED
@@ -1,3 +1 @@
|
|
1
|
-
}
|
2
|
-
A�߃�����&;;f �q��1V�cC`���]���kò*�5Y��/�G-s�������1����K��sC�qM�ݻ���WYi�55"�E~�0���s�de�b�=
|
3
|
-
/ݛTg3j�����9_U
|
1
|
+
?4�Q��lt�)�t0�u�5���}����Q��t�KeIs�0_�4���45���0�� �]t3����Ķ�།÷�i�2����y�@RӃܘ�`�-����M��a[i����)7���}:���f~���Ӂ�yfI�b��.w�'�G��� SIn��lAG@j�E[� hd/G��?�d�v�9�����|�ҙ�vBJ� ��-�ҙ���l���j��d[�$m�lo�?ĸ���P�I�e
|
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.
|
4
|
+
version: 0.1.9
|
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-
|
34
|
+
date: 2017-12-24 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: line-tree
|
metadata.gz.sig
CHANGED
Binary file
|