Jump to content

Newlines in script filter feedback "arg"


Recommended Posts

The `arg` part of a script filter's result (the bit passed on as {query}) is oddly an XML attribute instead of an element. This makes it harder to pass on newlines in results--they just turn into spaces. The trick is to escape the newlines as an entity reference like:

 

Most XML escape functions won't do that automatically, so you probably need to it yourself. Possibly double-quotes too. The best thing I came up with in Python is:

 

from xml.sax.saxutils import escape

safe_arg = escape(any_crazy_text, {'"': '"', '\n': '
'} )

 

 

I'd be happy to hear that there's a simpler way.

 

Just passing this on since it stumped me at first.

Link to post
  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...