[devdocsgjs/main: 7/64] kotlin: fix linebreaks in code




commit 114155cd322a2ad2940f097d2e05074badba73a3
Author: Simon Legner <Simon Legner gmail com>
Date:   Fri Apr 8 21:25:35 2022 +0200

    kotlin: fix linebreaks in code
    
    Fixes #1729.

 lib/docs/filters/kotlin/clean_html.rb | 18 ------------------
 lib/docs/scrapers/kotlin.rb           |  5 +++++
 2 files changed, 5 insertions(+), 18 deletions(-)
---
diff --git a/lib/docs/filters/kotlin/clean_html.rb b/lib/docs/filters/kotlin/clean_html.rb
index e65216d5..38a2b8d8 100644
--- a/lib/docs/filters/kotlin/clean_html.rb
+++ b/lib/docs/filters/kotlin/clean_html.rb
@@ -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
diff --git a/lib/docs/scrapers/kotlin.rb b/lib/docs/scrapers/kotlin.rb
index 9212bbec..38882986 100644
--- a/lib/docs/scrapers/kotlin.rb
+++ b/lib/docs/scrapers/kotlin.rb
@@ -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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]