Skip to content

Commit

Permalink
Switch to Kramdown for better rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
cdp1337 committed Jul 11, 2023
1 parent e432aa9 commit b1788a9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ gem 'http_accept_language', '~> 2.1'
gem 'httplog', '~> 1.6.2'
gem 'idn-ruby', require: 'idn'
gem 'kaminari', '~> 1.2'
gem 'kramdown', '~> 2.4'
gem 'kramdown-parser-gfm'
gem 'link_header', '~> 0.0'
gem 'mime-types', '~> 3.4.1', require: 'mime/types/columnar'
gem 'nokogiri', '~> 1.14'
Expand Down
26 changes: 26 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ GIT
hkdf (~> 0.2)
jwt (~> 2.0)

GIT
remote: https://github.com/kreeti/kt-paperclip.git
revision: 11abf222dc31bff71160a1d138b445214f434b2b
ref: 11abf222dc31bff71160a1d138b445214f434b2b
specs:
kt-paperclip (7.1.1)
activemodel (>= 4.2.0)
activesupport (>= 4.2.0)
marcel (~> 1.0.1)
mime-types
terrapin (~> 0.6.0)

GIT
remote: https://github.com/mastodon/rails-settings-cached.git
revision: 86328ef0bd04ce21cc0504ff5e334591e8c2ccab
branch: v0.6.6-aliases-true
specs:
rails-settings-cached (0.6.6)
rails (>= 4.2.0)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -361,6 +381,10 @@ GEM
activerecord
kaminari-core (= 1.2.2)
kaminari-core (1.2.2)
kramdown (2.4.0)
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
kt-paperclip (7.1.1)
activemodel (>= 4.2.0)
activesupport (>= 4.2.0)
Expand Down Expand Up @@ -811,6 +835,8 @@ DEPENDENCIES
json-ld-preloaded (~> 3.2)
json-schema (~> 3.0)
kaminari (~> 1.2)
kramdown (~> 2.4)
kramdown-parser-gfm
kt-paperclip (~> 7.1)
letter_opener (~> 1.8)
letter_opener_web (~> 2.0)
Expand Down
3 changes: 2 additions & 1 deletion app/javascript/styles/mastodon/components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,8 @@ body > [data-popper-placement] {

p {
margin-bottom: 20px;
white-space: pre-wrap;

/* white-space: pre-wrap; */
unicode-bidi: plaintext;

&:last-child {
Expand Down
13 changes: 11 additions & 2 deletions app/lib/advanced_text_formatter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# frozen_string_literal: true

require 'kramdown'
require 'kramdown-parser-gfm'


Check failure on line 6 in app/lib/advanced_text_formatter.rb

View workflow job for this annotation

GitHub Actions / lint

[Correctable] Layout/EmptyLines: Extra blank line detected. (https://rubystyle.guide#two-or-more-empty-lines)
class AdvancedTextFormatter < TextFormatter
class HTMLRenderer < Redcarpet::Render::HTML
def initialize(options, &block)
Expand Down Expand Up @@ -97,8 +101,13 @@ def rewrite
private

def format_markdown(html)
html = markdown_formatter.render(html)
html.delete("\r").delete("\n")
# if redcarpet @todo
#html = markdown_formatter.render(html)

Check failure on line 105 in app/lib/advanced_text_formatter.rb

View workflow job for this annotation

GitHub Actions / lint

[Correctable] Layout/LeadingCommentSpace: Missing space after #. (https://rubystyle.guide#hash-space)
options = {
input: 'GFM',
}
html = Kramdown::Document.new(html, options).to_html

Check warning on line 109 in app/lib/advanced_text_formatter.rb

View workflow job for this annotation

GitHub Actions / lint

Lint/UselessAssignment: Useless assignment to variable - html. (https://rubystyle.guide#underscore-unused-vars)
# html.delete("\r").delete("\n")
end

def markdown_formatter
Expand Down

0 comments on commit b1788a9

Please sign in to comment.