fix: Multiline alerts are now handled

This commit is contained in:
imtodor 2018-10-18 10:24:50 +03:00
Родитель b7611f891f
Коммит c99fdf0c3b
1 изменённых файлов: 27 добавлений и 27 удалений

Просмотреть файл

@ -1,36 +1,36 @@
module Reading module Reading
class Generator < Jekyll::Generator class Generator < Jekyll::Generator
def generate(site) def generate(site)
@site = site @site = site
@converter = site.find_converter_instance(Jekyll::Converters::Markdown) @converter = site.find_converter_instance(Jekyll::Converters::Markdown)
site.pages.each do |p| site.pages.each do |p|
createAlert("tip", p.content) createAlert("tip", p.content)
createAlert("important", p.content) createAlert("important", p.content)
createAlert("caution", p.content) createAlert("caution", p.content)
end end
end end
def createAlert(alertType, content) def createAlert(alertType, content)
sub_string = content.scan(/(>#{alertType})(.*)/) sub_string = content.scan(/(>#{alertType})((.|\n[\w\*\[!^<>|#])*)/)
if sub_string.count == 0 if sub_string.count == 0
##puts "no " + alertType + "s" ##puts "no " + alertType + "s"
else else
sub_string.each do |s| sub_string.each do |s|
block ="<blockquote class='#{alertType}'>" + @converter.convert(s[1]) + "</blockquote>" block ="<blockquote class='#{alertType}'>" + @converter.convert(s[1].gsub(/(^>)/x, "")) + "</blockquote>"
slugsInBlock = block.scan(/.*?(%7[Bb]%slug%20([\w-]+)%{2}7[Dd])/) slugsInBlock = block.scan(/.*?(%7[Bb]%slug%20([\w-]+)%{2}7[Dd])/)
if slugsInBlock.count > 0 if slugsInBlock.count > 0
slugsInBlock.each do |slug| slugsInBlock.each do |slug|
targetPage = @site.pages.find {|p| p.data['slug'] == slug[1]} targetPage = @site.pages.find {|p| p.data['slug'] == slug[1]}
if targetPage if targetPage
link = @site.baseurl + targetPage.url.sub('.html', '') link = @site.baseurl + targetPage.url.sub('.html', '')
block.sub!(slug[0], link) block.sub!(slug[0], link)
end end
end end
end end
content.sub!(s[0]+s[1], block) content.sub!(s[0]+s[1], block)
end end
end end
end end
end end
end end