EmEditor (text editor) Forum Index
   Regular Expressions
     How to clean unclosed HTML TAG ?
Register To Post

Flat Previous Topic | Next Topic
Poster Thread
Stefan
Posted on: 11/14/2012 9:29 pm
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 263
Re: How to clean unclosed HTML TAG ?
.

* 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);
}

Flat Previous Topic | Next Topic


Subject Poster Date
   How to clean unclosed HTML TAG ? liloli 11/13/2012 4:49 pm
     Re: How to clean unclosed HTML TAG ? Stefan 11/13/2012 9:52 pm
       Re: How to clean unclosed HTML TAG ? liloli 11/14/2012 3:48 pm
       » Re: How to clean unclosed HTML TAG ? Stefan 11/14/2012 9:29 pm
           Re: How to clean unclosed HTML TAG ? liloli 11/17/2012 3:34 pm
             Re: How to clean unclosed HTML TAG ? Stefan 11/18/2012 2:32 am
               Re: How to clean unclosed HTML TAG ? liloli 11/18/2012 4:06 pm
                 Re: How to clean unclosed HTML TAG ? Yutaka 11/18/2012 4:41 pm
                   Re: How to clean unclosed HTML TAG ? liloli 11/18/2012 6:20 pm

Register To Post
 
English čeština Deutsch español français italiano 日本語 한국어 Русский 简体中文 繁體中文