little_markdown 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: d4eff9db8eb79878c68d73cc18f03fb4eb3f1c24827897b690feb3a3274928b4
4
- data.tar.gz: 2f7f0edefaf545e8b6654817965381d9a1a06532aaad81e8514705c998895ded
3
+ metadata.gz: da97d151c8c53f9f2baf01827cf5fd9bfdd67368de5a54399a1821ca91a05885
4
+ data.tar.gz: 3a17999a0f8a218aa91b5ead67eb43d90acdd737d38a848a83ba99d996409c9b
5
5
  SHA512:
6
- metadata.gz: 529dfab4fffb4d8110c5c8e87a374a5f1f242309edfd58f5eedbc4c7e0c0914069eeb8410b04358f86fffe41b6c51e9a5431b907616f6df9d2d5ff590fbb17e6
7
- data.tar.gz: 9c6d629c7414029fb798833a46e210a7984811c2204c7249df5b726f0b148015c2f1600f1f1b91283020f4b23f6c536ac225f920d43e3d5de8814821f8d355f7
6
+ metadata.gz: 9a8c351a0f3ae24187bb95ea7055121842e94546c859fc130c6b3c0dea3c80af2a5d505e500b2a909a76c784ecb129a74784f7d454fbd27d4091bd75ece5109a
7
+ data.tar.gz: 58dbcb5b6b95afd5e33d0cfcdeec39c1a7e6f4725ecd322f47aac36820f7f77f2d3d6845c82c596d491371aabfb27537d8cd8ba64d7b86818b55641b308460a6
checksums.yaml.gz.sig CHANGED
Binary file
@@ -4,6 +4,12 @@
4
4
 
5
5
  require 'rexle'
6
6
 
7
+ # The following HTML types are handled:
8
+ #
9
+ # * h1, h2, h3 etc
10
+ # * ul, ol
11
+ # * img, a
12
+
7
13
  class LittleMarkdown
8
14
 
9
15
  attr_reader :to_html
@@ -17,16 +23,20 @@ class LittleMarkdown
17
23
  s3 = ul_parse(s2)
18
24
 
19
25
  raw_html = s3.lines.map do |line|
20
- linex = replace(line) {|x| h1_parse(x)}
26
+ linex = replace(line) {|x| hx_parse(x)}
21
27
  linex3 = replace(linex) {|x| p_parse(x)}
22
28
 
23
29
  end.join
24
30
 
25
31
  doc = Rexle.new("<body>%s</body>" % raw_html)
26
32
  xml = doc.xml(pretty: true, declaration: 'none')
27
- xml2 = replace_link(xml)
28
- puts 'xml2: ' + xml2.inspect if @debug
29
- @to_html = xml2.strip.lines[1..-2].map {|x| x[2..-1] }.join
33
+
34
+
35
+ xml2 = replace_img(xml)
36
+ xml3 = replace_link(xml2)
37
+ puts 'xml3: ' + xml3.inspect if @debug
38
+
39
+ @to_html = xml3.strip.lines[1..-2].map {|x| x[2..-1] }.join
30
40
 
31
41
  end
32
42
 
@@ -43,8 +53,14 @@ class LittleMarkdown
43
53
 
44
54
  end
45
55
 
46
- def h1_parse(s)
47
- s.sub(/^# ([^\n]+)/,'<h1>\1</h1>')
56
+ def hx_parse(s)
57
+
58
+ s.sub(/^(#+) ([^\n]+)/) do |x|
59
+ puts 'x: ' + [$1, $2].inspect
60
+ hx, title = [$1, $2]
61
+ "<h%d>%s</h%d>" % [hx.length, title, hx.length]
62
+ end
63
+
48
64
  end
49
65
 
50
66
  def p_parse(s)
@@ -134,7 +150,31 @@ class LittleMarkdown
134
150
  end
135
151
 
136
152
  end
153
+
154
+ def replace_img(s5)
137
155
 
138
- end
156
+ if @debug then
157
+ puts 'inside replace_img'
158
+ puts 's5: ' + s5.inspect
159
+ end
160
+
161
+ s5.gsub(/\!\[([^\]]+)\]\(([^\)]+)/m) do |x|
139
162
 
163
+ puts 'x: ' + x.inspect if @debug
164
+
165
+ found = x.match(/\[([^\]]+)\]\(([^\)]+)/)
166
+ puts 'found: ' + found.inspect if @debug
167
+
168
+ if found then
169
+ title, src = found[1..-1]
170
+ "<img src='%s' alt='%s'/>" % [src, title]
171
+ else
172
+ x
173
+ end
174
+
175
+ end
176
+
177
+ end
178
+
179
+ end
140
180
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: little_markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -36,7 +36,7 @@ cert_chain:
36
36
  WnSWgG73Vz5MRLGt7hkHbXuiioyoBR5Y9F70rfvUkaViGxc2BxSv7wdlif8jgMQt
37
37
  BpyN4tcC5tg1KfgtGRJPCjmb8Ql4/ZMYZgM=
38
38
  -----END CERTIFICATE-----
39
- date: 2023-05-02 00:00:00.000000000 Z
39
+ date: 2023-05-04 00:00:00.000000000 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rexle
metadata.gz.sig CHANGED
Binary file