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

This commit is contained in:
echarp 2019-03-03 18:11:06 +00:00
parent e3936359b9
commit fa04fc1259
2 changed files with 11 additions and 4 deletions

View File

@ -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

View File

@ -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