EmEditor (text editor) Forum Index Regular Expressions
How to clean unclosed HTML TAG ? | Register To Post |
| Threaded | Newest First | Previous Topic | Next Topic | Bottom |
| Poster | Thread |
|---|---|
| liloli | Posted on: 11/13/2012 4:49 pm |
Just popping in ![]() ![]() Joined: 11/13/2012 From: Posts: 5 |
How to clean unclosed HTML TAG ? Hi! I'd like to do such replacement:
The primary task is to locate "</span>" which is not appear in pairs. Note the "</span>" in line 3, line 5, line 7. They should be cleaned off. *SOURCE: 1. <p><span style="font-weight:bold;">CCNA Portable Command Guide</span></p> 2. <p><span style="font-weight:bold;">Second Edition Scott Empson</span></p> 3. <p>Cisco Press</span></p> 4. <p>800 East 96th Street Indianapolis, Indiana 46240 USA</p> 5. <p>Command Syntax Conventions</span></p> 6. <h1><span style="font-weight:bold;">PART I</span> <span style="font-weight:bold;">TCP/IP Version 4</span></h1> 7. <h2>CHAPTER 1</span><span style="font-weight:bold;"> How to Subnet</span></h2> *RESULT: 1. <p><span style="font-weight:bold;">CCNA Portable Command Guide</span></p> 2. <p><span style="font-weight:bold;">Second Edition Scott Empson</span></p> 3. <p>Cisco Press</p> 4. <p>800 East 96th Street Indianapolis, Indiana 46240 USA</p> 5. <p>Command Syntax Conventions</p> 6. <h1><span style="font-weight:bold;">PART I</span> <span style="font-weight:bold;">TCP/IP Version 4</span></h1> 7. <h2>CHAPTER 1<span style="font-weight:bold;"> How to Subnet</span></h2> Would anyone please teach me how to do this task using a Regular Expressions ? Thank you! |
| Stefan | Posted on: 11/13/2012 9:52 pm |
Home away from home ![]() ![]() Joined: 7/14/2008 From: Germany, EU Posts: 261 |
Re: How to clean unclosed HTML TAG ? .
Hi and welcome. 1.) Do "<span" and "</span>" always be on the same line? Or could it be that they are on different lines like 1. <p><span style="font-weight:bold;"> CCNA Portable Command Guide</span></p> Your example doesn't provide this detail. - - - 2.) Is it always the first occurrence of "</span>" 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: |
| liloli | Posted on: 11/14/2012 3:48 pm |
Just popping in ![]() ![]() Joined: 11/13/2012 From: Posts: 5 |
Re: How to clean unclosed HTML TAG ? 1.) Let's say <span and </span are always in the same line.
2.)Is it always the first occurrence of "</span>" 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! |
| Stefan | Posted on: 11/14/2012 9:29 pm |
Home away from home ![]() ![]() Joined: 7/14/2008 From: Germany, EU Posts: 261 |
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: |
| liloli | Posted on: 11/17/2012 3:34 pm |
Just popping in ![]() ![]() Joined: 11/13/2012 From: Posts: 5 |
Re: How to clean unclosed HTML TAG ? I'afraid this macros doesn't work well. Nothing happens after I run it .
|
| Stefan | Posted on: 11/18/2012 2:32 am |
Home away from home ![]() ![]() Joined: 7/14/2008 From: Germany, EU Posts: 261 |
Re: How to clean unclosed HTML TAG ? What 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. . |
| liloli | Posted on: 11/18/2012 4:06 pm |
Just popping in ![]() ![]() Joined: 11/13/2012 From: Posts: 5 |
Re: How to clean unclosed HTML TAG ? I 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. |
| Yutaka | Posted on: 11/18/2012 4:41 pm |
Webmaster ![]() ![]() Joined: 9/28/2006 From: Redmond Posts: 2398 |
Re: How to clean unclosed HTML TAG ? Hello,
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: http://www.emeditor.com/images/emeditor10_tool_prop_e_s.png
|
| liloli | Posted on: 11/18/2012 6:20 pm |
Just popping in ![]() ![]() Joined: 11/13/2012 From: Posts: 5 |
Re: How to clean unclosed HTML TAG ? OK then, Thanks a lot.
|
| Threaded | Newest First | Previous Topic | Next Topic | Top |
| Register To Post | |






