I presume this is on the browser?
The exact code very much depends on the Rich Text Editor you're using, i.e. how to interact with the text in the editor.
Hope this gets you started.
Jack Poorte, Jan 09, 2016