From 825315fbb0673eedb0963d76878f3ea91f18e255 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Tue, 8 Jan 2019 20:23:36 -0500 Subject: [PATCH] Work around Nokogiri pretty-print issues. In general, pretty-printing XHTML will change its meaning because whitespace added or removed can affect the results. Instead of using the xsl:strip-space functionality which is quite limited, use a normal template to remove unwanted whitespace-only text nodes which can be manually tweaked as required. Then we explicitly add dummy nodes to prevent Nokogiri from reindenting problematic cases, and finally clean those out just before publishing (after all XSLT processing is finished). --- Rules | 3 ++ layouts/default.xsl | 61 ++++++++++++++++++++++++++++++++++--- layouts/functions.xsl | 70 +++++++++++++++++++++++++++++++++++++++++++ lib/removewj.rb | 25 ++++++++++++++++ 4 files changed, 155 insertions(+), 4 deletions(-) create mode 100644 layouts/functions.xsl create mode 100644 lib/removewj.rb diff --git a/Rules b/Rules index 06f3a11..e81b5e2 100644 --- a/Rules +++ b/Rules @@ -36,6 +36,7 @@ compile '/**/*.md' do layout '/default.xml' layout '/default.xsl' filter :relativize_paths, type: :xml + filter :remove_wj write to_xhtml end @@ -45,6 +46,7 @@ compile '/license/cc*.sgml' do layout '/default.xml' layout '/default.xsl' filter :relativize_paths, type: :xml + filter :remove_wj write to_xhtml end @@ -53,6 +55,7 @@ compile '/license/cc*.xhtml' do layout '/default.xml' layout '/default.xsl' filter :relativize_paths, type: :xml + filter :remove_wj write to_xhtml end diff --git a/layouts/default.xsl b/layouts/default.xsl index 2af8dc2..d7381d5 100644 --- a/layouts/default.xsl +++ b/layouts/default.xsl @@ -1,8 +1,8 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +--> + + + + + + + + + + + + + + + diff --git a/lib/removewj.rb b/lib/removewj.rb new file mode 100644 index 0000000..18264dd --- /dev/null +++ b/lib/removewj.rb @@ -0,0 +1,25 @@ +# Nick's web site: remove_wj filter. Delete all zero-width word joiners +# which were added during XSLT processing. +# +# Copyright © 2019 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 . + +class RemoveWJFilter < Nanoc::Filter + identifier :remove_wj + + def run(content, params = {}) + return content.delete "\u2060" + end +end -- 2.43.0