replace question

R

Rauan Maemirov

Hi, all. I'm trying to replace <object ...><embed... /></object> with
<img> tag and vice-verse. It's like implementation of media plugin of
Tiny MCE editor. I tried to watch their code, but it's too complicated
and has a lot of unnecessary code. And the main reason is i'm weak in
javascript rewriting. :)

I need just simple rewrite for e.g. this

<object width="425" height="355"><param name="movie" value="URL"></
param><param name="wmode" value="transparent"></param><embed src="URL"
type="application/x-shockwave-flash" wmode="transparent" width="425"
height="355"></embed></object>

<img width="425" height="355" title="src:'URL'">.

param tags can be omitted.

Could anybody help me? Thanks in advance.
 
R

Rauan Maemirov

Hi, all. I'm trying to replace <object ...><embed... /></object> with
<img> tag and vice-verse. It's like implementation of media plugin of
Tiny MCE editor. I tried to watch their code, but it's too complicated
and has a lot of unnecessary code. And the main reason is i'm weak in
javascript rewriting. :)

I need just simple rewrite for e.g. this

<object width="425" height="355"><param name="movie" value="URL"></
param><param name="wmode" value="transparent"></param><embed src="URL"
type="application/x-shockwave-flash" wmode="transparent" width="425"
height="355"></embed></object>

<img width="425" height="355" title="src:'URL'">.

param tags can be omitted.

Could anybody help me? Thanks in advance.

I tried to do it myself, but all I did is to replaced

<object width="425" height="355"><param name="movie" value="URL"></
param><param name="wmode" value="transparent"></param><embed src="URL"
type="application/x-shockwave-flash" wmode="transparent" width="425"
height="355"></embed></object>

with

<object width="425" height="355"><param name="movie" value="URL"></
param><param name="wmode" value="transparent"></param><img src="URL"
type="application/x-shockwave-flash" wmode="transparent" width="425"
height="355"></embed></object>
 
T

Thomas 'PointedEars' Lahn

Rauan said:
I tried to do it myself, but all I did is to replaced

<object width="425" height="355"><param name="movie" value="URL"></
param><param name="wmode" value="transparent"></param><embed src="URL"
type="application/x-shockwave-flash" wmode="transparent" width="425"
height="355"></embed></object>

with

<object width="425" height="355"><param name="movie" value="URL"></
param><param name="wmode" value="transparent"></param><img src="URL"
type="application/x-shockwave-flash" wmode="transparent" width="425"
height="355"></embed></object>

1. My tests indicate that a Flash movie is not played by an `img' element,
so replacing the object-embed element combination would be futile, even
though the `embed' element is proprietary (and therefore not Valid).

2. Using client-side scripting to correct markup is the wrong approach
as it does not need to be available.

3. If necessary, you should rewrite the editor instead.

4. FWIW, in Eclipse I would have used the following parameters:

Search for:
(?s)<object\s+.*?<embed\s+.*?(src=".+?")[^>]*?\s+(width=.+?>)</embed></object>

Replace with:
<img $1 $2 alt="">

(Don't forget the `alt' attribute, give it a descriptive value if
possible/applicable!)

BTW, QuickREx again came in handy in finding that out:
<http://www.bastian-bergerhoff.com/eclipse/features/web/QuickREx/toc.html>

5. With the exception of `(?s)', which can be worked around with
`(?:.|[\r\n])' instead of `.', this should also work with
String.prototype.replace() in JavaScript 1.5+ (Mozilla/5.0),
JScript 5.5+ (IE 5.5+), ECMAScript Ed. 3+.

6. Replacing content this way might require using `innerHTML', a
proprietary property that should be avoided in favor of DOM 2 scripting.


HTH

PointedEars
 
R

Rauan Maemirov

Rauan said:
I tried to do it myself, but all I did is to replaced
<object width="425" height="355"><param name="movie" value="URL"></
param><param name="wmode" value="transparent"></param><embed src="URL"
type="application/x-shockwave-flash" wmode="transparent" width="425"
height="355"></embed></object>

<object width="425" height="355"><param name="movie" value="URL"></
param><param name="wmode" value="transparent"></param><img src="URL"
type="application/x-shockwave-flash" wmode="transparent" width="425"
height="355"></embed></object>

1. My tests indicate that a Flash movie is not played by an `img' element,
   so replacing the object-embed element combination would be futile, even
   though the `embed' element is proprietary (and therefore not Valid)..

2. Using client-side scripting to correct markup is the wrong approach
   as it does not need to be available.

3. If necessary, you should rewrite the editor instead.

4. FWIW, in Eclipse I would have used the following parameters:

Search for:
(?s)<object\s+.*?<embed\s+.*?(src=".+?")[^>]*?\s+(width=.+?>)</embed></object>

Replace with:
<img $1 $2 alt="">

(Don't forget the `alt' attribute, give it a descriptive value if
possible/applicable!)

