Author Topic: Remove Image Borders  (Read 7562 times)

altosax

  • Sr. Member
  • ****
  • Posts: 328
    • ICQ Messenger -
    • AOL Instant Messenger -
    • Yahoo Instant Messenger -
    • View Profile
    • http://
    • Email
Remove Image Borders
« Reply #15 on: August 22, 2002, 11:04:52 AM »
hi hp,
i'm sorry, but i hadn't read first your answer to jor. so you need both to replace the border attribute when different from 0 and add border=0 when missing.
well, your filter works as expected but you can merge some option to make it simpler:

Name = "Remove Image Borders v2.2"
Active = TRUE
Multi = TRUE
URL = "$TYPE(htm)"
Bounds = "<im(g|age)s*>"
Limit = 300
Match = "border=$AV(*)2$SET(1=border="0")"
        "|>$SET(1= border="0">)"
Replace = "12"

altosax.

 
 

TEggHead

  • Jr. Member
  • **
  • Posts: 93
    • ICQ Messenger - 21893433
    • AOL Instant Messenger -
    • Yahoo Instant Messenger - eljarec
    • View Profile
    • Email
Remove Image Borders
« Reply #16 on: August 22, 2002, 12:52:23 PM »
quote:
Match = "border=$AV(*)2$SET(1=border="0")|>$SET(1= border="0">)"


Aren't we overlooking a small thing here? this type of filters may follow a common logic, but that is certainly not the if-then-else logic but rather a no-matter-what logic, not? I mean, this is simply a case of
if it matches, fine, replace it, otherwise fine too, just insert it, so both branches end up doing the same thing, very atypical for an if-then-else structure, in fact quite the opposite, this looks more like an assertion

basically, the filter will need to always match (no matter if the attribute is there, the replacement is always inserted) so we do not need to complicate the match with all kinds of exceptions coz there's only one exception basically, the attribute not being present...

based on that I found the following format to always work

Match = "<TAG( ATTRIBUTE=$AV(*)|) 1>"
Replace = "<TAG ATTRIBUTE=MyValue 1>"

HPGuru
quote:

Can anyone think of a way to make it fail to match in the bounds match if border="0" already exists?


This would be the same test to exclude a replacement from being matched by the filter again...something like

Bounds = "<TAG(^*ATTRIBUTE=MyValue)*>"




Edited by - TEggHead on 22 Aug 2002  14:06:14
 

hpguru

  • Sr. Member
  • ****
  • Posts: 257
    • ICQ Messenger -
    • AOL Instant Messenger -
    • Yahoo Instant Messenger -
    • View Profile
    • http://lightning.prohosting.com/~hpguru/
    • Email
Remove Image Borders
« Reply #17 on: August 22, 2002, 05:47:37 PM »
Thank you altosax and tegghead. Those filters are a lot better and I learned a few tricks in the procces. What I've opted for however is to globally set the border attribute to "0" via my injected style sheet.

quote:

Aren't we overlooking a small thing here? this type of filters may follow a common logic, but that is certainly not the if-then-else logic but rather a no-matter-what logic, not?



Actually the implied logical structure is very similar to the IF-THEN-ELSE stuctures used in high level computer languages or like a CASE structure which is

CASE
(IF) test-clause_1 THEN true-clause_1
(IF) test-clause_2 THEN true-clause_2
...
(IF) test-clause_n THEN true-clause_n
default-clause
END

This runs through the (IF)-THEN tests till it finds a true result. If all tests are false it can process an optional default-clause or just fail the entire series of tests and exit without doing anything.

Years ago I wrote assembler code for HPs advanced scientific calculators such as the HP48 SX and GX series. Saturn Assembler being a low level machine language had no higher level branching structures but you could roll your own. It all depended on how you manipulated register/stack data and how you employed gotos and gosubs following simple bit and flag tests. So an IF-THEN-ELSE structure could be constructed as an implied meta structure but it wasn't actually there. Even so the code behaved as if it was there. This filter I posted has the same sort of *implied meta structure* that isn't really there but you get the same result you would if it was present.

Facing each other,
a thousand miles apart.


Edited by - hpguru on 22 Aug 2002  18:48:40
Facing each other,
a thousand miles apart.

altosax

  • Sr. Member
  • ****
  • Posts: 328
    • ICQ Messenger -
    • AOL Instant Messenger -
    • Yahoo Instant Messenger -
    • View Profile
    • http://
    • Email
Remove Image Borders
« Reply #18 on: August 22, 2002, 06:37:06 PM »
tegghead wrote:

quote:

based on that I found the following format to always work

Match = "<TAG( ATTRIBUTE=$AV(*)|) 1>"
Replace = "<TAG ATTRIBUTE=MyValue 1>"




