-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
💻 Add curly braces around teacher adventures' code #5253
Conversation
@Felienne This PR is almost ready but there's something I haven't been able to figure out and would like to hear your input! Adding curly braces around keywords in code snippets is possible due to Lezer, and since the keywords have context attached to them, in the case of keywords using the same word, we can know by context which one is right. However, what to do with keywords that aren't part of snippets, like this: Just iterating over the keyword regexes, and returning the one that matches is not enough, because there might be several of them. How can we handle this? |
Why not? You could iterate over all the code tags (that you get from CKEditor for free) and then surround them by {}, if the teacher didn't do so! |
We've already had this problem in the past (see #4898), but essentially the problem is that if the teacher writes: |
I'm merely trying to think with you! We are only concered with the keys that we add to the keywords and not their translations, i think. So, if they write |
Sorry if the message sounded dry! Thanks for helping out!
This is not really possible! The format we use for the translation of keywords is the following:
an example of this is:
If the user writes So, let's see this case, in Spanish we have these two keywords that use the word, but in English the word is different:
So if the teacher writes But maybe I'm being dumb and this is what you're suggesting? In any case, hope I'm not sounding dismissive, thanks a lot for helping out! |
I'm marking this as ready to review, because maybe we can deal with the individual keywords in other PR! |
ok! Was the confusion above addressed (ie, did Hasan's solution make sense?) |
No, not really! That's why I think it might be addressed in a different PR, I have some ideas but maybe we can discuss them tomorrow? |
Absolutely! Shall we merge this as is (it does work!) or do you want to tak the content suggestion I made above into account here? |
I removed the curly braces from the code blocks in English, Spanish and Dutch. Would that be enough or do I remove them from every language? |
…edyorg/hedy into automatically_add_curly_braces
Ideally, yes! I tried to do a few more. I also thought that the first {print} needed to be removed, see 63fd54d. Is that correct? If not... feel free to revert the commit! |
This reverts commit 63fd54d.
I did revert the commit because curly braces around those keywords are still needed, I also removed the unnecessary curlies in the languages that were left! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, thanks for the extra effort on the content!
Thank you for contributing! Your pull request is now going on the merge train (choo choo! Do not click update from main anymore, and be sure to allow changes to be pushed to your fork). |
Thank you for contributing! Your pull request is now going on the merge train (choo choo! Do not click update from main anymore, and be sure to allow changes to be pushed to your fork). |
Adds curly braces automatically around keywords in the teacher's adventure code.
For that, we iterate over the code snippets inside the contents of the editor, and use Lezer to parse and the code, and eventually iterate over the syntax tree to add curly braces around the keywords. The generated code should be as close as possible to the original one, maintaining indentation levels, spaces, and even errors.
Also adds a warning for the case when the teacher selects several levels and also have code snippets, letting them know this can lead to trouble.
Fixes #5140
How to test