#10631

Stefan
Participant

.

* open EmEditor
*
* open a new document
* paste the script in
* save as e.g. Untitled.txt
* click at “Macros > Select This”
*
* open your source document
* put your cursor in ONE line
* execute “Macro > Run Untitled.txt”
* you should be prompted with “delete/all ok/nothing found” depending on the line content
*
* check for each line if the script works for you
* if yes, the next step is to build a loop over all lines
and at last exchange the “delete” message with an find&delete code

Here the proof of concept code again
but with comments:


//settings:
openTag = "<span";
closingTag = "</span";

//get current line number:
yLine = document.selection.GetActivePointY( eePosLogical );

//get line content:
str = document.GetLine( yLine );

//search for occurrences in this line:
openTagPos = str.indexOf(openTag);
closingTagPos = str.indexOf(closingTag);

//if an closing tag is found:
if(closingTagPos > -1){
//if no opening tag is found at all
//OR
//if closing tag is found before the first opening tag
if(openTagPos == -1 || (closingTagPos < openTagPos)){
//<here find first closing tag and remove it>
alert(closingTag + " to delete found");
}else{
//nothing to do in this line. This code can be removed.
alert("lines is ok");
}
}else{
//nothing to do in this line. This code can be removed.
alert("not found " + closingTag);
}