-
Notifications
You must be signed in to change notification settings - Fork 2
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
Problem with \n not correctly handled in preview #7
Comments
Ah it really isn't working! Could you give me a screenshot of what the question looks like when it's imported into Moodle? |
@ethan-ou If this turns out to be a problem with the parser, I can try to fix it. I'm thinking a new test needs to include that input to make sure it's parsed correctly. |
@fuhrmanator I believe it might be because the preview just takes the raw output from the parser. I'm not 100% sure how new lines would work when converted to HTML but if not, I can write in some parsing logic to add new lines in the preview plugin. Thanks for picking this up by the way! I was going to add an issue on your project when I got around to it. |
@didoudiaz I think I fixed it in the previewer at https://fuhrmanator.github.io/GIFT-grammar-PEG.js/editor/editor.html @ethan-ou perhaps you can use that logic to change your extension's preview? |
@fuhrmanator had a read of your code and found an interesting edge case. @didoudiaz used a single backslash In order to get I'm thinking the regex should probably be: switch (giftText.format) {
case "html":
case "moodle":
// convert Moodle's embedded line feeds (GIFT) to HTML
unescapedString = giftText.text.replace(/\n/g, '<br\>');
html = unescapedString;
break;
case "plain":
html = giftText.text;
break;
case "markdown":
html = converter.makeHtml(giftText.text, { breaks: true });
break;
default:
break;
} Also, this fix could be extended to carriage line returns switch (giftText.format) {
case "html":
case "moodle":
// convert Moodle's embedded line feeds (GIFT) to HTML
unescapedString = giftText.text.replace(/(?:\r\n|\r|\n)/g, '<br>');
html = unescapedString;
break;
case "plain":
html = giftText.text;
break;
case "markdown":
html = converter.makeHtml(giftText.text, { breaks: true });
break;
default:
break;
} |
@didoudiaz the preview plugin should be updated. Give it a try and see whether everything works on your end. |
@fuhrmanator my apologies you were right about escaping the backslashes, and it looks like enabling line breaks in markedjs does something different to I imagined. v0.0.10 is up now if you want to try again. |
Sorry for the noise. Looking again at the definition for GIFT, I believe this could be a parser issue:
I totally ignored this case in the parser (it actually filters out whitespace, see here), but I'm wondering if that's the right approach. That is, should the parser convert the It's easy enough to do (I just added the rule in the grammar, but I will have to clean up that white space logic). A lot of tests will break as written, but that's normal. If you agree, @ethan-ou, let's open an issue there - I think it changes a lot (especially previews), so I would do a branch. |
Sounds good. I opened an issue on your repo so we'll take it from there. |
Not yet sure if it is a parser-issue (or a client application issue, like the VSCode plugin). See my comment in the newly created parser issue. |
I "re-import" your remark in this thread to separate things.
Wonderful ! Thanks BTW, do you plan to add other functionalities ? Here are some ideas:
Point 5 is because moodle seems to ignore spaces at the begining of a line when importing a GIFT file (at least on our moodle)... replacing the fisrt space by
What do you think ? |
@didoudiaz if you restart your Vscode it should be working by now. By the time I'm writing this you might already see it. The actions I'm most inclined to implement right now is the ability to switch question types (e.g. multiple choice to short answer or matching) and generated answer weights for multiple choice multiple answer questions. I want to make sure the most general use cases are handled, especially for people who aren't as technically savvy. I also don't want too many actions so that the context menus stay relatively small. Wouldn't want to go through a long menu just to find the action you're looking for. Otherwise, do you think the actions you're suggesting would be useful for other users too? |
This makes sense.
My suggestions are really useful for people wanting to insert "verbatim text" ("preformated" in the html jargon) in their questions. Such a text should be reflected as is once imported in moodle. It is the case of source code (questions about programming) but also of examples. In that case, the user will surely use
A help for these tasks is a really improvement. |
VSCode snippets might be a good compromise? https://code.visualstudio.com/docs/editor/userdefinedsnippets Otherwise, some regex replacement pattern? |
@fuhrmanator @didoudiaz I think I found a good solution using commands. To access them, you can use CTRL + SHIFT + P and get them from the dialog menus. There's more friction to the process as a user but it means we can implement many specific formatting actions without overwhelming other users. When I get to it, I'll try the real new line action first. I think it'll be good to discuss the HTML ones in greater detail. |
Both snippets and commands seem promising. I'm a new VSCode user, so I don't yet master it and know all its possibility. I'm a bit overwhelmed with remote-teaching duties at my University but I'm very interested by your ideas. |
I followed https://code.visualstudio.com/docs/editor/userdefinedsnippets#_create-your-own-snippets to make the following snippet in a
Then, as I type a question, like:
as the To be honest, I don't understand why the next-to-last line with "\\}" requires 4 backslashes! I tried it with only two, but it didn't work when the snippet gets inserted. |
@fuhrmanator Thank you, seems very promising ! I could also define a snippet form my examples following the same line. |
Hi,
I obtain an error |
I made a fix to patch it. It should be live now. Keep coming if you have any more issues! |
The escape character \n should be reflected as a newline in the Preview window.
Here is an example (type this GIFT question and look at the preview) :
Is the newline escape character\nworking ?
{F}
NB: I have modified a bit the question (no newline after the \n).
The text was updated successfully, but these errors were encountered: