Skip to content

IIRR-34: Fix newlines around codeblocks for Redcarpet renderer#94

Merged
JuanVqz merged 2 commits into
mainfrom
IIRR-34-fix-newlines-codeblocks-bug
Jun 1, 2026
Merged

IIRR-34: Fix newlines around codeblocks for Redcarpet renderer#94
JuanVqz merged 2 commits into
mainfrom
IIRR-34-fix-newlines-codeblocks-bug

Conversation

@arielj
Copy link
Copy Markdown
Contributor

@arielj arielj commented May 29, 2026

My previous PR #93 adding code style introduced a bug: redcarpets needs the first three-backticks of a codeblock to have 2 newlines before it to render it properly.

This is not required for the closing three-backticks and also not required by discord either.

Because of this, some of our puzzles that don't have 2 newlines before the start of a codeblock were rendered incorrectly, parsing the code that should have been part of a code block as HTML instead.

This PR fixes that by fixing the missing newline during render if needed.

I didn't add a fix in the data stored in the database because it's not really a requirement for Discord, it's just a weird thing with Redcarpet so it's fixed on the fly as needed when rendered.

I also added a bit of space after the code block because it looked too close to the next line because of how redcarpet renders pre and p tags

@arielj arielj requested a review from JuanVqz May 29, 2026 18:10
Comment thread app/helpers/application_helper.rb Outdated
# fixing this at render because it's not really required by Discord
# it's just a quirk of Redcarpet
if text.match?(/[^\n]\n```(.*)\n```/m)
text = text.gsub(/[^\n]\n```(.*)\n```/m, "\n\n```\\1\n```")
Copy link
Copy Markdown
Member

@JuanVqz JuanVqz May 29, 2026

Choose a reason for hiding this comment

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

The requex you added is eathing the h of with, this worked for me:

Suggested change
text = text.gsub(/[^\n]\n```(.*)\n```/m, "\n\n```\\1\n```")
text = text.gsub(/([^\n])\n```(.*?)\n```/m, "\\1\n\n```\\2\n```")

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.

thanks! I updated this and also the test

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.

QA'ed :shipit:

@JuanVqz JuanVqz merged commit 62de5bd into main Jun 1, 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