SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    May 2005
    Location
    Columbus, OH
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Techniques for rendering overlapping markup

    I'm building a JS module with an unusual requirement that has me pulling my hair out.

    In a nutshell, multiple users are able to highlight text in their own
    "copy" of the document. For example, the saved markup for two users
    might look like:

    <div id="annotation_1">
    The <span id="highlight_1">quick brown fox</span> jumps over the
    lazy dog.
    </div>

    and

    <div id="annotation_2">
    The quick <span id="highlight_2">brown fox jumps</span> over the
    lazy dog.
    </div>

    These two annotated copies of the same content then need to be able to
    be rendered in a combined view. This would obviously be trivial if we
    didn't need to worry about overlapping span tags, but the plugin needs
    to be able to handle this scenario and herein lies my dilemma.

    My current thought is see if there is a library/method/technique to
    merge the two containers to create something like

    <div id="annotation_combined">
    The <span id="highlight_1">quick </span><span
    id="highlight_1_2">brown fox</span> <span id="highlight_2">jumps</
    span> over the lazy dog.
    </div>

    ... or similar that simulates overlapping markup capabilities.

    Any advice (or alternative methods) is appreciated.

    Thanks,
    Jason

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Management of wiki's would be the best place to find a solution. A first step is to display the original and modified versions of the line sequentially with different colors showing the changed parts.

    Then you can move forward from there by scripting the unchanged parts, and working through scenarios to deal with the changed bits.

    It's not going to be easy, but it can be done, for a given value of done.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    May 2005
    Location
    Columbus, OH
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's a good idea, Paul. I'll start looking into some wiki code to see how they handle this sort of thing.

    Thanks,
    Jason

  4. #4
    SitePoint Member
    Join Date
    May 2005
    Location
    Columbus, OH
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I haven't completed this yet, but I found a very strong lead in John Resig's Diff Algorithm (based on an old whitepaper by Paul Heckel).

    http://ejohn.org/projects/javascript-diff-algorithm/

    I'm thinking a few markup modifications to this will work nicely.

    Jason


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •