Cronos,
I have done plenty of conversion projects in the past years and from my experience I can only give you one very good advice about this: FORGET IT.
Creating a script that allows selecting a piece of text in an unstructured document and convert it into a valid DITA file is not something you should even want to create. It is impossible to capture all the possible errors due to text selections that are impossible to structure.
You have two options to go forward building on this idea:
1. Create somthing that allows copying the currently selected piece of text into an existing DITA document, in which case the selected text should always be wrapped into something that cannot invalidate the structure. I would suggest gluing all paragraph text together so that you have one single paragraph and wrap that content into a single <p> element in your existing DITA file. Although this method might sound like a good idea, I do not think it is.
2. Structure the entire document and save it as DITA - if you can make it valid DITA, that is. This process can be highly optimized using scripts to pre- and post-process the document (removing some horrible unstructured stuff before conversion and augmenting the resulting structure after).
I hope you will find my advice useful. I am not trying to step on anyone's toes, just helping you to learn from my experience.
Kind regards
Jang