mtlite 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: e2ad3477f98d6b65820ae905f8c8e02604dc43d1
4
+ data.tar.gz: 8cce9b70fa79ca82efc364655ed3bc8620a0e890
5
+ SHA512:
6
+ metadata.gz: 95abd9c190aa666c8b8c0d326dbc04486a05cd22f1a24e9cf3ea9331b34dfd75bffed858dbbc7c312c779b6f7b75822299bbdc02d95fc12be0745b7cfdabb6a4
7
+ data.tar.gz: 43a1ba85b28f8c7e40859caa01fd16f514792faa0f262f61a5e6e9a50fe585638dfff8b5b16347c41af10edd637d55c0d208752945e11185bcc99890192344d8
checksums.yaml.gz.sig ADDED
@@ -0,0 +1 @@
1
+ uV��
data.tar.gz.sig ADDED
Binary file
data/lib/mtlite.rb ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: mtlite.rb
4
+
5
+ require 'markdown'
6
+
7
+ class MTLite
8
+ def initialize(raw_msg)
9
+ @raw_msg = raw_msg
10
+ end
11
+
12
+ def to_html()
13
+ raw_msg = @raw_msg
14
+ raw_msg.sub!(/\[\[.*\]/){|x| x[0..-2].gsub(/[^\n](\[[x\s]?\])/,'<br/>\1') }
15
+ raw_msg = raw_msg.gsub(/\[\s*\]/,'&#9744;').gsub(/\[x\]/,'&#9745;')
16
+ raw_msg = raw_msg.gsub('1/4','&#188;').gsub('1/2','&#189;').gsub('3/4','&#190;')
17
+
18
+ raw_msg.gsub!(/\s-[^-]+-?[^-]+-[\s\]]/) do |x|
19
+ x.sub(/-([&\w]+.*\w+)-/,'<del>\1</del>')
20
+ end
21
+
22
+ raw_msg.gsub!(/(?:^\[|\s\[)[^\]]+\]\((https?:\/\/[^\s]+)/) do |x|
23
+ s2 = x[/https?:\/\/([^\/]+)/,1].split(/\./)
24
+ r = s2.length >= 3 ? s2[1..-1] : s2
25
+ "%s [%s]" % [x, r.join('.')]
26
+ end
27
+
28
+ raw_msg.gsub!(/\[[\*#][^\]]+\]/) do |list|
29
+
30
+ if not list[/\n/] then
31
+
32
+ symbol = list[1]
33
+ symbol.prepend '\\' if symbol == '*'
34
+ tag = {'#' => 'ol', '\*' => 'ul'}[symbol]
35
+
36
+ "<#{tag}>%s</#{tag}>" % list.strip[1..-2].split(/#{symbol}/)[1..-1].
37
+ map{|x| "<li>%s</li>" % x.strip}.join
38
+ else
39
+ list
40
+ end
41
+
42
+ end
43
+
44
+ msg = Markdown.new(raw_msg).to_html.gsub(/<\/?p[^>]*>/,'')
45
+ msg.gsub!(/(?:^(https?:[^\s]+)|\s(https?:[^\s]+))/,' <a href="\2">\2</a>')
46
+ msg.gsub!(/<a /,'<a target="_blank" ')
47
+ len = msg.gsub(/<\/?.[^>]*>/,'').length
48
+
49
+ msg
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mtlite
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
+ 8ixkARkWAmV1MB4XDTEzMDkwOTE0MDUyNVoXDTE0MDkwOTE0MDUyNVowSDESMBAG
16
+ A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
+ EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
+ ggEBANkHhe7tkoX1WtJvygqWKYtUgiZbmhcv5O/xUXCkBJR0QpnVe2QvpQi+BUz7
19
+ EZS13YmkHryR28Va7l7XnrOnZ+gGk7nvzyX+Rw5jEbl6nOT9UYe7AdPuwazdjQVb
20
+ u90E9JsfxZ3fvKPUI0y79Ene5nBWtaXI51IB6uvF3VMlOxpOPCBOUXpcF3Gw7JSI
21
+ Hp+jq1AK8vCuCcJJltY9UGuYk7glIO3NBmkInabr8FZ3fCz8IZRf+/WdpAZ2lcJ9
22
+ vRNACg8Kkt3B9aa3bRIGvC4Ue1JOYwWjbLN09M6pmPLYsmAi8XcsXeiy2ss0yrlR
23
+ B+8fKgvOIA6beN0mFtBHKxbP7osCAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
24
+ DwQEAwIEsDAdBgNVHQ4EFgQUIJYiIUVf+FdVq9SGqQt7qyXqJVEwJgYDVR0RBB8w
25
+ HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
26
+ c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEACcN8RQL5
27
+ vhAE07AmAwOaLnnGSWFgXPJoS2NUJgyjEZf6B680aMx1Koc0Ad8CbOnp1rsVEmY/
28
+ Sdjd1vG5JIOhlPpJJcVDpBG/2rPPraWPMw94f7VdoiayvO6R/rL2MvdaVXxKBJiR
29
+ Tyxk2FfjEof/3PjVWaILA1fvrPkBlC9UMFFS+SNkgIWLMFtVWkiCZmMS67fqQU2w
30
+ +4uH78fBJDZNpbKyvcFYV9/D2vBeW6CNqy2BBtEcdyP/9KoS8GKAH1YNSOnPeuE7
31
+ 5/TxC35nCZmPNpOqets9YZ3k51P68rX0BUcUlqXZn7VmkT1Un30VYxuWwUsOhOYA
32
+ dZmrX4ybr1RPCQ==
33
+ -----END CERTIFICATE-----
34
+ date: 2013-09-09 00:00:00.000000000 Z
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: markdown
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ description:
51
+ email: james@r0bertson.co.uk
52
+ executables: []
53
+ extensions: []
54
+ extra_rdoc_files: []
55
+ files:
56
+ - lib/mtlite.rb
57
+ homepage: https://github.com/jrobertson/mtlite
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.0.0.rc.2
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: mtlite
81
+ test_files: []
metadata.gz.sig ADDED
Binary file