Skip to content
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

Enable markdown in all gradethis feedback messages #189

Merged
merged 10 commits into from
Jan 5, 2021

Conversation

gadenbuie
Copy link
Member

@gadenbuie gadenbuie commented Dec 28, 2020

This PR fixes #152 and closes #176 to add support for markdown in gradethis feedback messages.

There are two places where the feedback message is handled by gradethis. First, the messages in pass(), fail() and related helper functions are processed by glue, either in glue_message() (legacy) or glue_message_with_env() (added in this PR), to interpolate values from the exercise into the message string. These messages are given to the condition object created in graded() that is handled by the grading functions. Eventually, the condition ends up in feedback() where it's used to create the feedback object learnr expects. Here, the condition message is used for the feedback message.

In both places, we differentiate between tag-like, as-is, and other messages:

  • tag-like messages are created with htmltools::tags$___() or htmltools::tagList()
  • as-is messages are "protected" by wrapping in I() and
    • are used as-is in the graded() condition
    • are coerced to character and HTML-escaped in the final feedback message
  • otherwise messages are
    • collapsed to length-1 strings without whitespace before being processed with glue()
    • are processed as markdown with commonmark::markdown_html() and stripped of potentially harmful tags, e.g. <style>, <script>, or other tags

As a side-effect, message — or incorrect or correct parameters containing a feedback message — can now take vectors which are collapsed without spaces. This could be helpful when writing long feedback messages, but it may have other consequences if the object isn't a character vector.

image

Edited to reflect final approach.

Feedback messages using tags and tagLists from htmltools are passed through untouched and are not glued.

Messages marked with `I()` are not glued but are collapsed with newlines and HTML-escaped
Copy link
Collaborator

@schloerke schloerke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pending small name change

R/feedback.R Outdated Show resolved Hide resolved
We can now use I() to skip markdown processing in tests, param msg_fixed is added to allow for regexp in expect_match()
@gadenbuie gadenbuie merged commit d6e000e into rstudio:master Jan 5, 2021
@gadenbuie gadenbuie deleted the markdown branch January 5, 2021 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable markdown in gradethis feedback Allow markdown or HTML in graded message
2 participants