HTML Diff problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aaron Gray

    HTML Diff problem

    Hi,

    I am working on an HTML WYSISYG Wiki and need to display a diff page like
    WikiPedia does if two people edit a file at the same time to give the second
    user the diff. Basically with additions in red and deletions in red strike
    though.

    There seem to be several in Perl and Python and many diff programs which all
    seem to be line based and work on text written in PHP.

    So I am after either existing PHP code to do an HTML diff or some help
    forming an algorithm todo this.

    Many thanks in advance,

    Aaron


  • C. (http://symcbean.blogspot.com/)

    #2
    Re: HTML Diff problem

    On 22 Oct, 18:54, "Aaron Gray" <ang.use...@gma il.comwrote:
    Hi,
    >
    I am working on an HTML WYSISYG Wiki and need to display a diff page like
    WikiPedia does if two people edit a file at the same time to give the second
    user the diff. Basically with additions in red and deletions in red strike
    though.
    >
    There seem to be several in Perl and Python and many diff programs which all
    seem to be line based and work on text written in PHP.
    >
    So I am after either existing PHP code to do an HTML diff or some help
    forming an algorithm todo this.
    >
    Many thanks in advance,
    Obvious solution would be to use 'diff' from popen / exec etc

    Another approach would be to hack the code from an existing
    implementation (like DokuWiki).

    But the very first hit for 'php diff' in Google provides what you
    describe.

    C.

    Comment

    • Aaron Gray

      #3
      Re: HTML Diff problem

      "C. (http://symcbean.blogsp ot.com/)" <colin.mckinnon @gmail.comwrote in
      message
      news:60ed1c02-af0c-4d40-b9b2-b92259710dab@d7 0g2000hsc.googl egroups.com...
      On 22 Oct, 18:54, "Aaron Gray" <ang.use...@gma il.comwrote:
      >Hi,
      >>
      >I am working on an HTML WYSISYG Wiki and need to display a diff page like
      >WikiPedia does if two people edit a file at the same time to give the
      >second
      >user the diff. Basically with additions in red and deletions in red
      >strike
      >though.
      >>
      >There seem to be several in Perl and Python and many diff programs which
      >all
      >seem to be line based and work on text written in PHP.
      >>
      >So I am after either existing PHP code to do an HTML diff or some help
      >forming an algorithm todo this.
      >>
      >Many thanks in advance,
      >
      Obvious solution would be to use 'diff' from popen / exec etc
      This is not HTML based.
      Another approach would be to hack the code from an existing
      implementation (like DokuWiki).
      This is not HTML based.
      But the very first hit for 'php diff' in Google provides what you
      describe.
      This is a straight diff not an HTML diff. The problem is comparing two HTML
      files, not wiki text files.

      Thanks anyway,

      Aaron


      Comment

      • Gordon

        #4
        Re: HTML Diff problem

        On Oct 23, 6:39 pm, "Aaron Gray" <ang.use...@gma il.comwrote:
        "C. (http://symcbean.blogsp ot.com/)" <colin.mckin... @gmail.comwrote in
        messagenews:60e d1c02-af0c-4d40-b9b2-b92259710dab@d7 0g2000hsc.googl egroups..com...
        >
        >
        >
        On 22 Oct, 18:54, "Aaron Gray" <ang.use...@gma il.comwrote:
        Hi,
        >
        I am working on an HTML WYSISYG Wiki and need to display a diff page like
        WikiPedia does if two people edit a file at the same time to give the
        second
        user the diff. Basically with additions in red and deletions in red
        strike
        though.
        >
        There seem to be several in Perl and Python and many diff programs which
        all
        seem to be line based and work on text written in PHP.
        >
        So I am after either existing PHP code to do an HTML diff or some help
        forming an algorithm todo this.
        >
        Many thanks in advance,
        >
        Obvious solution would be to use 'diff' from popen / exec etc
        >
        This is not HTML based.
        >
        Another approach would be to hack the code from an existing
        implementation (like DokuWiki).
        >
        This is not HTML based.
        >
        But the very first hit for 'php diff' in Google provides what you
        describe.
        >
        This is a straight diff not an HTML diff. The problem is comparing two HTML
        files, not wiki text files.
        >
        Thanks anyway,
        >
        Aaron
        There is no such thing as a HTML diff, or a wiki diff, or a
        thingywosit diff. They all use the same algorithm. They scan a
        string and look for differences on a line by line basis. You can feed
        HTML data into them just as easily as any other kind of data.

        For example, using http://www.holomind.de/phpnet/diff2.src.php:

        Input 1:

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/
        TR/xhtml11/DTD/xhtml11.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Untitl ed Document</title>
        <script type="text/javascript" src="/js/jquery/jquery.js" />
        </head>
        <body>
        <pLorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
        sed purus ac
        elit tempor lacinia. Fusce viverra! Duis elementum nisl nec metus.
        Sed quis arcu.
        Morbi tortor! Maecenas ac nisl sit amet felis euismod elementum. Sed
        non lacus
        sed mi vehicula congue. Vestibulum non felis egestas leo ultricies
        ultricies.
        Donec ornare scelerisque leo! Vivamus sed nunc quis augue
        consectetuer eleifend.
        Praesent cursus. Phasellus cursus, nunc eu placerat dictum, metus
        leo volutpat
        arcu, ac convallis tellus nunc in elit. Maecenas dignissim tincidunt
        pede. Vivamus
        eget metus. Integer luctus est interdum nibh. Curabitur condimentum
        faucibus enim.
        Nunc tincidunt ipsum et odio. </p>
        <pDonec sed nunc. Fusce accumsan, felis dignissim faucibus cursus,
        diam neque
        pharetra libero, at rhoncus enim ipsum nec nulla. Donec sed metus.
        Suspendisse
        potenti. Nam suscipit vehicula risus. Integer vel arcu. Ut nec enim
        pulvinar magna
        tristique laoreet. Quisque viverra tellus a sapien. Praesent
        fringilla. Duis mi
        risus, tempus ut, venenatis quis, malesuada eget; velit. Cras nisi.
        Nam et ligula.
        Duis feugiat lorem at urna. </p>
        <pSuspendisse potenti. Integer interdum, dolor sed ullamcorper
        dictum; est augue
        aliquet eros, at molestie augue est et nunc. Pellentesque habitant
        morbi tristique
        senectus et netus et malesuada fames ac turpis egestas. Aenean ac
        metus? Duis
        vel nibh vitae odio hendrerit vulputate. Ut tortor. Ut fermentum
        pellentesque
        nulla. Sed eros dui, volutpat nec, ultrices feugiat, semper sit
        amet, nunc. Pellentesque
        habitant morbi tristique senectus et netus et malesuada fames ac
        turpis egestas.
        Morbi hendrerit nibh. Pellentesque lacinia urna. Sed nisi ligula,
        interdum quis,
        volutpat ac, placerat commodo, metus. Curabitur venenatis venenatis
        quam. Vivamus
        cursus, dolor vitae rutrum tempus, erat ipsum volutpat pede, sed
        cursus nunc mauris
        in ligula. In eget justo id justo pulvinar malesuada. Etiam nisi
        est, auctor vitae,
        blandit vel, aliquet quis, metus. Cras dui magna, commodo posuere,
        dictum convallis,
        laoreet vitae, lorem. Praesent luctus, ante at dictum vestibulum, mi
        urna pulvinar
        velit, ut ultricies erat purus luctus sapien. Praesent molestie
        turpis. Pellentesque
        bibendum rutrum est. </p>
        <pMauris adipiscing ante id neque. Nulla sit amet massa. Nam
        consectetuer lorem
        sed augue. Nullam in dui! Integer rutrum venenatis nisl.
        Pellentesque habitant
        morbi tristique senectus et netus et malesuada fames ac turpis
        egestas. Suspendisse
        id sem eget est rhoncus lobortis. Cras consequat ligula a mi. In hac
        habitasse
        platea dictumst. Cras vel sem. Quisque adipiscing. Suspendisse
        convallis justo
        ac nulla. Vivamus tincidunt. In rutrum consequat lorem. </p>
        </body>
        </html>

        Input 2:

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
        www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Lorem ipsum</title>
        </head>
        <body>
        <pLorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
        sed purus ac
        elit tempor lacinia. Fusce viverra! Duis elementum nisl nec metus.
        Sed quis arcu.
        Morbi tortor! Maecenas ac nisl sit amet felis euismod elementum. Sed
        non lacus
        sed mi vehicula congue. Vestibulum non felis egestas leo ultricies
        ultricies.
        Donec ornare scelerisque leo. Vivamus sed nunc quis augue
        consectetuer eleifend.
        Praesent cursus. Phasellus cursus, nunc eu placerat dictum, metus
        leo volutpat
        arcu, ac convallis tellus nunc in elit. Maecenas dignissim tincidunt
        pede. Vivamus
        eget metus. Integer luctus est interdum nibh. Curabitur condimentum
        faucibus enim.
        Nunc tincidunt ipsum et odio. </p>
        <pSuspendisse potenti. Integer interdum, dolor sed ullamcorper
        dictum; est augue
        aliquet eros, at molestie augue est et nunc. Pellentesque habitant
        morbi tristique
        senectus et netus et malesuada fames ac turpis egestas. Aenean ac
        metus? Duis
        vel nibh vitae odio hendrerit vulputate. Ut tortor. Ut fermentum
        pellentesque
        nulla. Sed eros dui, volutpat nec, ultrices feugiat, semper sit
        amet, nunc. Pellentesque
        habitant morbi tristique senectus et netus et malesuada fames ac
        turpis egestas.
        Morbi hendrerit nibh. Pellentesque lacinia urna. Sed nisi ligula,
        interdum quis,
        volutpat ac, placerat commodo, metus. Curabitur venenatis venenatis
        quam. Vivamus
        cursus, dolor vitae rutrum tempus, erat ipsum volutpat pede, sed
        cursus nunc mauris
        in ligula. In eget justo id justo pulvinar malesuada. Etiam nisi
        est, auctor vitae,
        blandit vel, aliquet quis, metus. Cras dui magna, commodo posuere,
        dictum convallis,
        laoreet vitae, lorem. Praesent luctus, ante at dictum vestibulum, mi
        urna pulvinar
        velit, ut ultricies erat purus luctus sapien. Praesent molestie
        turpis. Pellentesque
        bibendum rutrum est. </p>
        <pLorem ipsum dolor sit amet, consectetuer adipiscing elit.
        Vestibulum pede ipsum,
        accumsan quis, porttitor ut, blandit sed, neque. Phasellus feugiat
        commodo erat.
        Praesent pulvinar augue sollicitudin nibh. Nunc tellus. Etiam ac
        nunc. Praesent
        eget lacus eu dolor fringilla vehicula. Nunc ac nulla nec dui
        imperdiet cursus?
        Sed dictum nunc nec erat. Donec laoreet magna nec est. Ut vel magna
        vel est scelerisque
        varius! In nulla leo, luctus sed, rhoncus vel, semper in, eros?
        Vestibulum quam
        dui, ultrices vitae, consectetuer in, aliquam nec, mauris. Morbi
        congue pulvinar
        quam! Vivamus tortor. Ut a leo et tortor accumsan pretium. Vivamus
        mi. Curabitur
        nulla lacus, commodo ut, iaculis vel, mollis eget, felis!
        Pellentesque habitant
        morbi tristique senectus et netus et malesuada fames ac turpis
        egestas. Vestibulum
        ut diam. Maecenas facilisis semper mi. </p>
        <pMauris adipiscing ante id neque. Nulla sit amet massa. Nam
        consectetuer lorem
        sed augue. Nullam in dui! Integer rutrum venenatis nisl.
        Pellentesque habitant
        morbi tristique senectus et netus et malesuada fames ac turpis
        egestas. Suspendisse
        id sem eget est rhoncus lobortis. Cras consequat ligula a mi. In hac
        habitasse
        platea dictumst. Cras vel sem. Quisque adipiscing. Suspendisse
        convallis justo
        ac nulla. Vivamus tincidunt. In rutrum consequat lorem. </p>
        <pUt blandit rhoncus tellus. Integer condimentum, turpis sit amet
        tempor viverra;
        tellus neque mollis dui, sit amet lacinia neque felis a enim. Nulla
        ac velit sit
        amet erat elementum dignissim. Cras suscipit, felis nec aliquet
        auctor, augue
        nisi ultrices purus, non convallis tortor odio ac nisi. Nam non
        mauris eget nunc
        congue euismod. Nam eget sapien at magna tempor aliquam. Nullam
        bibendum tempor
        velit. Phasellus in elit at mi vestibulum convallis. Integer sit
        amet nulla. Pellentesque
        habitant morbi tristique senectus et netus et malesuada fames ac
        turpis egestas.
        Mauris nec magna id nibh sagittis posuere. Nulla a metus vitae
        tortor tempus lobortis.
        Praesent augue dolor, pulvinar vitae, accumsan vel, bibendum
        faucibus, eros? Sed
        a ipsum id dui varius blandit! In aliquet suscipit pede. </p>
        </body>
        </html>

        Result:

        1c1
        < <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/
        TR/xhtml11/DTD/xhtml11.dtd">
        ---
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
        5,6c5
        < <title>Untitl ed Document</title>
        < <script type="text/javascript" src="/js/jquery/jquery.js" />
        ---
        <title>Lorem ipsum</title>
        13c12
        < Donec ornare scelerisque leo! Vivamus sed nunc quis augue
        consectetuer eleifend.
        ---
        Donec ornare scelerisque leo. Vivamus sed nunc quis augue consectetuer eleifend.
        18,23d16
        < <pDonec sed nunc. Fusce accumsan, felis dignissim faucibus cursus,
        diam neque
        < pharetra libero, at rhoncus enim ipsum nec nulla. Donec sed metus.
        Suspendisse
        < potenti. Nam suscipit vehicula risus. Integer vel arcu. Ut nec
        enim pulvinar magna
        < tristique laoreet. Quisque viverra tellus a sapien. Praesent
        fringilla. Duis mi
        < risus, tempus ut, venenatis quis, malesuada eget; velit. Cras
        nisi. Nam et ligula.
        < Duis feugiat lorem at urna. </p>
        37a31,41
        <pLorem ipsum dolor sit amet, consectetuer adipiscing elit. Vestibulum pede ipsum,
        accumsan quis, porttitor ut, blandit sed, neque. Phasellus feugiat commodo erat.
        Praesent pulvinar augue sollicitudin nibh. Nunc tellus. Etiam ac nunc. Praesent
        eget lacus eu dolor fringilla vehicula. Nunc ac nulla nec dui imperdietcursus ?
        Sed dictum nunc nec erat. Donec laoreet magna nec est. Ut vel magna velest scelerisque
        varius! In nulla leo, luctus sed, rhoncus vel, semper in, eros? Vestibulum quam
        dui, ultrices vitae, consectetuer in, aliquam nec, mauris. Morbi conguepulvinar
        quam! Vivamus tortor. Ut a leo et tortor accumsan pretium. Vivamus mi. Curabitur
        nulla lacus, commodo ut, iaculis vel, mollis eget, felis! Pellentesque habitant
        morbi tristique senectus et netus et malesuada fames ac turpis egestas.Vestibu lum
        ut diam. Maecenas facilisis semper mi. </p>
        43a48,57
        <pUt blandit rhoncus tellus. Integer condimentum, turpis sit amet tempor viverra;
        tellus neque mollis dui, sit amet lacinia neque felis a enim. Nulla ac velit sit
        amet erat elementum dignissim. Cras suscipit, felis nec aliquet auctor,augue
        nisi ultrices purus, non convallis tortor odio ac nisi. Nam non mauris eget nunc
        congue euismod. Nam eget sapien at magna tempor aliquam. Nullam bibendum tempor
        velit. Phasellus in elit at mi vestibulum convallis. Integer sit amet nulla. Pellentesque
        habitant morbi tristique senectus et netus et malesuada fames ac turpisegestas.
        Mauris nec magna id nibh sagittis posuere. Nulla a metus vitae tortor tempus lobortis.
        Praesent augue dolor, pulvinar vitae, accumsan vel, bibendum faucibus, eros? Sed
        a ipsum id dui varius blandit! In aliquet suscipit pede. </p>

        Comment

        • Aaron Gray

          #5
          Re: HTML Diff problem

          "Gordon" <gordon.mcvey@n tlworld.comwrot e in message
          news:c4145620-1838-4775-aaad-208c95c75485@k3 0g2000hse.googl egroups.com...
          >There is no such thing as a HTML diff, or a wiki diff, or a
          >thingywosit diff. They all use the same algorithm. They scan a
          >string and look for differences on a line by line basis. You can feed
          >HTML data into them just as easily as any other kind of data.
          Well, I think there needs to be one.

          You cannot presume HTML is always line based for starters.

          Plain Diff does not comeup with the correct goods !

          They do exist PERL has one, Python has one.

          I need to code one in PHP !

          Regards,

          Aaron


          Comment

          • Aaron Gray

            #6
            Re: HTML Diff problem

            "Aaron Gray" <ang.usenet@gma il.comwrote in message
            news:6m97mpFf87 77U1@mid.indivi dual.net...
            Hi,
            >
            I am working on an HTML WYSISYG Wiki and need to display a diff page like
            WikiPedia does if two people edit a file at the same time to give the
            second user the diff. Basically with additions in red and deletions in red
            strike though.
            >
            There seem to be several in Perl and Python and many diff programs which
            all seem to be line based and work on text written in PHP.
            >
            So I am after either existing PHP code to do an HTML diff or some help
            forming an algorithm todo this.
            Doing Diff's via DOM tree's look attractive. Maybe it could be done in XSLT
            ?

            Aaron


            Comment

            • Aaron Gray

              #7
              Re: HTML Diff problem

              "Aaron Gray" <ang.usenet@gma il.comwrote in message
              news:6m97mpFf87 77U1@mid.indivi dual.net...
              Hi,
              >
              I am working on an HTML WYSISYG Wiki and need to display a diff page like
              WikiPedia does if two people edit a file at the same time to give the
              second user the diff. Basically with additions in red and deletions in red
              strike though.
              >
              There seem to be several in Perl and Python and many diff programs which
              all seem to be line based and work on text written in PHP.
              >
              So I am after either existing PHP code to do an HTML diff or some help
              forming an algorithm todo this.
              I have been looking into using XHTML/XML and DOM, this gives the tree
              walking mechanism, but the actual diff still looks difficult :)

              Aaron


              Comment

              Working...