Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ td:last-child {
width: 120px;
}

td pre {
margin-bottom: 1rem;
}

/* Banner styles - using styleguide colors where possible */
.banner {
position: fixed;
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ module ApplicationHelper
def markdown(text)
renderer = Redcarpet::Render::HTML.new(escape_html: true)
markdown = Redcarpet::Markdown.new(renderer, fenced_code_blocks: true)

# Redcarpet needs the codeblocks to have 2 newlines before them
# 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```")

end

markdown.render(text.to_s).html_safe
end
end
14 changes: 14 additions & 0 deletions test/helpers/markdown_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,18 @@ class ACodeBlock

assert_includes as_html, "<pre><code>class ACodeBlock"
end

test "fixes newlines around code blocks" do
puzzle_content = <<~CONTENT
Some content with
```
class ACodeBlock
end
```
in it
CONTENT
as_html = markdown(puzzle_content)

assert_includes as_html, "<pre><code>class ACodeBlock"
end
end