- AuthorPosts
- November 14, 2012 at 1:49 am #10626liloliMember
Hi! I’d like to do such replacement:
The primary task is to locate “” which is not appear in pairs.
Note the “” in line 3, line 5, line 7. They should be cleaned off.*SOURCE:
1.CCNA Portable Command Guide
2.
Second Edition Scott Empson
3.
Cisco Press
4.
800 East 96th Street Indianapolis, Indiana 46240 USA
5.
Command Syntax Conventions
6.
PART I TCP/IP Version 4
7.
CHAPTER 1 How to Subnet
*RESULT:
1.CCNA Portable Command Guide
2.
Second Edition Scott Empson
3.
Cisco Press
4.
800 East 96th Street Indianapolis, Indiana 46240 USA
5.
Command Syntax Conventions
6.
PART I TCP/IP Version 4
7.
CHAPTER 1 How to Subnet
Would anyone please teach me how to do this task using a Regular Expressions ?
Thank you!November 14, 2012 at 6:52 am #10627StefanParticipant.
Hi and welcome.
1.)
Do “<span" and "” always be on the same line?Or could it be that they are on different lines like
1.
CCNA Portable Command GuideYour example doesn’t provide this detail.
– – –
2.)
Is it always the first occurrence of “” in a line that can be remove?Then the rule would be easier:
if there is found a closing tag without an opening tag before, then it can be removed.Proof Of Concept:
openTag = "<span";
closingTag = "</span";
yLine = document.selection.GetActivePointY( eePosLogical );
str = document.GetLine( yLine );
openTagPos = str.indexOf(openTag);
closingTagPos = str.indexOf(closingTag);
if(closingTagPos > -1){
if(openTagPos == -1 || (closingTagPos < openTagPos)){
alert("delete");
}else{
alert("all ok");
}
}else{
alert("not found " + closingTag);
}
November 15, 2012 at 12:48 am #10630liloliMember1.) Let’s say <span and </span are always in the same line.
2.)Is it always the first occurrence of “” in a line that can be remove?
YES!How should I use these codes ? from Macros? I just thought there might be some find and replace solutions. Anyway thanks a lot ! I’ll try it today!
November 15, 2012 at 6:29 am #10631StefanParticipant.
* 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 codeHere 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);
}
November 18, 2012 at 12:34 am #10635liloliMemberI’afraid this macros doesn’t work well. Nothing happens after I run it . :-(
November 18, 2012 at 11:32 am #10636StefanParticipantWhat have you done?
Step by step.– – –
Also you may want to change my code
str = document.GetLine( yLine );
to
str = document.GetLine( yLine ).toLowerCase();
because indexOf is case sensitive.
.
November 19, 2012 at 1:06 am #10638liloliMemberI realized that you just tried to locate where the line contain a unclosed tag , rather than auto clean it, right?
The code above does cofirm whether current line contain a unclosed tag. and also that’s all it does. :-D
November 19, 2012 at 1:41 am #10639Yutaka EmuraKeymasterHello,
If you just want to make your HTML prettier, you can use HTML tidy. You can search the internet for “HTML Tidy” to download the binary, and run that from an External Tool with EmEditor. See this screenshot:
November 19, 2012 at 3:20 am #10640liloliMemberOK then, Thanks a lot. :-)
- AuthorPosts
- You must be logged in to reply to this topic.