Browse Source

Titles (h1, h2) are changed to h3 for markdown digests

remotes/origin/master
echarp 3 years ago
parent
commit
fa04fc1259
  1. 2
      app/helpers/events_helper.rb
  2. 13
      test/helpers/events_helper_test.rb

2
app/helpers/events_helper.rb

@ -65,10 +65,10 @@ module EventsHelper
attributes: %w[href]
Kramdown::Document.new(spaces(desc), input: :html, line_width: line_width)
.to_kramdown
.gsub(/^#+ (.*)/, '### \1')
.gsub(/\\([\"'])/, '\1') # Remove slash before quotes
.remove(/[[:blank:]]+$/) # Remove extraneous spaces
.remove(/{::}/) # Markdown artefact
.gsub(/^#+ (.*)/, '**\1**')
end
private

13
test/helpers/events_helper_test.rb

@ -19,8 +19,15 @@ class EventsHelperTest < ActionView::TestCase
assert_equal '*ho* **h**,', to_markdown('<i>ho</i><b> h</b>,')
end
test 'HTML titles to strong' do
assert_equal '**Big**', to_markdown('<h1>Big</h1>,')
assert_equal '**Big again**', to_markdown('<h2>Big again</h2>,')
test 'HTML titles too strong' do
assert_equal '### Big
', to_markdown('<h1>Big</h1>')
assert_equal '### Big again
', to_markdown('<h2>Big again</h2>')
assert_equal '### **Too**
', to_markdown('<h3><strong>Too</strong></h3>')
end
end

Loading…
Cancel
Save