Skip to content

Commit

Permalink
Merge pull request #58 from datacamp/bf/extras-markdown
Browse files Browse the repository at this point in the history
[CP-902] Multiline code block support
  • Loading branch information
BogdanFloris authored Dec 29, 2022
2 parents 5a79197 + fdf0e98 commit ba53556
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
6 changes: 5 additions & 1 deletion protowhat/Reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,8 @@ def build_final_payload(self):

@staticmethod
def to_html(msg):
return re.sub("<p>(.*)</p>", "\\1", markdown2.markdown(msg)).strip()
return re.sub(
"<p>(.*)</p>",
"\\1",
markdown2.markdown(msg, extras=["fenced-code-blocks", "code-friendly"]),
).strip()
2 changes: 1 addition & 1 deletion protowhat/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.1.2"
__version__ = "2.1.3"
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# protowhat deps
markdown2~=2.3.10
markdown2==2.4.6
Pygments==2.13.0
jinja2~=2.11.3
markupsafe==2.0.1

Expand Down
36 changes: 36 additions & 0 deletions tests/test_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,39 @@ def test_highlighting_path_no_position():
expected_payload = {"correct": False, "message": "msg", "path": "test.py"}

assert payload == expected_payload


def test_reporter_code_block():
r = Reporter()
msg = "Expected \n```\n{{sol_str}}\n```\n, but got \n```\n{{stu_str}}\n```\n"
code = """
while True:
car_wash_num += 1
# Get the current simulation time and clock-in the process time
yield env.timeout(5)"""
fmt_kwargs = {"sol_str": code, "stu_str": code}
f = Feedback(FeedbackComponent(msg, fmt_kwargs))

payload = r.build_failed_payload(f)
expected_message = """Expected
<pre><code>
while True:
car_wash_num += 1
# Get the current simulation time and clock-in the process time
yield env.timeout(5)
</code></pre>
, but got
<pre><code>
while True:
car_wash_num += 1
# Get the current simulation time and clock-in the process time
yield env.timeout(5)
</code></pre>"""

assert payload["message"] == expected_message

0 comments on commit ba53556

Please sign in to comment.