Sha256: 3f703e5f74728eb701df7b53afdf5b110d4f64fffeae1d85c048ee67090cbe5e
Contents?: true
Size: 991 Bytes
Versions: 35
Compression:
Stored size: 991 Bytes
Contents
# encoding: utf-8 class MarkdownString class << self # Return markdown heading level1-6 from text # # === Example # # MarkdownString.heading1("title") # => "# title" # MarkdownString.heading2("title") # => "## title" # MarkdownString.heading3("title") # => "### title" # MarkdownString.heading4("title") # => "#### title" # MarkdownString.heading5("title") # => "##### title" # MarkdownString.heading6("title") # => "###### title" # MarkdownString.heading1("") # => "# " # MarkdownString.heading1(nil) # => "# " # MarkdownString.heading1(12345) # => "# 12345" # [*1..6].each do |i| define_method "heading#{i}".to_sym do |text| heading(text, i) end end end private def self.heading(text, level) return '#' * level + ' ' if text.nil? return '#' * level + ' ' if text.respond_to?(:empty) && text.empty? '#' * level + " #{text}" end end
Version data entries
35 entries across 35 versions & 1 rubygems