Skip to content

IIRR-34: Render puzzles's code with code-style#93

Merged
JuanVqz merged 2 commits into
mainfrom
IIRR-34-render-code-as-code
May 29, 2026
Merged

IIRR-34: Render puzzles's code with code-style#93
JuanVqz merged 2 commits into
mainfrom
IIRR-34-render-code-as-code

Conversation

@arielj
Copy link
Copy Markdown
Contributor

@arielj arielj commented May 28, 2026

This PR adds code-style around code inside puzzles.

This makes it easier to review them since some cases were problematic before:

  • html in puzzles was not escaped, so the actual HTML elements were rendered
image
  • it was easy to miss basic typos like using 4 backticks instead of 1, or not adding a new line around the backticks
image
  • it was easy to miss mismatched backticks for inline code

Now, code is rendered in the table:
image

@arielj arielj requested a review from JuanVqz May 28, 2026 19:55
Copy link
Copy Markdown
Member

@JuanVqz JuanVqz left a comment

Choose a reason for hiding this comment

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

The rendered code looks good, I was expecting having colors :) maybe next iteration, thanks @arielj

Screenshot 2026-05-28 at 15 12 24

Comment thread test/helpers/markdown_helper_test.rb Outdated
Comment on lines +2 to +4
def markdown(text)
RedcarpetCompat.new(text, :fenced_code).to_html.html_safe
end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just for the record, Since this is under our control, we can leave it as it is, but we are going to render HTML tags and test it with the following record:

Puzzle.create!(question: "test `<script>alert(1)</script>`", answer: :ruby, explanation: "loose <img src=x onerror=alert(1)>", state: :pending)
Image

This is a safer way to do it:

Suggested change
def markdown(text)
RedcarpetCompat.new(text, :fenced_code).to_html.html_safe
end
def markdown(text)
r = Redcarpet::Render::HTML.new(escape_html: true)
Redcarpet::Markdown.new(r, fenced_code_blocks: true).render(text.to_s).html_safe
end

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated

@arielj
Copy link
Copy Markdown
Contributor Author

arielj commented May 28, 2026

The rendered code looks good, I was expecting having colors :) maybe next iteration, thanks @arielj

I think we should leave it without colors since the language hints are not supported by Discord, Discord does not show colors.

@JuanVqz JuanVqz merged commit c80f306 into main May 29, 2026
4 checks passed
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.

2 participants