docbrown/app/lib/redcarpet/render/html_rouge.rb
Ben Halpern 3a469a99e2
[deploy] Enable admin-configured app_domain (#10206)
* Move app_domain from env var to siteconfig *within app area*

* Fix SiteConfig

* Don't change URL.domain yet

* Not use in fastly cache purge yet

* Session store magoo

* Revert domain issue

* Add SetCookie middleware

* Temporarily remove cookie middleware and release tasks

* Re-enable SetCookieDomain

* Add some more comments, get it ready for testing

* Remove host from url options and temporarily show errors

* Allow forwarded host to be cookie

* Fix typo

* Change invalidAuthenticityToken

* Properly set app domain

* Proper Fastly cache

* Remove config.app_domain

* Remove config.app_domain

* Explicitely set remember_user_token

* More play with cookies

* Fiddle with remember_user_token

* Add remember_user_token changes

* Monkeypatch devise

* Sessions controller

* Include rememberable

* Include rememberable

* Proper cookie monkeypatch

* Proper cookie monkeypatch

* Proper cookie monkeypatch

* Remove extra cookie code

* User sign in tweak

* Close the loop

* Experiment with carrierwave public_url

* Finalize carrierwave monkeypatch

* Remove async controller specs

* Change some tests

* Update domain test

* Remove temporary production.rb change

* modify cookie logic

* Remove unneeded changes

* Remove unneeded changes

* Explicitely pass host

* Fix linting

* Fix social image test

* Add some cookie tests

* Modify article url

* Fix canonical urls

* Fix typo

* Remove sessions controller

* Remove devise monkeypatch

* Add monkeypatch

* Remove elsif

* Update spec/helpers/application_helper_spec.rb

Co-authored-by: Michael Kohl <citizen428@dev.to>

* Adjust remember_cookie_sync

* Remember user token experimentation

* Fiddle with devise

* Properly configure devise

* Fix typo

* Fix formatting issue

* Add comment about middleware

* Fix typo

Co-authored-by: Vaidehi Joshi <vaidehi.sj@gmail.com>

* Remove commented-out code

Co-authored-by: Michael Kohl <citizen428@dev.to>
Co-authored-by: Vaidehi Joshi <vaidehi.sj@gmail.com>
2020-09-11 09:38:34 -04:00

62 lines
1.9 KiB
Ruby

require "rouge/plugins/redcarpet"
module Redcarpet
module Render
class HTMLRouge < HTML
include Rouge::Plugins::Redcarpet
# Rouge requires the hint language to be lower case, by overriding this
# method we can allow the hint language to be specified with other casings
# eg. `Ada` instead of `ada`
def block_code(code, language)
super(code, language.to_s.downcase)
end
def link(link, _title, content)
# Probably not the best fix but it does it's job of preventing
# a nested links.
return if %r{<a\s.+/a>}.match?(content)
link_attributes = ""
@options[:link_attributes]&.each do |attribute, value|
link_attributes += %( #{attribute}="#{value}")
end
if (%r{https?://\S+}.match? link) || link.nil?
%(<a href="#{link}"#{link_attributes}>#{content}</a>)
elsif /\.{1}/.match? link
%(<a href="//#{link}"#{link_attributes}>#{content}</a>)
elsif link.start_with?("#")
%(<a href="#{link}"#{link_attributes}>#{content}</a>)
else
%(<a href="#{app_protocol}#{app_domain}#{link}"#{link_attributes}>#{content}</a>)
end
end
def header(title, header_number)
anchor_link = slugify(title)
<<~HEREDOC
<h#{header_number}>
<a name="#{anchor_link}" href="##{anchor_link}" class="anchor">
</a>
#{title}
</h#{header_number}>
HEREDOC
end
private
def app_protocol
ApplicationConfig["APP_PROTOCOL"]
end
def app_domain
SiteConfig.app_domain
end
def slugify(string)
stripped_string = ActionView::Base.full_sanitizer.sanitize string
stripped_string.downcase.gsub(EmojiRegex::Regex, "").strip.gsub(/[[:punct:]]/u, "").gsub(/\s+/, "-")
end
end
end
end