diff --git a/lib/puppet-strings/markdown/base.rb b/lib/puppet-strings/markdown/base.rb index 455aacdad..2a40cf515 100644 --- a/lib/puppet-strings/markdown/base.rb +++ b/lib/puppet-strings/markdown/base.rb @@ -172,9 +172,9 @@ def word_wrap(text, line_width: 120, break_sequence: "\n") # @return [String] full markdown rendering of a component def render(template) + file = File.join(File.dirname(__FILE__), 'templates', template) begin - file = File.join(File.dirname(__FILE__),"templates/#{template}") - ERB.new(File.read(file), nil, '-').result(binding) + PuppetStrings::Markdown.erb(file).result(binding) rescue StandardError => e fail "Processing #{@registry[:file]}:#{@registry[:line]} with #{file} => #{e}" end @@ -199,4 +199,17 @@ def clean_link(input) input.tr('^a-zA-Z0-9_-', '-') end end + + # Helper function to load an ERB template. + # + # @param [String] path The full path to the template file. + # @return [ERB] Template + def self.erb(path) + if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.0') + ERB.new(File.read(path), trim_mode: '-') + else + # This outputs warnings in Ruby 2.6+. + ERB.new(File.read(path), nil, '-') + end + end end diff --git a/lib/puppet-strings/markdown/table_of_contents.rb b/lib/puppet-strings/markdown/table_of_contents.rb index 89883ecae..5f7e15382 100644 --- a/lib/puppet-strings/markdown/table_of_contents.rb +++ b/lib/puppet-strings/markdown/table_of_contents.rb @@ -17,8 +17,8 @@ def self.render group = toc priv = r.contains_private? - template = File.join(File.dirname(__FILE__),"templates/table_of_contents.erb") - final += ERB.new(File.read(template), nil, '-').result(binding) + template = File.join(File.dirname(__FILE__), 'templates/table_of_contents.erb') + final += PuppetStrings::Markdown.erb(template).result(binding) end final end