Skip to content
Permalink
Browse files

Handle gcse:search

  • Loading branch information...
ddfreyne committed Feb 21, 2018
1 parent e7d915a commit b9fe397adbed6cb572afc7383e76d714ecfad78f
Showing with 25 additions and 1 deletion.
  1. +3 −1 nanoc/lib/nanoc/filters/relativize_paths.rb
  2. +22 −0 nanoc/spec/nanoc/regressions/gh_1319_spec.rb
@@ -106,6 +106,8 @@ def nokogiri_process(content, selectors, namespaces, klass, type, nokogiri_save_
# Ensure that all prefixes are strings
namespaces = namespaces.reduce({}) { |new, (prefix, uri)| new.merge(prefix.to_s => uri) }

content = content.gsub('gcse:search', 'nanoc__gcse_search_workaround')

doc = content =~ /<html[\s>]/ ? klass.parse(content) : klass.fragment(content)
selector = selectors.map { |sel| "descendant-or-self::#{sel}" }.join('|')
doc.xpath(selector, namespaces).each do |node|
@@ -121,7 +123,7 @@ def nokogiri_process(content, selectors, namespaces, klass, type, nokogiri_save_
doc.to_html(save_with: nokogiri_save_options)
else
doc.send("to_#{type}", save_with: nokogiri_save_options)
end
end.gsub('nanoc__gcse_search_workaround', 'gcse:search')
end

def nokogiri_process_comment(node, doc, selectors, namespaces, klass, type)
@@ -0,0 +1,22 @@
# frozen_string_literal: true

describe 'GH-1248', site: true, stdio: true do
before do
File.write('content/stuff.html', '<gcse:search>abc</gcse:search>')

File.write('Rules', <<~EOS)
compile '/**/*' do
filter :relativize_paths, type: :html
write ext: 'html'
end
EOS
end

before do
Nanoc::CLI.run(%w[compile])
end

example do
expect(File.read('output/stuff.html')).to eq('<gcse:search>abc</gcse:search>')
end
end

0 comments on commit b9fe397

Please sign in to comment.
You can’t perform that action at this time.