Browse Source

sanctuary: simplify filter

Simon Legner 3 years ago
parent
commit
0536298501
2 changed files with 9 additions and 25 deletions
  1. 1 25
      lib/docs/filters/sanctuary/clean_html.rb
  2. 8 0
      lib/docs/scrapers/sanctuary.rb

+ 1 - 25
lib/docs/filters/sanctuary/clean_html.rb

@@ -1,11 +1,3 @@
-def repeat(n, s)
-  Array.new(n, s).join("")
-end
-
-def _(n)
-  repeat(n, " ")
-end
-
 module Docs
 
   class Sanctuary
@@ -44,23 +36,7 @@ module Docs
               node
                 .css("input")
                 .map { |node| "> " + node.attributes["value"].value }
-                .zip(node.css(".output").map { |node|
-                  if node.content.start_with?("! Invalid value")
-                    # XXX: Reinstate newlines and consecutive spaces.
-                    content = node.content.dup()
-                    content[ 15] = "\n\n"
-                    content[ 68] = "\n" + _("add :: FiniteNumber -> ".size)
-                    content[104] = "\n" + _("add :: FiniteNumber -> ".size + ("FiniteNumber".size - 1) / 2)
-                    content[134] = "\n\n"
-                    content[138] = _(2)
-                    content[155] = "\n\n"
-                    content[215] = "\n\n"
-                    content[337] = "\n"
-                    content
-                  else
-                    node.content
-                  end
-                })
+                .zip(node.css(".output").map { |node| node.content })
                 .map { |pair| pair.join("\n") }
                 .join("\n\n"),
               {"data-language" => "javascript"}

+ 8 - 0
lib/docs/scrapers/sanctuary.rb

@@ -20,6 +20,14 @@ module Docs
     def get_latest_version(opts)
       get_npm_version("sanctuary", opts)
     end
+
+    private
+
+    def parse(response) # Hook here because Nokogori removes whitespace from textareas
+      response.body.gsub! %r{<div class="output"[^>]*>([\W\w]+?)</div>}, '<pre class="output">\1</pre>'
+      super
+    end
+
   end
 
 end