problem with html entity in string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Juan R. =?iso-8859-1?q?Gonz=E1lez-=C1lvarez?=

    problem with html entity in string


    I want to substitute "\(" by "("

    i have tried

    content = content.replace (/\\\(/g, "(");

    content = content.replace (/\\\(/g, unescape("%26") + "#40;");

    content = content.replace (/\\\(/g, "\&" + "#40;");


    In all three cases the resulting HTML is "("

    How do i force "&" to be "&" instead "&"?

    --

  • Henry

    #2
    Re: problem with html entity in string

    On May 8, 1:44 pm, "Juan R." González-Álvarez wrote:
    I want to substitute "\(" by "("
    >
    i have tried
    >
    content = content.replace (/\\\(/g, "(");
    >
    content = content.replace (/\\\(/g, unescape("%26") + "#40;");
    >
    content = content.replace (/\\\(/g, "\&" + "#40;");
    >
    In all three cases the resulting HTML is "("
    The result of the javascript - replace - method is a javascript string
    primitive, not HTML. If the input string is the backslash character
    followed by the opening parenthesis character then the output string
    is _never_ "(" . So the odds are that either you have omitted
    context that is significant to your problem of your problem is down-
    stream of your use of the - replace - method (or possibly your input
    strings are not what you think they are).
    How do i force "&" to be "&" instead "&"?
    There is nothing to force until the cause and effect relationship has
    been identified, and it is not in the - replace - method calls. Try
    posting a minimal text-case page that demonstrates the effects you
    observe in isolation.

    Comment

    • Juan R. =?iso-8859-1?q?Gonz=E1lez-=C1lvarez?=

      #3
      Re: problem with html entity in string

      Henry wrote on Thu, 08 May 2008 06:38:38 -0700:
      On May 8, 1:44 pm, "Juan R." González-Álvarez wrote:
      >I want to substitute "\(" by "("
      >>
      >i have tried
      >>
      > content = content.replace (/\\\(/g, "(");
      >>
      > content = content.replace (/\\\(/g, unescape("%26") + "#40;");
      >>
      > content = content.replace (/\\\(/g, "\&" + "#40;");
      >>
      >In all three cases the resulting HTML is "("
      >
      The result of the javascript - replace - method is a javascript string
      primitive, not HTML.
      Exactly i want to substitute a string by other.
      If the input string is the backslash character
      followed by the opening parenthesis character then the output string is
      _never_ "(" .
      But i got just that output in end page. Is then the problem in the
      createTextNode method (see below)?
      So the odds are that either you have omitted
      context that is significant to your problem of your problem is down-
      stream of your use of the - replace - method (or possibly your input
      strings are not what you think they are).
      E.g. the input string is "\(n\)"

      and the result i got is "(n&amp ;#41;"

      but it would be "(n&#41 ;"
      >How do i force "&" to be "&" instead "&"?
      >
      There is nothing to force until the cause and effect relationship has
      been identified, and it is not in the - replace - method calls. Try
      posting a minimal text-case page that demonstrates the effects you
      observe in isolation.
      Ok, try with this to see the script in action



      The code is at



      the part is at the end /* CANONML TO HTML */



      --

      Comment

      • Juan R. =?iso-8859-1?q?Gonz=E1lez-=C1lvarez?=

        #4
        Re: problem with html entity in string

        "Juan R." González-Álvarez wrote on Thu, 08 May 2008 16:51:29 +0200:
        Henry wrote on Thu, 08 May 2008 06:38:38 -0700:
        >
        >On May 8, 1:44 pm, "Juan R." González-Álvarez wrote:
        >>I want to substitute "\(" by "("
        >>>
        >>i have tried
        >>>
        >> content = content.replace (/\\\(/g, "(");
        >>>
        >> content = content.replace (/\\\(/g, unescape("%26") + "#40;");
        >>>
        >> content = content.replace (/\\\(/g, "\&" + "#40;");
        >>>
        >>In all three cases the resulting HTML is "("
        >>
        >The result of the javascript - replace - method is a javascript string
        >primitive, not HTML.
        >
        Exactly i want to substitute a string by other.
        >
        >If the input string is the backslash character followed by the opening
        >parenthesis character then the output string is _never_ "(" .
        >
        But i got just that output in end page. Is then the problem in the
        createTextNode method (see below)?
        Ok i think that Henry is right and the problem is not in replace but in
        the posterior createTextNode method when it finds the "&" in the string
        and escape like "&" when generating the HTML.

        What would be more easy way to fix that?


        --

        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: problem with html entity in string

          Juan R. González-Álvarez wrote:
          Ok i think that Henry is right and the problem is not in replace but in
          the posterior createTextNode method when it finds the "&" in the string
          and escape like "&" when generating the HTML.
          >
          What would be more easy way to fix that?
          ISTM there is no problem but a misconception of yours that needs fixing.
          The DOM2Core:Docume nt::createTextN ode() method that you presumably speak
          of takes a DOMString value as argument, supported by a primitive string
          value in ECMAScript implementations per the DOM 2 Core Specifications'
          ECMAScript Binding section.

          document.create TextNode("&")

          is supposed to create a TextNode object[1] with the content

          &

          and return a reference to it which is represented in HTML by

          &

          among other entity references. Maybe you think that

          <a href="http://foo.example/?bar=42&amp;baz =23">...</a>

          would not be correct in which case you should read on SGML and HTML, and
          validate your markup (you should do that anyway) because you were wrong then.

          See also:



          W3C's easy-to-use markup validation service, based on SGML and XML parsers.



          PointedEars
          -----------
          [1] "Foo object" is a short-hand term for "an object that implements the
          Foo interface"
          --
          var bugRiddenCrashP ronePieceOfJunk = (
          navigator.userA gent.indexOf('M SIE 5') != -1
          && navigator.userA gent.indexOf('M ac') != -1
          ) // Plone, register_functi on.js:16

          Comment

          • Juan R. =?iso-8859-1?q?Gonz=E1lez-=C1lvarez?=

            #6
            Re: problem with html entity in string (solved)

            "Juan R." González-Álvarez wrote on Thu, 08 May 2008 14:44:59 +0200:
            I want to substitute "\(" by "&#40;"
            >
            i have tried
            >
            content = content.replace (/\\\(/g, "&#40;");
            >
            content = content.replace (/\\\(/g, unescape("%26") + "#40;");
            >
            content = content.replace (/\\\(/g, "\&" + "#40;");
            >
            >
            In all three cases the resulting HTML is "&amp;#40;"
            >
            How do i force "&" to be "&" instead "&amp;"?
            Yes, the problem was on the CreateTextNode and not in the replace method.
            I had simply adapted a previous code for CanonML 0.6 to CanonML 0.7 and
            then introduced replace.

            I have eliminated replace method introduced a next token variable and
            modified the nested if to go over escaping backslashes. It is now
            working. See



            Place your mouse over an equation and you can see original code.

            Thanks Henry and Thomas.


            --

            Comment

            Working...