deleting text enclosed by a tag with particular attribute values from html file

238 views Asked by At

I have an html file which has both English and Arabic text. I need to delete all the Arabic texts from the file.

I observed that all the urdu texts come inside a <p> or a <div> tag with the attribute style="direction: rtl;" which makes the Arabic text appear right to left.

stripped example:

<P style="direction:rtl">
<SPAN style="font-family:'serif'>Arabic Text: ������������</SPAN>
</P>

So I need to find all the tag blocks with the attribute style="direction:rtl" (I don't know much html, and I am not very sure it is called an attribute) and delete them. Tried Aptana Studio but I found it couldn't do the job either (please tell me if I missed a trick).

I tried to do it with Firebug, but couldn't figure it out (never used it before).

So can this be done with Firebug? Or, is there an HTML editor which'll let me search and list blocks with specific tags or attribute values?

Any help will be greatly appreciated.

1

There are 1 answers

1
Brock Adams On BEST ANSWER

There are all kinds of ways to do this; a Python program would be perhaps best if this was an ongoing operation.

But, since this is a Firebug question and stated to be a one-time operation, here's how to do it using Firebug and jQuery:

  1. Make a backup copy of the original files.

  2. Open the file in Firefox.

  3. If using Noscript, or similar, make sure JavaScript is temporarily enabled for local files.

  4. Open the Firebug console.

  5. Reload the page if the console says it's needed.

  6. Open the large command-line/command-box.

  7. Paste in the following code:

    var scriptNode          = document.createElement ("script");
    scriptNode.setAttribute ("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js");
    document.body.appendChild (scriptNode);
    
    function KilltheCrud ()
    {
        jQuery('p[style*="rtl"]').remove ();
        jQuery('div[style*="rtl"]').remove ();
    }
    
    //-- Delay to allow jQuery to load and initialize.
    setTimeout (KilltheCrud, 444); //-- Adjust time delay if necessary
    


  8. Press "Run".

  9. The file should now be stripped, save the modified file.

  10. Done! Repeat for the other files.