* Update rubocop-todo.yml with new violations * Fix Layout/EmptyLine* rules * Fix Layout/Indentation* rules * Fix remaining Layout/* rules * Fix Lint/DuplicateMethods by removing unused accessor * Fix Lint/IneffectiveAccessModifier * Fix Lint/MissingCopEnableDirective * Re-run rubocop auto gen config * Fix Layout/RescueEnsureAlignment * Fix Naming/* rules * Fix some RSpec/* rules * Fix typos * Fix RSpec/LetBeforeExamples * Series should only be an attr_writer, not an attr_accessor * Fix RSpec/InstanceVariable * Fix RSpec/InstanceVariable * Fix RSpec/RepeatedDescription and RSpec/RepeatedExample * Fix Style/ClassAndModuleChildren * Fix Style/ConditionalAssignment * Fix some Style/* rules * Trigger Travis CI build because failing tests are not failing locally * Revert "Fix Style/ClassAndModuleChildren" This reverts commit 1686801d8a1516ba1894f79e24401a20dea65f99.
39 lines
1.1 KiB
Ruby
39 lines
1.1 KiB
Ruby
require "rouge/plugins/redcarpet"
|
|
|
|
module Redcarpet
|
|
module Render
|
|
class HTMLRouge < HTML
|
|
include Rouge::Plugins::Redcarpet
|
|
|
|
def link(link, _title, content)
|
|
# Probably not the best fix but it does it's job of preventing
|
|
# a nested links.
|
|
return nil if /<a\s.+\/a>/.match?(content)
|
|
|
|
link_attributes = ""
|
|
@options[:link_attributes]&.each do |attribute, value|
|
|
link_attributes += %( #{attribute}="#{value}")
|
|
end
|
|
%(<a href="#{link}"#{link_attributes}>#{content}</a>)
|
|
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 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
|