little_markdown 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/little_markdown.rb +47 -7
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da97d151c8c53f9f2baf01827cf5fd9bfdd67368de5a54399a1821ca91a05885
|
4
|
+
data.tar.gz: 3a17999a0f8a218aa91b5ead67eb43d90acdd737d38a848a83ba99d996409c9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a8c351a0f3ae24187bb95ea7055121842e94546c859fc130c6b3c0dea3c80af2a5d505e500b2a909a76c784ecb129a74784f7d454fbd27d4091bd75ece5109a
|
7
|
+
data.tar.gz: 58dbcb5b6b95afd5e33d0cfcdeec39c1a7e6f4725ecd322f47aac36820f7f77f2d3d6845c82c596d491371aabfb27537d8cd8ba64d7b86818b55641b308460a6
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/little_markdown.rb
CHANGED
@@ -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|
|
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
|
-
|
28
|
-
|
29
|
-
|
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
|
47
|
-
|
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
|
-
|
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.
|
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-
|
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
|