File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -125,6 +125,10 @@ td:last-child {
125125 width : 120px ;
126126}
127127
128+ td pre {
129+ margin-bottom : 1rem ;
130+ }
131+
128132/* Banner styles - using styleguide colors where possible */
129133.banner {
130134 position : fixed ;
Original file line number Diff line number Diff line change @@ -2,6 +2,14 @@ module ApplicationHelper
22 def markdown ( text )
33 renderer = Redcarpet ::Render ::HTML . new ( escape_html : true )
44 markdown = Redcarpet ::Markdown . new ( renderer , fenced_code_blocks : true )
5+
6+ # Redcarpet needs the codeblocks to have 2 newlines before them
7+ # fixing this at render because it's not really required by Discord
8+ # it's just a quirk of Redcarpet
9+ if text . match? ( /[^\n ]\n ```(.*)\n ```/m )
10+ text = text . gsub ( /([^\n ])\n ```(.*?)\n ```/m , "\\ 1\n \n ```\\ 2\n ```" )
11+ end
12+
513 markdown . render ( text . to_s ) . html_safe
614 end
715end
Original file line number Diff line number Diff line change @@ -24,4 +24,18 @@ class ACodeBlock
2424
2525 assert_includes as_html , "<pre><code>class ACodeBlock"
2626 end
27+
28+ test "fixes newlines around code blocks" do
29+ puzzle_content = <<~CONTENT
30+ Some content with
31+ ```
32+ class ACodeBlock
33+ end
34+ ```
35+ in it
36+ CONTENT
37+ as_html = markdown ( puzzle_content )
38+
39+ assert_includes as_html , "with</p>\n \n <pre><code>class ACodeBlock"
40+ end
2741end
You can’t perform that action at this time.
0 commit comments