diff --git a/lib/puppet-strings/markdown/base.rb b/lib/puppet-strings/markdown/base.rb index f99adeacd..b9cf203a4 100644 --- a/lib/puppet-strings/markdown/base.rb +++ b/lib/puppet-strings/markdown/base.rb @@ -182,8 +182,7 @@ def word_wrap(text, line_width: 120, break_sequence: "\n") # @return [String] full markdown rendering of a component def render(template) begin - file = File.join(File.dirname(__FILE__),"templates/#{template}") - ERB.new(File.read(file), nil, '-').result(binding) + PuppetStrings::Markdown.erb(template).result(binding) rescue StandardError => e fail "Processing #{@registry[:file]}:#{@registry[:line]} with #{file} => #{e}" end @@ -196,4 +195,18 @@ def select_tags(name) tags.empty? ? nil : tags end end + + # Helper function to load an ERB template + # + # @param [String] template The template name, including the .erb suffix. + # @return [ERB] Template + def self.erb(template) + template_path = File.join(File.dirname(__FILE__), 'templates', template) + if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.0') + ERB.new(File.read(template_path), trim_mode: '-') + else + # This works in Ruby 2.6+, but it outputs warnings. + ERB.new(File.read(template_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..2a4d8f4f7 100644 --- a/lib/puppet-strings/markdown/table_of_contents.rb +++ b/lib/puppet-strings/markdown/table_of_contents.rb @@ -17,8 +17,7 @@ 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) + final += PuppetStrings::Markdown.erb('table_of_contents.erb').result(binding) end final end