kotlin: fix linebreaks in code

Fixes #1729.
This commit is contained in:
Simon Legner 2022-04-08 21:25:35 +02:00
parent 34c2bcba2d
commit 114155cd32
2 changed files with 5 additions and 18 deletions

View file

@ -12,24 +12,6 @@ module Docs
css('a > img').each do |node|
node.parent.before(node.parent.content).remove
end
css('div.code-block').each do |node|
node.name = 'pre'
node['data-language'] = node['data-lang']
node.content = node.content
# FIXME: newlines in code-block are lost because of <div>? (on https://kotlinlang.org/docs/typecasts.html for instance)
end
css('pre').each do |node|
node['data-language'] = 'kotlin' if node.at_css('code.language-kotlin')
node['data-language'] = 'groovy' if node.at_css('code.language-groovy')
node['data-language'] = 'javascript' if node.at_css('code.language-javascript')
node['data-language'] = 'xml' if node.at_css('code.language-xml')
node.content = node.content
node.parent.remove_attribute('data-highlight-only')
node.parent.remove_attribute('data-lang')
node.parent.remove_attribute('theme')
end
end
def api_page

View file

@ -49,5 +49,10 @@ module Docs
return false unless super
response.body !~ /http-equiv="refresh"/i
end
def parse(response)
response.body.gsub! %r{<div\ class="code-block" data-lang="([^"]+)"[^>]*>([\W\w]+?)</div>}, '<pre class="code" data-language="\1">\2</pre>'
super
end
end
end