]> git.draconx.ca Git - homepage.git/commitdiff
Improve script hack compatibility.
authorNick Bowler <nbowler@draconx.ca>
Wed, 17 Feb 2021 04:01:02 +0000 (23:01 -0500)
committerNick Bowler <nbowler@draconx.ca>
Wed, 17 Feb 2021 04:04:23 +0000 (23:04 -0500)
Old versions of Netscape will actually try and execute these
definitely-not-javascript hacks as Javascript.  So let's try to
avoid that from happening by making the contents look like one
big Javascript comment.

We might need an additional workaround if any of the contents
contains a literal */.  We'll cross that bridge when we get to it.

lib/xhtml-compat.rb

index f69c1eeaad19df9320b1655b30c64297070c30b4..25fe2e2a6e3a88f5cb92efac5555d084309ab1ba 100644 (file)
@@ -20,6 +20,9 @@ class XhtmlCompatFilter < Nanoc::Filter
     identifier :xhtml_compat
 
     def run(content, params = {})
-        return content.gsub(/([^[:space:]])\/>/m, '\1 />');
+        text = content.gsub(/([^[:space:]])\/>/m, '\1 />');
+        text.gsub!("<![CDATA[]]x><!--]]>", '/*\&')
+        text.gsub!("<![CDATA[-->]]>", '\&*/')
+        return text
     end
 end