]> git.draconx.ca Git - homepage.git/commitdiff
Add spaces in self-closing XML tags.
authorNick Bowler <nbowler@draconx.ca>
Sun, 21 Jun 2020 16:14:01 +0000 (12:14 -0400)
committerNick Bowler <nbowler@draconx.ca>
Sun, 21 Jun 2020 16:18:56 +0000 (12:18 -0400)
Some very old browsers that do not implement XHTML get confused by
tags like <hr/> but have no problem with <hr />.  This is very easy
to accomodate so let's do it.

Rules
lib/xhtml-compat.rb [new file with mode: 0644]

diff --git a/Rules b/Rules
index d0a81fb8c496c7f2232393bdba6f32dbd68fdc30..a7dffeef792cb601a11b44497a7a7c767d520461 100644 (file)
--- a/Rules
+++ b/Rules
@@ -1,6 +1,6 @@
 #!/usr/bin/env ruby
 #
-# Copyright © 2018-2019 Nick Bowler
+# Copyright © 2018-2020 Nick Bowler
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -54,6 +54,7 @@ compile '/license/gpl*.md' do
     layout '/gpl.xsl'
     layout '/default.xsl'
     filter :relativize_paths, type: :xml
+    filter :xhtml_compat
     filter :remove_wj
     write to_xhtml
 end
@@ -65,6 +66,7 @@ compile '/**/*.md' do
     layout '/default.xml'
     layout '/default.xsl'
     filter :relativize_paths, type: :xml
+    filter :xhtml_compat
     filter :remove_wj
     write to_xhtml
 end
@@ -75,6 +77,7 @@ compile '/license/cc*.sgml' do
     layout '/default.xml'
     layout '/default.xsl'
     filter :relativize_paths, type: :xml
+    filter :xhtml_compat
     filter :remove_wj
     write to_xhtml
 end
@@ -84,6 +87,7 @@ compile '/license/cc*.xhtml' do
     layout '/default.xml'
     layout '/default.xsl'
     filter :relativize_paths, type: :xml
+    filter :xhtml_compat
     filter :remove_wj
     write to_xhtml
 end
diff --git a/lib/xhtml-compat.rb b/lib/xhtml-compat.rb
new file mode 100644 (file)
index 0000000..f69c1ee
--- /dev/null
@@ -0,0 +1,25 @@
+# Nick's web site: xhtml_compat filter.  Add whitespace before the end
+# of empty element tags to improve compatibility with old browsers.
+#
+# Copyright © 2020 Nick Bowler
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+class XhtmlCompatFilter < Nanoc::Filter
+    identifier :xhtml_compat
+
+    def run(content, params = {})
+        return content.gsub(/([^[:space:]])\/>/m, '\1 />');
+    end
+end