using a slightly modified code, i think this structure could be used EVERY TIME we need to replace or set an attribute value:

Bounds = "<tags*>"
Match = "(1attribute=$AV(*)|1)2"
Replace = "1attribute="my_value"2"

i had need to modify a little the tegghead structure to take in account all variations, with a particular attention to spaces between attributes.
the variable is just to consume parens when the attribute we are searching for is not present.

altosax.

 
 

hpguru

  • Sr. Member
  • ****
  • Posts: 257
    • ICQ Messenger -
    • AOL Instant Messenger -
    • Yahoo Instant Messenger -
    • View Profile
    • http://lightning.prohosting.com/~hpguru/
    • Email
Remove Image Borders
« Reply #19 on: August 22, 2002, 06:51:45 PM »
Altosax,

That filter will place the desired attribute outside the tag in the event the attribute was missing.

Facing each other,
a thousand miles apart.
Facing each other,
a thousand miles apart.

altosax

  • Sr. Member
  • ****
  • Posts: 328
    • ICQ Messenger -
    • AOL Instant Messenger -
    • Yahoo Instant Messenger -
    • View Profile
    • http://
    • Email
Remove Image Borders
« Reply #20 on: August 22, 2002, 06:57:39 PM »
you are right, this fix it:

Bounds = "<tags*>"
Match = "(1attribute=$AV(*)|1)2>"
Replace = "1attribute="my_value"2>"

altosax.

 
 

altosax

  • Sr. Member
  • ****
  • Posts: 328
    • ICQ Messenger -
    • AOL Instant Messenger -
    • Yahoo Instant Messenger -
    • View Profile
    • http://
    • Email
Remove Image Borders
« Reply #21 on: August 22, 2002, 07:01:49 PM »
a better way:

Bounds = "<tags*>"
Match = "1(attribute=$AV(*)2|)>"
Replace = "1attribute="my_value"2>"

i think this is the state of the art for this kind of filters

altosax.

 
 

hpguru

  • Sr. Member
  • ****
  • Posts: 257
    • ICQ Messenger -
    • AOL Instant Messenger -
    • Yahoo Instant Messenger -
    • View Profile
    • http://lightning.prohosting.com/~hpguru/
    • Email
Remove Image Borders
« Reply #22 on: August 22, 2002, 07:12:22 PM »
That along with teggheads bounds match so the filter won't match if the desired attribute value already exists.

<TAG(^*ATTRIBUTE="MY_VALUE")*>

Facing each other,
a thousand miles apart.
Facing each other,
a thousand miles apart.

hpguru

  • Sr. Member
  • ****
  • Posts: 257
    • ICQ Messenger -
    • AOL Instant Messenger -
    • Yahoo Instant Messenger -
    • View Profile
    • http://lightning.prohosting.com/~hpguru/
    • Email
Remove Image Borders
« Reply #23 on: August 22, 2002, 07:17:46 PM »
And here is an improvement on that.

<TAG(^*ATTRIBUTE=("|)MY_VALUE("|))*>

Facing each other,
a thousand miles apart.
Facing each other,
a thousand miles apart.

hpguru

  • Sr. Member
  • ****
  • Posts: 257
    • ICQ Messenger -
    • AOL Instant Messenger -
    • Yahoo Instant Messenger -
    • View Profile
    • http://lightning.prohosting.com/~hpguru/
    • Email
Remove Image Borders
« Reply #24 on: August 22, 2002, 07:21:54 PM »
Better still

<TAG(^*ATTRIBUTE=$AV(MY_VALUE))*>

Facing each other,
a thousand miles apart.
Facing each other,
a thousand miles apart.

hpguru

  • Sr. Member
  • ****
  • Posts: 257
    • ICQ Messenger -
    • AOL Instant Messenger -
    • Yahoo Instant Messenger -
    • View Profile
    • http://lightning.prohosting.com/~hpguru/
    • Email
Remove Image Borders
« Reply #25 on: August 22, 2002, 07:40:26 PM »
May I recommend this replacement instead?

Replace = "1 attribute="my_value"2>"

Facing each other,
a thousand miles apart.
Facing each other,
a thousand miles apart.

TEggHead

  • Jr. Member
  • **
  • Posts: 93
    • ICQ Messenger - 21893433
    • AOL Instant Messenger -
    • Yahoo Instant Messenger - eljarec
    • View Profile
    • Email
Remove Image Borders
« Reply #26 on: August 23, 2002, 12:15:24 AM »
quote:

i think this structure could be used EVERY TIME we need to replace or set an attribute value:


It is just another form of the basic test for 'something or nothing' as described in "Tips And Tricks.html" ;)