-
Notifications
You must be signed in to change notification settings - Fork 15
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
Support for linebreaks in grading comments #5913
Conversation
b882e36
to
3f034ec
Compare
@@ -12,3 +13,6 @@ def includeme(config): # pragma: nocover | |||
config.register_service_factory( | |||
BlackboardCourseCopyPlugin.factory, iface=BlackboardCourseCopyPlugin | |||
) | |||
config.register_service_factory( |
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.
The blackboard misc plugin is back, we need to define different behavior for BB here.
class BlackboardMiscPlugin(MiscPlugin): | ||
def format_grading_comment_for_lms(self, comment: str) -> str: | ||
# Replace new lines by by html, otherwise format it lost when read back. | ||
return comment.replace("\n", "<br/>") |
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.
Sad, but it's only for BB
@@ -63,21 +65,16 @@ def read_result(self, grading_id) -> GradingResult: | |||
# We'll filter ourselves here instead. | |||
results = [result for result in results if result["userId"] == grading_id] | |||
|
|||
# On top of this, blackboard adds some HTML to the comments it returns |
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.
Doing this with the plugin instead now.
from html.parser import HTMLParser | ||
|
||
|
||
def strip_html_tags(html: str) -> str: | ||
"""Get plain text from a string which may contain HTML tags.""" | ||
class WhiteSpaceHTMLParser(HTMLParser): # pylint:disable=abstract-method |
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.
I initially thought I would have to substantially change this. I didn't. But I think this version is slightly more pythonic (whatever that means). I kept the refactor.
parser.feed(html) | ||
parser.close() | ||
|
||
# Strip leading/trailing whitespace and duplicate spaces | ||
return " ".join("".join(chunks).split()) |
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.
This was very specific to the use case in jstor, where it used in titles. This removes newlines.
Move it back to the jstor service.
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.
Looks good and mostly works as expected.
I just noticed something we might want check on a later stage, which is that extra empty lines are discarded in D2L and Moodle, but they are preserved in Blackboard.
With "extra" I mean that it removes one empty line when saving, which means that, if you add more than one, it keeps one less every time, but if the same comment is submitted more times, eventually all empty lines are lost.
Grabacion.de.pantalla.desde.2023-12-13.09-58-19.webm
Keep the duplicate whitespace behaviour outside the service and move it back to the JSTOR one, where it was originally written.
This reverts commit d699591.
It turns out that LMS that support HTML also keep the new lines. We only need to remove the HTML tags to display the text in our textarea.
57ca8b8
to
ac3f738
Compare
Some LMS don't play nice with regular line breaks in grading comments (
\n
) but use HTML instead.This PR uses a naive approach to maintain the new lines in our textarea. It doesn't however try to support the full range of HTML different LMSes support.
Testing
D2L
Moodle
Blackboard
Enable grading comments in http://localhost:8001/admin/instance/100/
Launch this gradable assignment as a student first
Lauch this gradable assignment now as a teacher
Read the comment, it contains new lines. Change the comment.
Reload the assignment, read the comment again, it contains the changes.