1 package AnyEvent
::XMPP
::Ext
::HTML
;
2 # ABSTRACT: XEP-0071: XHTML-IM (Version 1.5) for AnyEvent::XMPP
7 use AnyEvent
::XMPP
::Ext
;
8 use AnyEvent
::XMPP
::Namespaces qw
/set_xmpp_ns_alias xmpp_ns/;
10 our @ISA = qw
/AnyEvent::XMPP::Ext/;
14 my $c = AnyEvent::XMPP::Connection->new(...);
15 $c->add_extension(my $disco = AnyEvent::XMPP::Ext::Disco->new);
16 $c->add_extension(AnyEvent::XMPP::Ext::HTML->new(disco => $disco));
19 body => "This is plain text; same as usual.",
20 html => "This is <em>XHTML</em>!",
25 An implementation of XEP-0071: XHTML-IM for HTML-formatted messages.
29 HTML messages are not validated nor escaped, so it is your responsibility to
30 use valid XHTML-IM tags and to close them properly.
34 Creates a new extension handle. It takes an optional C<disco> argument which
35 is a L<AnyEvent::XMPP::Ext::Disco> object for which this extension will be
42 my $class = ref($this) || $this;
43 my $self = bless { @_ }, $class;
50 Initialize the extension
. This
does not need to be called externally
.
57 set_xmpp_ns_alias
(xhtml_im
=> 'http://jabber.org/protocol/xhtml-im');
58 set_xmpp_ns_alias
(xhtml
=> 'http://www.w3.org/1999/xhtml');
60 $self->{disco
}->enable_feature($self->disco_feature) if defined $self->{disco
};
62 $self->{cb_id
} = $self->reg_cb(
63 send_message_hook
=> sub {
64 my ($self, $con, $id, $to, $type, $attrs, $create_cb) = @_;
66 return unless exists $attrs->{html
};
67 my $html = delete $attrs->{html
};
69 push @$create_cb, sub {
72 $w->addPrefix(xmpp_ns
('xhtml_im'), '');
73 $w->startTag([xmpp_ns
('xhtml_im'), 'html']);
74 if (ref($html) eq 'HASH') {
76 $w->addPrefix(xmpp_ns
('xhtml'), '');
77 $w->startTag([xmpp_ns
('xhtml'), 'body'], ($_ ne '' ? ([xmpp_ns
('xml'), 'lang'] => $_) : ()));
82 $w->addPrefix(xmpp_ns
('xhtml'), '');
83 $w->startTag([xmpp_ns
('xhtml'), 'body']);
99 $self->unreg_cb($self->{cb_id
});