BTW, QuickREx again came in handy in finding that out:
<http://www.bastian-bergerhoff.com/eclipse/features/web/QuickREx/toc.html>

5. With the exception of `(?s)', which can be worked around with
   `(?:.|[\r\n])' instead of `.', this should also work with
   String.prototype.replace() in JavaScript 1.5+ (Mozilla/5.0),
   JScript 5.5+ (IE 5.5+), ECMAScript Ed. 3+.

6. Replacing content this way might require using `innerHTML', a
   proprietary property that should be avoided in favor of DOM 2 scripting.

HTH

PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee

I tried your regex:


var flash = '<object width="425" height="355"><param name="movie"
value="
"></param><param
name="wmode" value="transparent"></param><embed src="http://
www.youtube.com/v/yVjzd320gew&hl=en" type="application/x-shockwave-
flash" wmode="transparent" width="425" height="355"></embed></
object>';

flash = flash.replace('(?s)<object\s+.*?<embed\s+.*?(src=".+?")[^>]*?\s
+(width=.+?>)</embed></object>', '<img $1 $2 alt=""> ');

It returns the same object...
 
R

Rauan Maemirov

Rauan said:
I tried to do it myself, but all I did is to replaced
<object width="425" height="355"><param name="movie" value="URL"></
param><param name="wmode" value="transparent"></param><embed src="URL"
type="application/x-shockwave-flash" wmode="transparent" width="425"
height="355"></embed></object>

<object width="425" height="355"><param name="movie" value="URL"></
param><param name="wmode" value="transparent"></param><img src="URL"
type="application/x-shockwave-flash" wmode="transparent" width="425"
height="355"></embed></object>

1. My tests indicate that a Flash movie is not played by an `img' element,
   so replacing the object-embed element combination would be futile, even
   though the `embed' element is proprietary (and therefore not Valid)..

2. Using client-side scripting to correct markup is the wrong approach
   as it does not need to be available.

3. If necessary, you should rewrite the editor instead.

4. FWIW, in Eclipse I would have used the following parameters:

Search for:
(?s)<object\s+.*?<embed\s+.*?(src=".+?")[^>]*?\s+(width=.+?>)</embed></object>

Replace with:
<img $1 $2 alt="">

(Don't forget the `alt' attribute, give it a descriptive value if
possible/applicable!)

BTW, QuickREx again came in handy in finding that out:
<http://www.bastian-bergerhoff.com/eclipse/features/web/QuickREx/toc.html>

5. With the exception of `(?s)', which can be worked around with
   `(?:.|[\r\n])' instead of `.', this should also work with
   String.prototype.replace() in JavaScript 1.5+ (Mozilla/5.0),
   JScript 5.5+ (IE 5.5+), ECMAScript Ed. 3+.

6. Replacing content this way might require using `innerHTML', a
   proprietary property that should be avoided in favor of DOM 2 scripting.

HTH

PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee

I tried to use QuickREx (application, that U noticed) and indeed, it
show matches correct. But in javascript it doesn't replace my text at
all.
 
T

Thomas 'PointedEars' Lahn

[trimmed attribution novel]

Rauan said:
Thomas said:
Rauan said:
I tried to do it myself, but all I did is to replaced
<object width="425" height="355"><param name="movie" value="URL"></
param><param name="wmode" value="transparent"></param><embed src="URL"
type="application/x-shockwave-flash" wmode="transparent" width="425"
height="355"></embed></object>
with
<object width="425" height="355"><param name="movie" value="URL"></
param><param name="wmode" value="transparent"></param><img src="URL"
type="application/x-shockwave-flash" wmode="transparent" width="425"
height="355"></embed></object>
[...]
4. FWIW, in Eclipse I would have used the following parameters:

Search for:
(?s)<object\s+.*?<embed\s+.*?(src=".+?")[^>]*?\s+(width=.+?>)</embed></object>

Replace with:
<img $1 $2 alt="">

(Don't forget the `alt' attribute, give it a descriptive value if
possible/applicable!)

