is there a reason why you would want to use the rich text field VS a text field? This feature is most often used to change just a small amount of code, for example a specific selector, so using an RTE wouldn’t be needed.
The solution might be to render the RTF as hidden on the page then reference that as an object in your custom code or you can use the code embed inside a RTF and then display it as needed.