replace question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rauan Maemirov

    replace question

    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"><p aram name="movie" value="URL"></
    param><param name="wmode" value="transpar ent"></param><embed src="URL"
    type="applicati on/x-shockwave-flash" wmode="transpar ent" 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

    #2
    Re: replace question

    On May 10, 9:37 pm, Rauan Maemirov <rauan1...@gmai l.comwrote:
    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"><p aram name="movie" value="URL"></
    param><param name="wmode" value="transpar ent"></param><embed src="URL"
    type="applicati on/x-shockwave-flash" wmode="transpar ent" 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"><p aram name="movie" value="URL"></
    param><param name="wmode" value="transpar ent"></param><embed src="URL"
    type="applicati on/x-shockwave-flash" wmode="transpar ent" width="425"
    height="355"></embed></object>

    with

    <object width="425" height="355"><p aram name="movie" value="URL"></
    param><param name="wmode" value="transpar ent"></param><img src="URL"
    type="applicati on/x-shockwave-flash" wmode="transpar ent" width="425"
    height="355"></embed></object>

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: replace question

      Rauan Maemirov wrote:
      I tried to do it myself, but all I did is to replaced
      >
      <object width="425" height="355"><p aram name="movie" value="URL"></
      param><param name="wmode" value="transpar ent"></param><embed src="URL"
      type="applicati on/x-shockwave-flash" wmode="transpar ent" width="425"
      height="355"></embed></object>
      >
      with
      >
      <object width="425" height="355"><p aram name="movie" value="URL"></
      param><param name="wmode" value="transpar ent"></param><img src="URL"
      type="applicati on/x-shockwave-flash" wmode="transpar ent" 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.prototyp e.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

      Comment

      • Rauan Maemirov

        #4
        Re: replace question

        On May 12, 4:43 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
        wrote:
        Rauan Maemirov wrote:
        I tried to do it myself, but all I did is to replaced
        >
        <object width="425" height="355"><p aram name="movie" value="URL"></
        param><param name="wmode" value="transpar ent"></param><embed src="URL"
        type="applicati on/x-shockwave-flash" wmode="transpar ent" width="425"
        height="355"></embed></object>
        >
        with
        >
        <object width="425" height="355"><p aram name="movie" value="URL"></
        param><param name="wmode" value="transpar ent"></param><img src="URL"
        type="applicati on/x-shockwave-flash" wmode="transpar ent" 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.prototyp e.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"><p aram name="movie"
        value="http://www.youtube.com/v/yVjzd320gew&hl= en"></param><param
        name="wmode" value="transpar ent"></param><embed src="http://
        www.youtube.com/v/yVjzd320gew&hl= en" type="applicati on/x-shockwave-
        flash" wmode="transpar ent" 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...

        Comment

        • Rauan Maemirov

          #5
          Re: replace question

          On May 12, 4:43 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
          wrote:
          Rauan Maemirov wrote:
          I tried to do it myself, but all I did is to replaced
          >
          <object width="425" height="355"><p aram name="movie" value="URL"></
          param><param name="wmode" value="transpar ent"></param><embed src="URL"
          type="applicati on/x-shockwave-flash" wmode="transpar ent" width="425"
          height="355"></embed></object>
          >
          with
          >
          <object width="425" height="355"><p aram name="movie" value="URL"></
          param><param name="wmode" value="transpar ent"></param><img src="URL"
          type="applicati on/x-shockwave-flash" wmode="transpar ent" 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.prototyp e.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.

          Comment

          • Thomas 'PointedEars' Lahn

            #6
            Re: replace question

            [trimmed attribution novel]

            Rauan Maemirov wrote:
            Thomas 'PointedEars' Lahn wrote:
            >Rauan Maemirov wrote:
            >>I tried to do it myself, but all I did is to replaced
            >><object width="425" height="355"><p aram name="movie" value="URL"></
            >>param><para m name="wmode" value="transpar ent"></param><embed src="URL"
            >>type="applica tion/x-shockwave-flash" wmode="transpar ent" width="425"
            >>height="355"> </embed></object>
            >>with
            >><object width="425" height="355"><p aram name="movie" value="URL"></
            >>param><para m name="wmode" value="transpar ent"></param><img src="URL"
            >>type="applica tion/x-shockwave-flash" wmode="transpar ent" 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.prototyp e.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"><p aram name="movie"
            value="http://www.youtube.com/v/yVjzd320gew&hl= en"></param><param
            name="wmode" value="transpar ent"></param><embed src="http://
            www.youtube.com/v/yVjzd320gew&hl= en" type="applicati on/x-shockwave-
            flash" wmode="transpar ent" 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

            Comment

            • Rauan Maemirov

              #7
              Re: replace question

              On May 12, 4:58 pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
              wrote:
              [trimmed attribution novel]
              >
              >
              >
              Rauan Maemirov wrote:
              Thomas 'PointedEars' Lahn wrote:
              Rauan Maemirov wrote:
              >I tried to do it myself, but all I did is to replaced
              ><object width="425" height="355"><p aram name="movie" value="URL"></
              >param><param name="wmode" value="transpar ent"></param><embed src="URL"
              >type="applicat ion/x-shockwave-flash" wmode="transpar ent" width="425"
              >height="355" ></embed></object>
              >with
              ><object width="425" height="355"><p aram name="movie" value="URL"></
              >param><param name="wmode" value="transpar ent"></param><img src="URL"
              >type="applicat ion/x-shockwave-flash" wmode="transpar ent" 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.prototyp e.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"><p aram name="movie"
              value="http://www.youtube.com/v/yVjzd320gew&hl= en"></param><param
              name="wmode" value="transpar ent"></param><embed src="http://
              www.youtube.com/v/yVjzd320gew&hl= en" type="applicati on/x-shockwave-
              flash" wmode="transpar ent" 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>...<emb ed src="title".../></
              object>...<obje ct>...<embed ... width="455".../></object>

              Comment

              Working...