File: commonmarker.rb

package info (click to toggle)
ruby-commonmarker 0.20.2-1~bpo10%2B1
  • links: PTS, VCS
  • area: main
  • in suites: buster-backports
  • size: 1,232 kB
  • sloc: ansic: 10,122; ruby: 1,539; makefile: 6
file content (44 lines) | stat: -rwxr-xr-x 1,560 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env ruby
# frozen_string_literal: true

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