Sha256: 421d9623985d294ab594e4cd6e729a5173fb27baba820f00948ce23387d14997

Contents?: true

Size: 1.49 KB

Versions: 38

Compression:

Stored size: 1.49 KB

Contents

#!/usr/bin/env ruby
require 'commonmarker/commonmarker'
require 'commonmarker/config'
require 'commonmarker/node'
require 'commonmarker/renderer'
require 'commonmarker/renderer/html_renderer'
require 'commonmarker/version'

begin
  require 'awesome_print'
rescue LoadError; end

module CommonMarker
  # Public:  Parses a Markdown string into an HTML string.
  #
  # text - A {String} of text
  # option - Either a {Symbol} or {Array of Symbol}s indicating the render options
  # extensions - An {Array of Symbol}s indicating the extensions to use
  #
  # Returns a {String} of converted HTML.
  def self.render_html(text, options = :DEFAULT, extensions = [])
    fail TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String)
    opts = Config.process_options(options, :render)
    text = text.encode('UTF-8')
    html = Node.markdown_to_html(text, opts, extensions)
    html.force_encoding('UTF-8')
  end

  # Public: Parses a Markdown string into a `document` node.
  #
  # string - {String} to be parsed
  # option - A {Symbol} or {Array of Symbol}s indicating the parse options
  # extensions - An {Array of Symbol}s indicating the extensions to use
  #
  # Returns the `document` node.
  def self.render_doc(text, options = :DEFAULT, extensions = [])
    fail TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String)
    opts = Config.process_options(options, :parse)
    text = text.encode('UTF-8')
    Node.parse_document(text, text.bytesize, opts, extensions)
  end
end

Version data entries

38 entries across 38 versions & 2 rubygems

Version Path
commonmarker-0.16.6 lib/commonmarker.rb
commonmarker-0.16.5 lib/commonmarker.rb
commonmarker-0.16.4 lib/commonmarker.rb
commonmarker-0.16.1 lib/commonmarker.rb
commonmarker-0.16.2 lib/commonmarker.rb
commonmarker-0.16.3 lib/commonmarker.rb
commonmarker-0.16.0 lib/commonmarker.rb
commonmarker-0.15.0 lib/commonmarker.rb
commonmarker-0.14.15 lib/commonmarker.rb
commonmarker-0.14.14 lib/commonmarker.rb
commonmarker-0.14.13 lib/commonmarker.rb
commonmarker-0.14.12 lib/commonmarker.rb
commonmarker-0.14.11 lib/commonmarker.rb
commonmarker-0.14.9 lib/commonmarker.rb
commonmarker-0.14.8 lib/commonmarker.rb
commonmarker-0.14.7 lib/commonmarker.rb
commonmarker-0.14.6 lib/commonmarker.rb
commonmarker-0.14.5 lib/commonmarker.rb