Home Forums General XMetaL Discussion Makro Search Entity and Replace it Reply To: Makro Search Entity and Replace it

Derek Read

Reply to: Makro Search Entity and Replace it

Right. No, you can't find carriage returns using the Find feature. That's a control character you just can't match on, even in Plain Text view. Something that shouldn't be necessary under normal circumstances and so it is unimplemented.

The sequence you indicate (carriage return + space) should be handled by any XML-aware processor without issue. The normal behaviour for multiple white space characters is to treat them as a single space (there are specific circumstances where the white space in an element should be treated as significant, but that has to be specifically indicated to the XML processor). It sounds like whatever you are using has problems dealing with this very common sequence.

If you cannot get that software to deal with the sequence then changing the XML would seem to be the only option. If you already use XSLT to modify or transform documents then I would see if you can take advantage of the XSLT normalize-space() function. That could possibly fix all of this up magically with almost no effort. I would *highly* recommend this over the ugly JScript hack example I list below.

[code=example /hack/ to remove duplicate white spaces]
//XMetaL Script Language JScript:
ActiveDocument.FormattingUpdating = false;
var doctxt = Selection.TextWithRM;
//modify the following regex as needed if it is matching too much
//I don't think you should try to replace the match with nothing (deleting it)
//as I think that definitely has the potential to break markup
doctxt = doctxt.replace(/s+/g,” “);
if(Selection.CanPaste(doctxt)) {
else {
Application.Alert(“Unable to perform operation on this document.”);
ActiveDocument.FormattingUpdating = true;[/code]

Test that *a lot* on your documents first (and then probably don't use it anyway).

Note that if pretty printing is enabled for this document type then switching to Plain Text view or saving the document will trigger that feature, possibly reintroducing characters you do not want to be in the document. If the unwanted white space characters are getting into the document through pretty printing you'll need to modify the pretty printing settings in the CTM file. There is a global setting and you can control it on a per-element basis as well.

I'm beginning to think that pretty printing is the most likely cause and that you may want to disable it outright. Keep in mind that doing so will not remove carriage returns from existing files, nor will it stop an author from inserting them in Plain Text view, nor stop them from being typed into elements where white space is treated significantly, nor stop someone from pasting them into a document.