As a developer, I have encountered a common need that StackOverflow addresses.
Situation
I am in the process of creating a website where users can post code examples and articles using an admin system. These posts may be created by me or registered frontend users.
Objective
The goal is to implement a WYSIWYG editor that allows users to easily submit articles. This editor should support text formatting, headings, and code examples enclosed in code tags.
Approach
I have been experimenting with extending TinyMCE to meet these requirements. While I can enable code tags, I faced challenges in getting highlighted text within the tags. However, using pre tags instead has proven effective. When pasting code snippets into the WYSIWYG editor and selecting Preformatted, the brackets are correctly encoded as < and >, which is acceptable. The content is then stored in the database and retrieved accurately.
However, when editing existing content loaded into the textarea field, TinyMCE re-encodes the brackets and removes any XML-based or script elements, treating them as invalid rather than plain text. Additionally, it lacks CDATA functionality, causing some parts to be ignored.
Unable to develop a plugin from scratch due to time and budget constraints, I seek a solution similar to what StackOverflow offers for question creation. Thank you StackOverflow!
Inquiry
Has anyone successfully addressed these challenges with TinyMCE? Can I replicate StackOverflow's functionality or access other formatting plugins suitable for inserting code snippets?