md_edit 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e17870afaf691d4e7f6f2a2fb6e3340fd382a848
4
+ data.tar.gz: 79e95c3e0bd988c4978af7c62915f9de5a110ffa
5
+ SHA512:
6
+ metadata.gz: 57614c63add6c1c6a93dd55cea2b0c1c3a57acf2995798d9ff79c0d14cf5c780a298a263dc4a88d21d7997a5bccbd8084d5e05eb08ae4a4e556479ce7f4992af
7
+ data.tar.gz: 261c04f03622d0c7dc87538f29c0ae63e66e25c21d4dd8f828132eada03323d75b5b95ccbd1245430d31ba2f0d6398d83e2fa9fbf460d0577fe7025a70f6c289
checksums.yaml.gz.sig ADDED
Binary file
data/lib/md_edit.rb ADDED
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: md_edit.rb
4
+
5
+
6
+ require 'line-tree'
7
+ require 'phrase_lookup'
8
+
9
+
10
+ class MdEdit
11
+
12
+ # pass in an MD document
13
+ #
14
+ def initialize(s=nil)
15
+
16
+ if s then
17
+
18
+ parse s
19
+
20
+ h = @h.keys.inject({}) do |r,x|
21
+ r.merge(x.sub(/^#+ +/,'').downcase => 5 - x.count('#'))
22
+ end
23
+
24
+ @pl = PhraseLookup.new h
25
+
26
+ end
27
+ end
28
+
29
+ def find(s)
30
+ key = @h.keys.grep(/#{s.downcase}/i).first
31
+ [key, @h[key]]
32
+ end
33
+
34
+ def query(s)
35
+ @pl.q s
36
+ end
37
+
38
+ alias q query
39
+
40
+ def to_h()
41
+ @h
42
+ end
43
+
44
+ private
45
+
46
+ def parse(s)
47
+
48
+ a = s.split(/(?=\n#+)/)
49
+
50
+ a2 = a.map.with_index do |x, i|
51
+
52
+ # get the indentation level
53
+ indent = x[/^#+/].count('#') - 1
54
+
55
+ lines = x.lstrip.lines
56
+ lines.first.prepend(' ' * indent) +
57
+ lines[1..-1].map {|y| (' ' * indent) + ' ' + y}.join + "\n"
58
+ end
59
+
60
+ a3 = LineTree.new(a2.join).to_a
61
+
62
+ h = {}
63
+
64
+ a4 = scan a3, h
65
+ @h = h
66
+
67
+ end
68
+
69
+ def scan(a, h={})
70
+
71
+ a.map do |x|
72
+
73
+ head = x.first
74
+
75
+ if head =~ /#/ then
76
+
77
+ r = scan(x[1..-1], h)
78
+ h[head] = r
79
+ [head, r]
80
+
81
+ else
82
+ x.first
83
+ end
84
+
85
+ end
86
+ end
87
+
88
+ end
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: md_edit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
+ YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
+ 8ixkARkWAmV1MB4XDTE3MTIxNzA5MDczNFoXDTE4MTIxNzA5MDczNFowSDESMBAG
16
+ A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
+ EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
+ ggEBAOUD4NlZ0CdDuEgTdM/ILWpAPYtNdVhJXpz8PXr6W7eMwNlqB7iTkOiOZB8g
19
+ cufC/ArBS8u+hSvdx4Tcv3y0o8RF+zUZrOjX6RuKoh/zbGILMI+PTBH71NxsjlWy
20
+ Rlb1r7m2hIE+XphOEW5E5uQJfLYgIWc5dLi9nHgBEkE/vJohKSiiRxhL+vi7JvP9
21
+ 9m9hXECKilzIQjzc464GKHWR9DOfD/44+EO6mEwpo+UIUCQ7yKKJ3h3GMt00FVXX
22
+ 1oT4919KxwQfk6qh8U/22Z4bVbmVziCD4ZiyKlTUqPRJSx7g3R/GSV0ExtqUJ8O/
23
+ XwDptWhZiwjcs6kiSZ7GvUpoEuUCAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
24
+ DwQEAwIEsDAdBgNVHQ4EFgQUY0rljsYQ+iPK45W6C0RJlnD8dY0wJgYDVR0RBB8w
25
+ HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
26
+ c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEAbkqXZ36A
27
+ 6naCgnYg7TOsHIf1LvWxmuv0icC0hR3LZhSwbB1RcYuqOVU19LAeCN3WLa5lSGTp
28
+ +HBdtXXdVTWg7OEjRmolIe0XxBnX/i57FJy/59+ORZ9cylfg/1R0/hJHoeC+6q3H
29
+ ono8m7G/35K8iktdWDkST1OaTjrmjY0tgPdMfaBF4toTXkeLVH3RByIcCo339gER
30
+ M5ByW2f3zZ+bJMgO0fvtz1I+wHaSL/iFVZSnX96ul2ltQCmeWE7Sw72vBVecFVIk
31
+ R5r1JjTBaaHOaqI14bIkwUSY5q1cO4Wl7HWly80kX2AD8o/tPHvyF9Tx3pBvaboU
32
+ etnSPHbQwmBvFQ==
33
+ -----END CERTIFICATE-----
34
+ date: 2017-12-17 00:00:00.000000000 Z
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: line-tree
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '0.2'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 0.2.7
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '0.2'
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 0.2.7
56
+ - !ruby/object:Gem::Dependency
57
+ name: phrase_lookup
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '0.2'
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 0.2.7
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '0.2'
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.2.7
76
+ description:
77
+ email: james@jamesrobertson.eu
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - lib/md_edit.rb
83
+ homepage: https://github.com/jrobertson/md_edit
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.6.13
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Find a section of a markdown document to edit using the name of the heading
107
+ test_files: []
metadata.gz.sig ADDED
Binary file