js beginner- how to get html for selected content in a web page along with entire node hierarchy for the selection
===

At http://rangy.googlecode.com/svn/trunk/demos/core.html there is a demo that shows how to get  the HTML for content selected by a user.

However, I also want to obtain the entire structure of nodes, from top level node till the node to which the selected content belongs. How do I obtain this node structure? For example, please take a look at the sample content below

    <div id="toplevelnotselectedbyuser">

    <p id="thispisselectedbyuser">
    This text is not selected by the user...
    Some sample text that has been selected by user...
    Some more text that has not been selected by the user.
    </p>
    </div>

Now, if the user only selects the content "Some sample text that has been selected by user..."  and if the above example I gave (using the "rangy" library) is used, then only the text "Some sample text that has been selected by user..." is shown as selected HTML by that library-- I want both the div and p's information also ... How do I do this? I would prefer jquery, but pure javascript or any other library, would also be OK with me...


