I would like to write a simple plain text editor including simple markdown instructions in QML. Therefore I added a TextEdit-Element and a JavaScript Function for Syntax Highlighting.
As an example:
I want to print the string between two asterisks ‘*’ in bold.
So I have to insert a <b> tag before or a </b> tag after the latest symbol (*), but the property of the element is a HTML document.
How can I find the right position (I can access the cursor position but this is different to the html-doc position)? And insert these tags? Are there some helper methods, cheats or guidelines?
You can use
window.getSelection()for get the selected text.For example:
HTML:
JavaScript: