saveDocument converts ©
I need some Mozilla help:
My extension, Launchy, gives the user the ability to view the source of a webpage in an editor of the users choice. To do this I use the saveDocument function. But when I do this, HTML entities like fx © gets converted into a real copyright char.
I thought that if I just use the ENCODE_FLAGS_RAW flag it would work. But it doesn't seems to work.
const nsIWBP = Components.interfaces.nsIWebBrowserPersist;
var persist = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(nsIWBP);
persist.persistFlags = nsIWBP.PERSIST_FLAGS_FROM_CACHE | nsIWBP.PERSIST_FLAGS_NO_CONVERSION | nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES | nsIWBP.PERSIST_FLAGS_NO_BASE_TAG_MODIFICATIONS | nsIWBP.PERSIST_FLAGS_DONT_FIXUP_LINKS | nsIWBP.FLAGS_DONT_CHANGE_FILENAMES;
var encodingFlags = nsIWBP.ENCODE_FLAGS_RAW;
persist.saveDocument(doc, f, null, null, encodingFlags, 0);
Can anybody help? If you can, please can leave a comment here or add a comment to the bug report here.
You can test it yourself if you install my Launchy extension and then right click on a gemal.dk page and say Launchy -> View Source in blabla. Then the © symbol at the end of the source will be converted, which it shouldn't.
I came across this bug today:
Maybe it is relevant.Comment by Nick Thomas at September 13, 2004 06:07 PM | Permalink
It seems that the solution is:
var encodingFlags = nsIWBP.ENCODE_FLAGS_RAW | nsIWBP.ENCODE_FLAGS_ENCODE_W3C_ENTITIES;
Henrik, I think you might want to be passing in ENCODE_FLAGS_ENCODE_HTML_ENTITIES, not PERSIST_FLAGS_NO_CONVERSION. I don't have a way to test this really, but if you take a look at these lines it looks more like what you want:
NO_CONVERSION is not referenced anywhere in the saveDocument function, whereas ENCODE_HTML is. Hope this works for you!Comment by Jon Henry at September 13, 2004 09:50 PM | Permalink