Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #10626
    liloli
    Member

    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!

    #10627
    Stefan
    Participant

    .

    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 Guide

    Your 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);
    }
    #10630
    liloli
    Member

    1.) 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!

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

    #10635
    liloli
    Member

    I’afraid this macros doesn’t work well. Nothing happens after I run it . :-(

    #10636
    Stefan
    Participant

    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.

    .

    #10638
    liloli
    Member

    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. :-D

    #10639
    Yutaka Emura
    Keymaster

    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

    #10640
    liloli
    Member

    OK then, Thanks a lot. :-)

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.