Hi !
Is there any way to add/guide for adding color syntax highlight to Custom Story Format in the Twine editor ?
I am interested by Snowman and especially Protagonist variant but not having visual clues about the syntax make it hard to code.
It was requested for
Protagonist here.
Thanks for your support !
Comments
I don't know of any guide explaining how to implement this feature for Twine 2, so I can only suggest the developers of other story formats look at Harlowe's source code to see how it was done.
Someone else may have a better answer.
So here is the file in harlow which allows that
_L_ / harlowe / source / js / markup / codemirror / mode.js — Bitbucket
I think it also works with some other js in the parent directory.
But I don't know yet how to minify Protagonist (or any other custom format) for distribution (and so for testing).
For Snowman, I see there was infos about that at the bottom of the readme, it seems that learning basic Node.js and Gulp is necessary. I don't have any experienced with those so I can't test color syntax implementation for now.
Meanwhile, I posted a FR for Color Syntax Highlight for Snowman.
I meant NPM, not Node.js ^^
it doesn't look like the format.js is loaded on the editor side...
Did I miss something ?
Yes it is installed.
Following your comment, I did a bit of inspection.
It seems that custom format.js is only loaded when clicking on the Change Story Format button, even if you don't change the story format. More, it loads ALL the format.js of all story format.
I don't know if this expected, but it doesn't look very right, IMHO.
What do you think ?
The gif shows that format.js are downloaded when clicking on story format. I understand this is to display formats.js info, contains as JSONP chunk.
But the gif also shows that these format.js are NOT downloaded before clicking on story format, even if a custom format was already choosen.
So the question is the following : can a format.js, as suggested by greyelf, handes color syntax information for backend ? But what about the fact that the format.js is not loaded at document.ready but only after clicking the menu ?
Put in another more global way : How would you put color syntax support in the editor to a custom language ? Do you have any working demo to show us ?
--
I tried a different approach with the codemiror mode.js file of Harlowe and with GreaseMonkey browser addon, without success. But maybe I miss a thing for this method.
If you open the project's change story format dialog, which enumerates the formats, then loading the formats is required, as your GIF showed.
If you had opened the passage editor, then you would have seen the project's selected format being loaded, as doing so would be required to obtain its CodeMirror mode. Give it a try.
So, format.js can indeed be used for syntax colorization. That's a good news.
That's where the hard begin.
I guess I could start by trying to import mode.js and see how it goes.