From 4936d05adc770088f966881b92a0d4bfaef02d3e Mon Sep 17 00:00:00 2001 From: Lina Date: Wed, 8 Feb 2023 22:07:53 +0000 Subject: [PATCH] better code blocks --- .../flavours/glitch/styles/forms.scss | 32 ++++++++++++++++++- app/lib/advanced_text_formatter.rb | 2 +- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/javascript/flavours/glitch/styles/forms.scss b/app/javascript/flavours/glitch/styles/forms.scss index 6a73b3a2ce..06b23b6659 100644 --- a/app/javascript/flavours/glitch/styles/forms.scss +++ b/app/javascript/flavours/glitch/styles/forms.scss @@ -2,7 +2,37 @@ $no-columns-breakpoint: 600px; code { font-family: $font-monospace, monospace; - font-weight: 400; + border-radius: 3px; + padding: 0 0.4em; + background: darken($ui-base-color, 8%); +} + +pre { + background: darken($ui-base-color, 8%); + border-radius: 3px; + padding: 0.75em; + counter-reset: line; + overflow-x: scroll; +} + +pre code { + counter-increment: line; + padding: 0; + white-space: pre; +} + +pre code::before { + font-size: 0.8em; + color: darken($primary-text-color, 33%); + content: counter(line); + display: inline-block; + border-right: 1px solid darken($primary-text-color, 33%); + margin: -0.05em 0.7em -0.05em 0; + padding: 0.05em 0.5em 0.05em 0; + text-align: right; + width: 1.2em; + white-space: nowrap; + direction: rtl; } .form-container { diff --git a/app/lib/advanced_text_formatter.rb b/app/lib/advanced_text_formatter.rb index 21e81d4d1e..0c73975d34 100644 --- a/app/lib/advanced_text_formatter.rb +++ b/app/lib/advanced_text_formatter.rb @@ -9,7 +9,7 @@ class AdvancedTextFormatter < TextFormatter def block_code(code, _language) <<~HTML -
#{ERB::Util.h(code).gsub("\n", '
')}
+
#{ERB::Util.h(code.rstrip).gsub("\n", '
')}
HTML end