Connecting Tech Pros Worldwide Forums | Help | Site Map

replace question

Rauan Maemirov
Guest
 
Posts: n/a
#1: Jun 27 '08
Hi, all. I'm trying to replace <object ...><embed... /></objectwith
<imgtag 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.

Rauan Maemirov
Guest
 
Posts: n/a
#2: Jun 27 '08

re: replace question


On May 10, 9:37*pm, Rauan Maemirov <rauan1...@gmail.comwrote:
Quote:
Hi, all. I'm trying to replace <object ...><embed... /></objectwith
<imgtag 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>
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#3: Jun 27 '08

re: replace question


Rauan Maemirov wrote:
Quote:
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
--
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
Rauan Maemirov
Guest
 
Posts: n/a
#4: Jun 27 '08

re: replace question


On May 12, 4:43*am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
Quote:
Rauan Maemirov wrote:
Quote:
I tried to do it myself, but all I did is to replaced
>
Quote:
<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>
>
Quote:
with
>
Quote:
<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="http://www.youtube.com/v/yVjzd320gew&hl=en"></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...
Rauan Maemirov
Guest
 
Posts: n/a
#5: Jun 27 '08

re: replace question


On May 12, 4:43*am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
Quote:
Rauan Maemirov wrote:
Quote:
I tried to do it myself, but all I did is to replaced
>
Quote:
<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>
>
Quote:
with
>
Quote:
<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.
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#6: Jun 27 '08

re: replace question


[trimmed attribution novel]

Rauan Maemirov wrote:
Quote:
Thomas 'PointedEars' Lahn wrote:
Quote:
>Rauan Maemirov wrote:
Quote:
>>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="http://www.youtube.com/v/yVjzd320gew&hl=en"></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
Rauan Maemirov
Guest
 
Posts: n/a
#7: Jun 27 '08

re: replace question


On May 12, 4:58*pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
Quote:
[trimmed attribution novel]
>
>
>
Rauan Maemirov wrote:
Quote:
Thomas 'PointedEars' Lahn wrote:
Quote:
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:
>
Quote:
Quote:
Search for:
(?s)<object\s+.*?<embed\s+.*?(src=".+?")[^>]*?\s+(width=.+?>)</embed></object>
>
Quote:
Quote:
Replace with:
<img $1 $2 alt="">
>
Quote:
Quote:
(Don't forget the `alt' attribute, give it a descriptive value if
possible/applicable!)
>
Quote:
Quote:
BTW, QuickREx again came in handy in finding that out:
<http://www.bastian-bergerhoff.com/eclipse/features/web/QuickREx/toc.html>
>
Quote:
Quote:
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+.
[...]
>
Quote:
I tried your regex:
>
Quote:
var flash = '<object width="425" height="355"><param name="movie"
value="http://www.youtube.com/v/yVjzd320gew&hl=en"></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>';
>
Quote:
flash = flash.replace('(?s)<object\s+.*?<embed\s+.*?(src=" .+?")[^>]*?\s
+(width=.+?>)</embed></object>', '<img $1 $2 alt=""');
>
Quote:
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>
Closed Thread


Similar JavaScript / Ajax / DHTML bytes