herrmiller
06-07-2009, 02:49 PM
if i have a coded string like the following.
<strong>This is |simply </strong><em>some random text</em> <strong>that i typed| just for you.</strong>
if i make a selection like i have indicated above (left of 'simply', right of 'typed'), create a range and extractContents i get a documentFragment like following
<strong>simply </strong><em>some random text</em> <strong>that i typed</strong>
The text nodes that have been cut in the original text are conviently enough also closed. So this seems like a good solution. However, now i want to go through all the <strong> nodes in the fragment and remove them, leaving their text content...
Any good ideas of how to this?
Also, if i select text like this (with the intention of making the selection bold):
<em>This is |simply some</em> random text that i typed| just for you.
i get a fragment like this:
<em>simply some</em> random text that i typed
if the user has chosen to make the selection bold i want to surround Every textNode with <strong> tags and turn the fragment into this:
<em><strong>simply some</strong></em><strong>random text that i typed</strong>
Any good ideas of how to do this? I was thinking of you could somehow use a range object to select each individual textNode and use surroundContents() but i am not sure how to iterate through all the nodes to find the textNodes in the best way...
<strong>This is |simply </strong><em>some random text</em> <strong>that i typed| just for you.</strong>
if i make a selection like i have indicated above (left of 'simply', right of 'typed'), create a range and extractContents i get a documentFragment like following
<strong>simply </strong><em>some random text</em> <strong>that i typed</strong>
The text nodes that have been cut in the original text are conviently enough also closed. So this seems like a good solution. However, now i want to go through all the <strong> nodes in the fragment and remove them, leaving their text content...
Any good ideas of how to this?
Also, if i select text like this (with the intention of making the selection bold):
<em>This is |simply some</em> random text that i typed| just for you.
i get a fragment like this:
<em>simply some</em> random text that i typed
if the user has chosen to make the selection bold i want to surround Every textNode with <strong> tags and turn the fragment into this:
<em><strong>simply some</strong></em><strong>random text that i typed</strong>
Any good ideas of how to do this? I was thinking of you could somehow use a range object to select each individual textNode and use surroundContents() but i am not sure how to iterate through all the nodes to find the textNodes in the best way...