hlt 0.1.11 → 0.2.1
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.tar.gz.sig +0 -0
- data/lib/hlt.rb +67 -5
- metadata +16 -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: 9bb51ca55833a336cde7a8ea1994202d0a1a117d
|
4
|
+
data.tar.gz: f8a6a92377d845860f1b3b968d65e0caef6ba0b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcd42b24d1f384bcd8318a7435b02dd9d2791eb4012f15d40f73758972dd9ee2f8589318eb448f0aaa9fb66449a7cff61889b794bb65f2110b7ef9320c30bf8e
|
7
|
+
data.tar.gz: 767373f23ffda3ac1a6bfa8e69f99bee04bb6e7400f7a4de5e4af7984b0df2be877a5c66a857bcfc9fb1f58cde6948335180b3827d1af135e30618cf2b2c1031
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/hlt.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
# file: hlt.rb
|
4
4
|
|
5
5
|
require 'line-tree'
|
6
|
+
require 'rdiscount'
|
6
7
|
|
7
8
|
class Hlt
|
8
9
|
|
@@ -12,23 +13,24 @@ class Hlt
|
|
12
13
|
|
13
14
|
# strip out lines which are blank or only contain a comment
|
14
15
|
#s = raw_s.lines.to_a.reject!{|x| x[/(^\s+\#\s)|(^\s*$)/] }
|
15
|
-
s = raw_s
|
16
16
|
|
17
|
+
s, markdown = fetch_markdown raw_s
|
18
|
+
#s = raw_s
|
17
19
|
# strip out the text from the line containing a comment
|
18
20
|
s.gsub!(/((^#\s|\s#\s).*)/,'').strip if s[/((^#\s|\s#\s).*)/]
|
19
|
-
|
21
|
+
a_code = s.scan(/^\[([^\]]+)\]\n/).map(&:first)
|
20
22
|
s.gsub!(/\n\[[^\]]+\]\n/, " !CODE\n")
|
21
23
|
|
22
24
|
s2 = s.lines.to_a.map!{|line|
|
23
25
|
|
24
26
|
hash = "(\s+\{[^\}]+\})?"
|
25
|
-
line.sub(/^\s+(\w+)?(?:[\.#]\w+){1,}#{hash}/) do |x|
|
27
|
+
r = line.sub(/^\s+(\w+)?(?:[\.#]\w+){1,}#{hash}/) do |x|
|
26
28
|
|
27
29
|
raw_attrs = x.slice!(/\{.*\}/)
|
28
30
|
attrs = raw_attrs[1..-2] if raw_attrs
|
29
31
|
|
30
32
|
a2 = []
|
31
|
-
tag = x[/(
|
33
|
+
tag = x[/(^\s*\w*)[#\.]/,1] || 'div'
|
32
34
|
tag += 'div' if tag.strip.empty?
|
33
35
|
|
34
36
|
x.sub(/(?:\.\w+){1,}/) do |x2|
|
@@ -43,13 +45,73 @@ class Hlt
|
|
43
45
|
"%s {%s}" % [tag, a2.join(', ')]
|
44
46
|
|
45
47
|
end
|
48
|
+
|
49
|
+
r
|
46
50
|
}.join
|
47
51
|
|
52
|
+
|
48
53
|
raw_html = LineTree.new(s2).to_xml
|
54
|
+
|
49
55
|
html = raw_html.gsub('!CODE').with_index do |x,i|
|
50
|
-
"\n\n" +
|
56
|
+
"\n\n" + a_code[i].lines.map{|x| ' ' * 4 + x}.join + "\n"
|
51
57
|
end
|
58
|
+
|
59
|
+
markdown.each.with_index do |x,i|
|
60
|
+
html.sub!(/<markdown:#{i}\/>/, RDiscount.new(x).to_html)
|
61
|
+
end
|
62
|
+
|
52
63
|
@to_html = Rexle.new(html).xml pretty: true
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
def fetch_markdown(raw_s)
|
68
|
+
|
69
|
+
# any lines which are in the context of markdown which only contain
|
70
|
+
# a new line character will have spaces inserted into them
|
71
|
+
|
72
|
+
prev_line = ''
|
73
|
+
s = raw_s.lines.map {|line|
|
74
|
+
line = prev_line + "\n" if line == "\n"
|
75
|
+
prev_line = line[/^\s+/]
|
76
|
+
line
|
77
|
+
}.join
|
78
|
+
|
79
|
+
index, spaces, md_spaces = 0, 0, 0
|
80
|
+
state = :default
|
81
|
+
markdown = []
|
82
|
+
|
83
|
+
s2 = s.lines.map do |line|
|
84
|
+
|
85
|
+
if state == :markdown then
|
86
|
+
spaces = line[/^\s+/].to_s.length
|
87
|
+
if spaces > md_spaces then
|
88
|
+
markdown[index] << line[(md_spaces + 2)..-1]
|
89
|
+
line = ''
|
90
|
+
else
|
91
|
+
markdown[index].strip!
|
92
|
+
index += 1
|
93
|
+
state = :default
|
94
|
+
end
|
95
|
+
|
96
|
+
else
|
97
|
+
|
98
|
+
r = line[/^(\s+)markdown:/,1]
|
99
|
+
|
100
|
+
if r then
|
101
|
+
|
102
|
+
state = :markdown
|
103
|
+
md_spaces = r.length
|
104
|
+
|
105
|
+
line.sub!(/markdown:/,'\0' + index.to_s)
|
106
|
+
markdown[index] = ''
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
line
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
[s2.join, markdown]
|
53
115
|
end
|
54
116
|
|
55
117
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hlt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -29,7 +29,7 @@ cert_chain:
|
|
29
29
|
WLDjnwWJij3s1n0smA0epN35TNfBPwBuMix0lFvcsZD+rLm3Q/VpL11uc8WftPB8
|
30
30
|
AjmkUd4GsuVwySXdl57hm+F/UhshciKo
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date: 2013-10-
|
32
|
+
date: 2013-10-04 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: line-tree
|
@@ -45,6 +45,20 @@ dependencies:
|
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rdiscount
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
48
62
|
description:
|
49
63
|
email: james@r0bertson.co.uk
|
50
64
|
executables: []
|
metadata.gz.sig
CHANGED
Binary file
|