BTW, QuickREx again came in handy in finding that out:
<http://www.bastian-bergerhoff.com/eclipse/features/web/QuickREx/toc.html>

5. With the exception of `(?s)', which can be worked around with
`(?:.|[\r\n])' instead of `.', this should also work with
String.prototype.replace() in JavaScript 1.5+ (Mozilla/5.0),
JScript 5.5+ (IE 5.5+), ECMAScript Ed. 3+.
[...]

I tried your regex:

var flash = '<object width="425" height="355"><param name="movie"
value="
"></param><param
name="wmode" value="transparent"></param><embed src="http://
www.youtube.com/v/yVjzd320gew&hl=en" type="application/x-shockwave-
flash" wmode="transparent" width="425" height="355"></embed></
object>';

flash = flash.replace('(?s)<object\s+.*?<embed\s+.*?(src=".+?")[^>]*?\s
+(width=.+?>)</embed></object>', '<img $1 $2 alt=""> ');

It returns the same object...

It returns a primitive string value, not an object. It returns the same
string it is being applied to because you have not passed a RegExp object
but a string as argument, and you have not read my posting thoroughly
enough. If you had quoted properly, you would have been forced to re-read
before replying and had probably not made this silly mistake.


PointedEars
 
R

Rauan Maemirov

[trimmed attribution novel]



Rauan said:
Thomas said:
Rauan Maemirov wrote:
I tried to do it myself, but all I did is to replaced
<object width="425" height="355"><param name="movie" value="URL"></
param><param name="wmode" value="transparent"></param><embed src="URL"
type="application/x-shockwave-flash" wmode="transparent" width="425"
height="355"></embed></object>
with
<object width="425" height="355"><param name="movie" value="URL"></
param><param name="wmode" value="transparent"></param><img src="URL"
type="application/x-shockwave-flash" wmode="transparent" width="425"
height="355"></embed></object>
[...]
4. FWIW, in Eclipse I would have used the following parameters:
Search for:
(?s)<object\s+.*?<embed\s+.*?(src=".+?")[^>]*?\s+(width=.+?>)</embed></object>
Replace with:
<img $1 $2 alt="">
(Don't forget the `alt' attribute, give it a descriptive value if
possible/applicable!)
BTW, QuickREx again came in handy in finding that out:
<http://www.bastian-bergerhoff.com/eclipse/features/web/QuickREx/toc.html>
5. With the exception of `(?s)', which can be worked around with
   `(?:.|[\r\n])' instead of `.', this should also work with
   String.prototype.replace() in JavaScript 1.5+ (Mozilla/5.0),
   JScript 5.5+ (IE 5.5+), ECMAScript Ed. 3+.
[...]
I tried your regex:
var flash = '<object width="425" height="355"><param name="movie"
value="
"></param><param
name="wmode" value="transparent"></param><embed src="http://
www.youtube.com/v/yVjzd320gew&hl=en" type="application/x-shockwave-
flash" wmode="transparent" width="425" height="355"></embed></
object>';
flash = flash.replace('(?s)<object\s+.*?<embed\s+.*?(src=".+?")[^>]*?\s
+(width=.+?>)</embed></object>', '<img $1 $2 alt=""> ');
It returns the same object...

It returns a primitive string value, not an object.  It returns the same
string it is being applied to because you have not passed a RegExp object
but a string as argument, and you have not read my posting thoroughly
enough.  If you had quoted properly, you would have been forced to re-read
before replying and had probably not made this silly mistake.

PointedEars
--
    realism:    HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness:    XHTML 1.1 as application/xhtml+xml
                                                    -- Bjoern Hoehrmann

Thanks, Thomas. I found my mistake. But there is the next trouble.
What if I have more than one <object>'s. It returns only one image. I
need to construct regexp the way, that it will replace only one
node(tag). E.g. <object>...<embed src="title".../></
object>...<object>...<embed ... width="455".../></object>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,696
Latest member
BarbraOLog

Latest Threads

Top