I am writing a script that needs to copy the actual, raw HTML that represents user-selected text. I do not need valid HTML (with balanced tags, etc), I need the character-by-character string from the source document that is wrapped by the selection.
For instance, if the HTML is the following:
<p>one two three <strong>four
five</strong> six seven</p>
... and the user starts the selection at the first 't' (just after the space following the word 'one') and ends the selection after the first 'v' (inside the word 'five'), I need to capture the following exact string to the clipboard:
two three <strong>four\nfiv
Note that the captured text needs to have the opening string
tag but not a matching closing tag, and needs to include the line break that exists in the source document after the word 'four' (even though this does not appear in the rendered HTML).
All of the help I have found so far tries to normalize the HTML that is selected, and this is not going to work for what I need.
Is this possible to capture? If so, how do I go about doing this? Thanks in advance for any suggestions or help!