pidgin2adium 3.1.0 → 3.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.
- data/ChangeLog +7 -0
- data/VERSION +1 -1
- data/lib/pidgin2adium/log_file.rb +1 -0
- data/lib/pidgin2adium/log_parser.rb +2 -3
- data/lib/pidgin2adium/message.rb +2 -97
- data/lib/pidgin2adium/messages/all.rb +5 -0
- data/lib/pidgin2adium/messages/auto_reply_message.rb +11 -0
- data/lib/pidgin2adium/messages/event.rb +17 -0
- data/lib/pidgin2adium/messages/message.rb +22 -0
- data/lib/pidgin2adium/messages/status_message.rb +17 -0
- data/lib/pidgin2adium/messages/xml_message.rb +40 -0
- data/lib/pidgin2adium/parsers/all.rb +3 -0
- data/lib/pidgin2adium/{basic_parser.rb → parsers/basic_parser.rb} +2 -3
- data/lib/pidgin2adium/{html_log_parser.rb → parsers/html_log_parser.rb} +0 -0
- data/lib/pidgin2adium/{text_log_parser.rb → parsers/text_log_parser.rb} +0 -0
- data/lib/pidgin2adium.rb +4 -1
- data/pidgin2adium.gemspec +11 -5
- data/spec/log_file_spec.rb +26 -30
- data/spec/spec_helper.rb +0 -1
- metadata +12 -6
- data/lib/pidgin2adium/balance_tags.rb +0 -118
data/ChangeLog
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
=== 3.1.1 / 2010-08-13
|
2
|
+
* Moved BasicParser and its subclasses into parsers/ subdir
|
3
|
+
- You can now do "require 'pidgin2adium/parsers/all'",
|
4
|
+
though the old "require 'pidgin2adium/log_parser" will still work
|
5
|
+
* Moved Message and its subclasses into messages/ subdir
|
6
|
+
- You can now do "require 'pidgin2adium/messages/all'",
|
7
|
+
though the old "require 'pidgin2adium/message" will still work
|
1
8
|
=== 3.1.0 / 2010-08-13
|
2
9
|
* Compatible with Ruby 1.9!
|
3
10
|
- removed dependency on "parsedate" library, which 1.9 doesn't have
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.1.
|
1
|
+
3.1.1
|
@@ -1,3 +1,2 @@
|
|
1
|
-
|
2
|
-
require 'pidgin2adium/
|
3
|
-
require 'pidgin2adium/html_log_parser'
|
1
|
+
# For backwards compatibility with Pidgin2Adium < 3.1.1
|
2
|
+
require 'pidgin2adium/parsers/all'
|
data/lib/pidgin2adium/message.rb
CHANGED
@@ -1,97 +1,2 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
module Pidgin2Adium
|
5
|
-
# A holding object for each line of the chat. It is subclassed as
|
6
|
-
# appropriate (eg AutoReplyMessage). Each subclass (but not Message
|
7
|
-
# itself) has its own to_s which prints out its information in a format
|
8
|
-
# appropriate for putting in an Adium log file.
|
9
|
-
# Subclasses: XMLMessage, AutoReplyMessage, StatusMessage, Event.
|
10
|
-
class Message
|
11
|
-
def initialize(sender, time, buddy_alias)
|
12
|
-
# The sender's screen name
|
13
|
-
@sender = sender
|
14
|
-
# The time the message was sent, in Adium format (e.g.
|
15
|
-
# "2008-10-05T22:26:20-0800")
|
16
|
-
@time = time
|
17
|
-
# The receiver's alias (NOT screen name)
|
18
|
-
@buddy_alias = buddy_alias
|
19
|
-
end
|
20
|
-
attr_accessor :sender, :time, :buddy_alias
|
21
|
-
end
|
22
|
-
|
23
|
-
# Basic message with body text (as opposed to pure status messages, which
|
24
|
-
# have no body).
|
25
|
-
class XMLMessage < Message
|
26
|
-
def initialize(sender, time, buddy_alias, body)
|
27
|
-
super(sender, time, buddy_alias)
|
28
|
-
@body = body
|
29
|
-
@styled_body = '<div><span style="font-family: Helvetica; font-size: 12pt;">%s</span></div>' % @body
|
30
|
-
normalize_body!()
|
31
|
-
end
|
32
|
-
attr_accessor :body
|
33
|
-
|
34
|
-
def to_s
|
35
|
-
return sprintf('<message sender="%s" time="%s" alias="%s">%s</message>' << "\n",
|
36
|
-
@sender, @time, @buddy_alias, @styled_body)
|
37
|
-
end
|
38
|
-
|
39
|
-
# Balances mismatched tags, normalizes body style, and fixes actions
|
40
|
-
# so they are in Adium style (Pidgin uses "***Buddy waves at you", Adium uses
|
41
|
-
# "*Buddy waves at you*").
|
42
|
-
def normalize_body!
|
43
|
-
normalize_body_entities!()
|
44
|
-
# Fix mismatched tags. Yes, it's faster to do it per-message
|
45
|
-
# than all at once.
|
46
|
-
@body = Pidgin2Adium.balance_tags_c(@body)
|
47
|
-
if @buddy_alias[0,3] == '***'
|
48
|
-
# "***<alias>" is what pidgin sets as the alias for a /me action
|
49
|
-
@buddy_alias.slice!(0,3)
|
50
|
-
@body = '*' << @body << '*'
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# Escapes entities.
|
55
|
-
def normalize_body_entities!
|
56
|
-
# Convert '&' to '&' only if it's not followed by an entity.
|
57
|
-
@body.gsub!(/&(?!lt|gt|amp|quot|apos)/, '&')
|
58
|
-
end
|
59
|
-
end # END XMLMessage class
|
60
|
-
|
61
|
-
# An auto reply message.
|
62
|
-
class AutoReplyMessage < XMLMessage
|
63
|
-
def to_s
|
64
|
-
return sprintf('<message sender="%s" time="%s" auto="true" alias="%s">%s</message>' << "\n",
|
65
|
-
@sender, @time, @buddy_alias, @styled_body)
|
66
|
-
end
|
67
|
-
end # END AutoReplyMessage class
|
68
|
-
|
69
|
-
# A message saying e.g. "Blahblah has gone away."
|
70
|
-
class StatusMessage < Message
|
71
|
-
def initialize(sender, time, buddy_alias, status)
|
72
|
-
super(sender, time, buddy_alias)
|
73
|
-
@status = status
|
74
|
-
end
|
75
|
-
attr_accessor :status
|
76
|
-
|
77
|
-
def to_s
|
78
|
-
return sprintf('<status type="%s" sender="%s" time="%s" alias="%s"/>' << "\n", @status, @sender, @time, @buddy_alias)
|
79
|
-
end
|
80
|
-
end # END StatusMessage class
|
81
|
-
|
82
|
-
# Pidgin does not have Events, but Adium does. Pidgin mostly uses system
|
83
|
-
# messages to display what Adium calls events. These include sending a file,
|
84
|
-
# starting a Direct IM connection, or an error in chat.
|
85
|
-
class Event < XMLMessage
|
86
|
-
def initialize(sender, time, buddy_alias, body, event_type)
|
87
|
-
super(sender, time, buddy_alias, body)
|
88
|
-
@event_type = event_type
|
89
|
-
end
|
90
|
-
attr_accessor :event_type
|
91
|
-
|
92
|
-
def to_s
|
93
|
-
return sprintf('<event type="%s" sender="%s" time="%s" alias="%s">%s</event>',
|
94
|
-
@event_type, @sender, @time, @buddy_alias, @styled_body)
|
95
|
-
end
|
96
|
-
end # END Event class
|
97
|
-
end
|
1
|
+
# For backwards compatibility with Pidgin2Adium < 3.1.1
|
2
|
+
require 'pidgin2adium/message/all'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# The Message class's subclasses, each used for holding one line of a chat.
|
2
|
+
|
3
|
+
module Pidgin2Adium
|
4
|
+
# An auto reply message.
|
5
|
+
class AutoReplyMessage < XMLMessage
|
6
|
+
def to_s
|
7
|
+
return sprintf('<message sender="%s" time="%s" auto="true" alias="%s">%s</message>' << "\n",
|
8
|
+
@sender, @time, @buddy_alias, @styled_body)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Pidgin2Adium
|
2
|
+
# Pidgin does not have Events, but Adium does. Pidgin mostly uses system
|
3
|
+
# messages to display what Adium calls events. These include sending a file,
|
4
|
+
# starting a Direct IM connection, or an error in chat.
|
5
|
+
class Event < XMLMessage
|
6
|
+
def initialize(sender, time, buddy_alias, body, event_type)
|
7
|
+
super(sender, time, buddy_alias, body)
|
8
|
+
@event_type = event_type
|
9
|
+
end
|
10
|
+
attr_accessor :event_type
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
return sprintf('<event type="%s" sender="%s" time="%s" alias="%s">%s</event>',
|
14
|
+
@event_type, @sender, @time, @buddy_alias, @styled_body)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# The Message class and its subclasses, each used for holding one line of a
|
2
|
+
# chat.
|
3
|
+
|
4
|
+
module Pidgin2Adium
|
5
|
+
# A holding object for each line of the chat. It is subclassed as
|
6
|
+
# appropriate (eg AutoReplyMessage). Each subclass (but not Message
|
7
|
+
# itself) has its own to_s which prints out its information in a format
|
8
|
+
# appropriate for putting in an Adium log file.
|
9
|
+
# Subclasses: XMLMessage, AutoReplyMessage, StatusMessage, Event.
|
10
|
+
class Message
|
11
|
+
def initialize(sender, time, buddy_alias)
|
12
|
+
# The sender's screen name
|
13
|
+
@sender = sender
|
14
|
+
# The time the message was sent, in Adium format (e.g.
|
15
|
+
# "2008-10-05T22:26:20-0800")
|
16
|
+
@time = time
|
17
|
+
# The receiver's alias (NOT screen name)
|
18
|
+
@buddy_alias = buddy_alias
|
19
|
+
end
|
20
|
+
attr_accessor :sender, :time, :buddy_alias
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# The Message class's subclasses, each used for holding one line of a chat.
|
2
|
+
|
3
|
+
module Pidgin2Adium
|
4
|
+
# A message saying e.g. "Blahblah has gone away."
|
5
|
+
class StatusMessage < Message
|
6
|
+
def initialize(sender, time, buddy_alias, status)
|
7
|
+
super(sender, time, buddy_alias)
|
8
|
+
@status = status
|
9
|
+
end
|
10
|
+
attr_accessor :status
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
return sprintf('<status type="%s" sender="%s" time="%s" alias="%s"/>' << "\n",
|
14
|
+
@status, @sender, @time, @buddy_alias)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Pidgin2Adium
|
2
|
+
# Basic message with body text (as opposed to pure status messages, which
|
3
|
+
# have no body).
|
4
|
+
class XMLMessage < Message
|
5
|
+
def initialize(sender, time, buddy_alias, body)
|
6
|
+
super(sender, time, buddy_alias)
|
7
|
+
@body = body
|
8
|
+
@styled_body = '<div><span style="font-family: Helvetica; font-size: 12pt;">%s</span></div>' % @body
|
9
|
+
normalize_body!()
|
10
|
+
end
|
11
|
+
attr_accessor :body
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
return sprintf('<message sender="%s" time="%s" alias="%s">%s</message>' << "\n",
|
15
|
+
@sender, @time, @buddy_alias, @styled_body)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Balances mismatched tags, normalizes body style, and fixes actions
|
19
|
+
# so they are in Adium style (Pidgin uses "***Buddy waves at you", Adium uses
|
20
|
+
# "*Buddy waves at you*").
|
21
|
+
def normalize_body!
|
22
|
+
normalize_body_entities!()
|
23
|
+
# Fix mismatched tags. Yes, it's faster to do it per-message
|
24
|
+
# than all at once.
|
25
|
+
@body = Pidgin2Adium.balance_tags_c(@body)
|
26
|
+
if @buddy_alias[0,3] == '***'
|
27
|
+
# "***<alias>" is what pidgin sets as the alias for a /me action
|
28
|
+
@buddy_alias.slice!(0,3)
|
29
|
+
@body = '*' << @body << '*'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Escapes all entities in @body except for "<", ">", "&", """,
|
34
|
+
# and "'".
|
35
|
+
def normalize_body_entities!
|
36
|
+
# Convert '&' to '&' only if it's not followed by an entity.
|
37
|
+
@body.gsub!(/&(?!lt|gt|amp|quot|apos)/, '&')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -10,7 +10,7 @@ require 'date'
|
|
10
10
|
require 'time'
|
11
11
|
|
12
12
|
require 'pidgin2adium/log_file'
|
13
|
-
require 'pidgin2adium/
|
13
|
+
require 'pidgin2adium/messages/all'
|
14
14
|
|
15
15
|
module Pidgin2Adium
|
16
16
|
# Empty class. Raise'd by LogParser if the first line of a log is not
|
@@ -182,8 +182,7 @@ module Pidgin2Adium
|
|
182
182
|
if tz_match and tz_match[1]
|
183
183
|
tz_offset = tz_match[1]
|
184
184
|
else
|
185
|
-
|
186
|
-
tz_offset = sprintf('%+03d00', Time.zone_offset(Time.now.zone) / 3600)
|
185
|
+
tz_offset = Pidgin2Adium::DEFAULT_TZ_OFFSET
|
187
186
|
end
|
188
187
|
return tz_offset
|
189
188
|
end
|
File without changes
|
File without changes
|
data/lib/pidgin2adium.rb
CHANGED
@@ -4,7 +4,8 @@
|
|
4
4
|
# them in the Adium log directory.
|
5
5
|
|
6
6
|
require 'fileutils'
|
7
|
-
require '
|
7
|
+
require 'time'
|
8
|
+
require 'pidgin2adium/parsers/all'
|
8
9
|
|
9
10
|
module Pidgin2Adium
|
10
11
|
# Returned by LogFile.write_out if the output logfile already exists.
|
@@ -13,6 +14,8 @@ module Pidgin2Adium
|
|
13
14
|
# These files/directories show up in Dir.entries()
|
14
15
|
BAD_DIRS = %w{. .. .DS_Store Thumbs.db .system}
|
15
16
|
VERSION = "3.1.0"
|
17
|
+
# "-0500" (3d rather than 2d to allow for "+")
|
18
|
+
DEFAULT_TZ_OFFSET = sprintf('%+03d00', Time.zone_offset(Time.now.zone) / 3600)
|
16
19
|
# For displaying after we finish converting
|
17
20
|
@@oops_messages = []
|
18
21
|
@@error_messages = []
|
data/pidgin2adium.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{pidgin2adium}
|
8
|
-
s.version = "3.1.
|
8
|
+
s.version = "3.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Gabe Berke-Williams"]
|
@@ -36,14 +36,20 @@ Gem::Specification.new do |s|
|
|
36
36
|
"ext/balance_tags_c/balance_tags_c.c",
|
37
37
|
"ext/balance_tags_c/extconf.rb",
|
38
38
|
"lib/pidgin2adium.rb",
|
39
|
-
"lib/pidgin2adium/balance_tags.rb",
|
40
|
-
"lib/pidgin2adium/basic_parser.rb",
|
41
|
-
"lib/pidgin2adium/html_log_parser.rb",
|
42
39
|
"lib/pidgin2adium/log_converter.rb",
|
43
40
|
"lib/pidgin2adium/log_file.rb",
|
44
41
|
"lib/pidgin2adium/log_parser.rb",
|
45
42
|
"lib/pidgin2adium/message.rb",
|
46
|
-
"lib/pidgin2adium/
|
43
|
+
"lib/pidgin2adium/messages/all.rb",
|
44
|
+
"lib/pidgin2adium/messages/auto_reply_message.rb",
|
45
|
+
"lib/pidgin2adium/messages/event.rb",
|
46
|
+
"lib/pidgin2adium/messages/message.rb",
|
47
|
+
"lib/pidgin2adium/messages/status_message.rb",
|
48
|
+
"lib/pidgin2adium/messages/xml_message.rb",
|
49
|
+
"lib/pidgin2adium/parsers/all.rb",
|
50
|
+
"lib/pidgin2adium/parsers/basic_parser.rb",
|
51
|
+
"lib/pidgin2adium/parsers/html_log_parser.rb",
|
52
|
+
"lib/pidgin2adium/parsers/text_log_parser.rb",
|
47
53
|
"pidgin2adium.gemspec",
|
48
54
|
"spec/balance_tags_c_extn_spec.rb",
|
49
55
|
"spec/basic_parser_spec.rb",
|
data/spec/log_file_spec.rb
CHANGED
@@ -14,30 +14,21 @@ describe "LogFile" do
|
|
14
14
|
"2010-08-10T22:55:17-0500",
|
15
15
|
"2010-08-10T22:55:22-0500"]
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
times[3],
|
33
|
-
@partner_alias,
|
34
|
-
"This is an away message")
|
35
|
-
]
|
36
|
-
@logfile = Pidgin2Adium::LogFile.new(@messages,
|
37
|
-
'aim',
|
38
|
-
@user_SN,
|
39
|
-
@partner_SN,
|
40
|
-
@start_time)
|
17
|
+
message_1 = Pidgin2Adium::XMLMessage.new(@user_SN, @start_time,
|
18
|
+
@user_alias, "Hello!")
|
19
|
+
message_2 = Pidgin2Adium::StatusMessage.new(@partner_SN, times[1],
|
20
|
+
@partner_alias, "Matz has gone away")
|
21
|
+
|
22
|
+
message_3 = Pidgin2Adium::Event.new(@user_SN, times[2], @user_alias,
|
23
|
+
"gabebw logged in.", 'online')
|
24
|
+
|
25
|
+
message_4 = Pidgin2Adium::AutoReplyMessage.new(@partner_SN, times[3],
|
26
|
+
@partner_alias,
|
27
|
+
"This is an away message")
|
28
|
+
|
29
|
+
@messages = [message_1, message_2, message_3, message_4]
|
30
|
+
@logfile = Pidgin2Adium::LogFile.new(@messages, 'aim', @user_SN,
|
31
|
+
@partner_SN, @start_time)
|
41
32
|
end
|
42
33
|
|
43
34
|
describe "attributes" do
|
@@ -69,12 +60,17 @@ describe "LogFile" do
|
|
69
60
|
end
|
70
61
|
end
|
71
62
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
63
|
+
|
64
|
+
describe "enumerable methods" do
|
65
|
+
it "should include Enumerable" do
|
66
|
+
Pidgin2Adium::LogFile.included_modules.include?(Enumerable).should be_true
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#each_with_index" do
|
70
|
+
it "should yield the correct messages" do
|
71
|
+
@logfile.each_with_index do |msg, n|
|
72
|
+
msg.should == @messages[n]
|
73
|
+
end
|
78
74
|
end
|
79
75
|
end
|
80
76
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 3
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 3.1.
|
8
|
+
- 1
|
9
|
+
version: 3.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Gabe Berke-Williams
|
@@ -86,14 +86,20 @@ files:
|
|
86
86
|
- ext/balance_tags_c/balance_tags_c.c
|
87
87
|
- ext/balance_tags_c/extconf.rb
|
88
88
|
- lib/pidgin2adium.rb
|
89
|
-
- lib/pidgin2adium/balance_tags.rb
|
90
|
-
- lib/pidgin2adium/basic_parser.rb
|
91
|
-
- lib/pidgin2adium/html_log_parser.rb
|
92
89
|
- lib/pidgin2adium/log_converter.rb
|
93
90
|
- lib/pidgin2adium/log_file.rb
|
94
91
|
- lib/pidgin2adium/log_parser.rb
|
95
92
|
- lib/pidgin2adium/message.rb
|
96
|
-
- lib/pidgin2adium/
|
93
|
+
- lib/pidgin2adium/messages/all.rb
|
94
|
+
- lib/pidgin2adium/messages/auto_reply_message.rb
|
95
|
+
- lib/pidgin2adium/messages/event.rb
|
96
|
+
- lib/pidgin2adium/messages/message.rb
|
97
|
+
- lib/pidgin2adium/messages/status_message.rb
|
98
|
+
- lib/pidgin2adium/messages/xml_message.rb
|
99
|
+
- lib/pidgin2adium/parsers/all.rb
|
100
|
+
- lib/pidgin2adium/parsers/basic_parser.rb
|
101
|
+
- lib/pidgin2adium/parsers/html_log_parser.rb
|
102
|
+
- lib/pidgin2adium/parsers/text_log_parser.rb
|
97
103
|
- pidgin2adium.gemspec
|
98
104
|
- spec/balance_tags_c_extn_spec.rb
|
99
105
|
- spec/basic_parser_spec.rb
|
@@ -1,118 +0,0 @@
|
|
1
|
-
module Pidgin2Adium
|
2
|
-
# Balances tags of string using a modified stack. Returns a balanced
|
3
|
-
# string, but also affects the text passed into it!
|
4
|
-
# Use text = balance_tags(text).
|
5
|
-
|
6
|
-
# From Wordpress's formatting.php; rewritten in Ruby by Gabe
|
7
|
-
# Berke-Williams, 2009.
|
8
|
-
# Author:: Leonard Lin <leonard@acm.org>
|
9
|
-
# License:: GPL v2.0
|
10
|
-
# Copyright:: November 4, 2001
|
11
|
-
def Pidgin2Adium.balance_tags( text )
|
12
|
-
tagstack = []
|
13
|
-
stacksize = 0
|
14
|
-
tagqueue = ''
|
15
|
-
newtext = ''
|
16
|
-
single_tags = %w{br hr img input meta} # Known single-entity/self-closing tags
|
17
|
-
#nestable_tags = %w{blockquote div span} # Tags that can be immediately nested within themselves
|
18
|
-
nestable_tags = %w{blockquote div span font} # Tags that can be immediately nested within themselves
|
19
|
-
# 1: tagname, with possible leading "/"
|
20
|
-
# 2: attributes
|
21
|
-
tag_regex = /<(\/?\w*)\s*([^>]*)>/
|
22
|
-
|
23
|
-
# WP bug fix for comments - in case you REALLY meant to type '< !--'
|
24
|
-
text.gsub!('< !--', '< !--')
|
25
|
-
|
26
|
-
# WP bug fix for LOVE <3 (and other situations with '<' before a number)
|
27
|
-
text.gsub!(/<([0-9]{1})/, '<\1')
|
28
|
-
|
29
|
-
while ( pos = (text =~ tag_regex) )
|
30
|
-
newtext << tagqueue
|
31
|
-
tag = $1.downcase
|
32
|
-
attributes = $2
|
33
|
-
matchlen = $~[0].size
|
34
|
-
|
35
|
-
# clear the shifter
|
36
|
-
tagqueue = ''
|
37
|
-
# Pop or Push
|
38
|
-
if (tag[0,1] == "/") # End Tag
|
39
|
-
tag.slice!(0,1)
|
40
|
-
# if too many closing tags
|
41
|
-
if(stacksize <= 0)
|
42
|
-
tag = ''
|
43
|
-
#or close to be safe: tag = '/' << tag
|
44
|
-
elsif (tagstack[stacksize - 1] == tag) # found closing tag
|
45
|
-
# if stacktop value == tag close value then pop
|
46
|
-
tag = '</' << tag << '>' # Close Tag
|
47
|
-
# Pop
|
48
|
-
tagstack.pop
|
49
|
-
stacksize -= 1
|
50
|
-
else # closing tag not at top, search for it
|
51
|
-
(stacksize-1).downto(0) do |j|
|
52
|
-
if (tagstack[j] == tag)
|
53
|
-
# add tag to tagqueue
|
54
|
-
ss = stacksize - 1
|
55
|
-
ss.downto(j) do |k|
|
56
|
-
tagqueue << '</' << tagstack.pop << '>'
|
57
|
-
stacksize -= 1
|
58
|
-
end
|
59
|
-
break
|
60
|
-
end
|
61
|
-
end
|
62
|
-
tag = ''
|
63
|
-
end
|
64
|
-
else
|
65
|
-
# Begin Tag
|
66
|
-
|
67
|
-
# Tag Cleaning
|
68
|
-
if( (attributes[-1,1] == '/') || (tag == '') )
|
69
|
-
# If: self-closing or '', don't do anything.
|
70
|
-
elsif ( single_tags.include?(tag) )
|
71
|
-
# ElseIf: it's a known single-entity tag but it doesn't close itself, do so
|
72
|
-
attributes << '/'
|
73
|
-
else
|
74
|
-
# Push the tag onto the stack
|
75
|
-
# If the top of the stack is the same as the tag we want to push, close previous tag
|
76
|
-
if ((stacksize > 0) &&
|
77
|
-
! nestable_tags.include?(tag) &&
|
78
|
-
(tagstack[stacksize - 1] == tag))
|
79
|
-
tagqueue = '</' << tagstack.pop << '>'
|
80
|
-
stacksize -= 1
|
81
|
-
end
|
82
|
-
tagstack.push(tag)
|
83
|
-
stacksize += 1
|
84
|
-
end
|
85
|
-
|
86
|
-
# Attributes
|
87
|
-
if(attributes != '')
|
88
|
-
attributes = ' ' << attributes
|
89
|
-
end
|
90
|
-
tag = '<' << tag << attributes << '>'
|
91
|
-
#If already queuing a close tag, then put this tag on, too
|
92
|
-
if (tagqueue)
|
93
|
-
tagqueue << tag
|
94
|
-
tag = ''
|
95
|
-
end
|
96
|
-
end
|
97
|
-
newtext << text[0,pos] << tag
|
98
|
-
text = text[pos+matchlen, text.length - (pos+matchlen)]
|
99
|
-
end
|
100
|
-
|
101
|
-
# Clear Tag Queue
|
102
|
-
newtext << tagqueue
|
103
|
-
|
104
|
-
# Add Remaining text
|
105
|
-
newtext << text
|
106
|
-
|
107
|
-
# Empty Stack
|
108
|
-
tagstack.reverse_each do |t|
|
109
|
-
newtext << '</' << t << '>' # Add remaining tags to close
|
110
|
-
end
|
111
|
-
|
112
|
-
# WP fix for the bug with HTML comments
|
113
|
-
newtext.gsub!("< !--", "<!--")
|
114
|
-
newtext.gsub!("< !--", "< !--")
|
115
|
-
|
116
|
-
return newtext
|
117
|
-
end
|
118
|
-
end
|