Module: PuppetStrings::Markdown::Helpers

Included in:
Base
Defined in:
lib/puppet-strings/markdown/helpers.rb

Overview

Helpers for rendering Markdown

Instance Method Summary collapse

Instance Method Details

#code_maybe_block(code, type: :puppet, block_prefix: "\n\n", inline_prefix: ' ') ⇒ Object

Formats code as either inline or a block.

Note that this does not do any escaping even if the code contains ‘ or “`.

Parameters:

  • code (String)

    The code to format.

  • type (Symbol) (defaults to: :puppet)

    The type of the code, e.g. :text, :puppet, or :ruby.

  • block_prefix (String) (defaults to: "\n\n")

    String to insert before if it’s a block.

  • inline_prefix (String) (defaults to: ' ')

    String to insert before if it’s inline.



14
15
16
17
18
19
20
# File 'lib/puppet-strings/markdown/helpers.rb', line 14

def code_maybe_block(code, type: :puppet, block_prefix: "\n\n", inline_prefix: ' ')
  if code.to_s.include?("\n")
    "#{block_prefix}```#{type}\n#{code}\n```"
  else
    "#{inline_prefix}`#{code}`"
  end
end