Good in-line code editor similar to TinyMCE?
Added by Mark Travis 25 days ago
I'm working on a request to allow users to type code (Lua in particular) into a chat-style format, and have the code syntax colored.
Kind of like this forum when you use the "<>" button to insert code
auto someCPPCode = this;
I found a plugin called CodeSample that is a TinyMCE plugin. But that requires double-clicking to open the sub-editor, and the code isn't syntax highlighted until you close it. https://www.tiny.cloud/docs/tinymce/latest/codesample/
Ideally, they want something to work in-line the way TinyMCE works with WTextEdit.
There is https://github.com/codemirror/dev but I'm not sure, yet, what kind of effort that will be to implement via WTextEdit.
Another requirement is to run all code locally with no outside interenet connection, so any library I find needs to be able to run in a local net environment.
Replies (1)
RE: Good in-line code editor similar to TinyMCE? - Added by Matthias Van Ceulebroeck 20 days ago
Hey Mark,
while I cannot chime in on an alternative, as I've not used one. I can add some information on your remark.
but I'm not sure, yet, what kind of effort that will be to implement via WTextEdit.
I would not override WTextEdit
, but go to that file's base class WTextArea
. You can then also create the JS implementation file, similar to WTextEdit.js
.
The documentation of CodeMirror seems pretty good. Allowing its state to be managed by JS calls.
A rough outline would be to then:
- initialise the widget, loading the JS file, and setting its JS members
- call the JS constructor, which defines the extensions to be used
- the
updateDom
function will then cal the CodeMirror API on any changes the application performed
You may want to see if the API offers some hooks you should be aware of (content changes, plugin changes, renders, ...), which can be listened to as JSignal
s.
Personally I don't think it's a huge amount of work (but of course, I work with Wt a lot, and I am biased), and it will be a teaching experience on many Wt concepts.
If you do take this route, and encounter issues, let me know!
If you do take this route, and do NOT encounter issues, still let me know, as I find this interesting! ;)
Best,
Matthias