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

Fix unicode support #51

Merged
merged 1 commit into from
Jul 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/problem_bank_scripts/problem_bank_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,9 @@ def parse_body_part(pnum, md_text):

# Store the content of the level 2 header
try:
content = codecs.unicode_escape_decode(
Copy link
Contributor

@firasm firasm Jul 6, 2023

Choose a reason for hiding this comment

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

I think there was a reason why I had added this (it wasn't done this way initially)...let me try to figure out why this was done this way, I don't want to break other questions by making this change.

Copy link
Collaborator Author

@Bluesy1 Bluesy1 Jul 6, 2023

Choose a reason for hiding this comment

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

diff mode on GitHub said it was to support LateX, but that doesn't make too much sense to me, since the tests questions that use LaTeX seem to be fine with the changes here

Edit: see this commit: 131ce85#diff-ec4c87e6a250f788996aabbdcca263c77e266b61454503016d38f2e678fdd945R161

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks - so basically we are now allowing unicode characters in questions. Hopefully that fixes questions like this one: https://ca.prairielearn.com/pl/course/38/question/237974/preview

mdformat.renderer.MDRenderer().render(
content = mdformat.renderer.MDRenderer().render(
tokens[3 : get_next_headerloc(3, tokens, 3)], mdit.options, env
) # Note the 3 is there to exclude header start,header content,header end tokens
)[0]
nested_dict[part]["content"] = content
except IndexError:
print("It looks like there is an empty section of header level 2 in your md file.")
Expand Down Expand Up @@ -334,9 +332,7 @@ def read_md_problem(filepath):

for k, v in blocks.items():

rendered_part = codecs.unicode_escape_decode(
mdformat.renderer.MDRenderer().render(tokens[v[0] : v[1]], mdit.options, env)
)[0]
rendered_part = mdformat.renderer.MDRenderer().render(tokens[v[0] : v[1]], mdit.options, env)

if k == "title":
body_parts["title"] = rendered_part
Expand Down Expand Up @@ -888,7 +884,7 @@ def str_presenter(dumper, data2):
"---\n"
+ header_yml
+ "---\n"
+ text
+ text.replace(r"\\", "\\")
+ "\n## Attribution\n\n"
+ process_attribution(header.get("attribution")),
encoding="utf8",
Expand Down Expand Up @@ -944,7 +940,7 @@ def str_presenter(dumper, data2):
+ "\n---\n"
+ dict_to_md(
body_parts,
)
).replace(r"\\", "\\")
+ "\n## Attribution\n\n"
+ process_attribution(header.get("attribution")),
encoding="utf8",
Expand Down