Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow HTML formatted messages #63

Open
plaisthos opened this issue Sep 2, 2011 · 4 comments
Open

Allow HTML formatted messages #63

plaisthos opened this issue Sep 2, 2011 · 4 comments

Comments

@plaisthos
Copy link

I have tried to send a message containing bold text. Unfortunaly the API does not allow to pass html tags unmodified.

A Jabber message with format looks this:

<message from="[email protected]/blabla" type="chat" to="[email protected]" id="purple5cc6aad7" >
<active xmlns="http://jabber.org/protocol/chatstates"/>
<body>bold italic</body>
<html xmlns="http://jabber.org/protocol/xhtml-im">
<body xmlns="http://www.w3.org/1999/xhtml">
<p>
<span style="font-weight: bold;" >bold <em>italic</em>
</span>
</p>
</body>
</html>
</message>
@Jajcus
Copy link
Owner

Jajcus commented Sep 2, 2011

PyXMPP2 doesn't have any dedicated XHTML-IM support yet, but you can add the XHTML code to the Message stanza as an XMLPayload object. Like this:

from pyxmpp2.etree import ElementTree
from pyxmpp2.message import Message
from pyxmpp2.stanzapayload import XMLPayload

message = Message(to_jid=recipient, stanza_type='chat', body='bold italic')
formatted = ElementTree.XML('''<html xmlns="http://jabber.org/protocol/xhtml-im">
<body xmlns="http://www.w3.org/1999/xhtml">
<p>
<span style="font-weight: bold;" >bold <em>italic</em>
</span>
</p>
</body>
</html>''')
message.add_payload(XMLPayload(formatted))

Dedicated support for XHTML-IM may be added to PyXMPP2 some day, but it is not high priority (much more important things are still missing).

@wschoenell
Copy link

Hi! I am having a similar issue here, but on the other way.
I'd like to receive XML messages from a Jabber server, but it mess with the message parser.
Is there any easy way to do this? Maybe overriding the client function fix_in_stanza(stanza)?

@Jajcus
Copy link
Owner

Jajcus commented Jun 21, 2012

@wschoenell How dos it mess with the message parser? Any XMPP message must be a well-formed XML element and as such is available through the PyXMPP2 API without any data loss.
Why do you think you should override fix_in_stanza()?

@wschoenell
Copy link

Hi... I'm sorry... I was using the wrong jabber list to do the tests. The one that I was using had a malformed XML stream.
I changed the list and everything works. :)
Thanks for your prompt answer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants