Class: MultiMarkdown

Inherits:
Object
  • Object
show all
Defined in:
lib/multimarkdown.rb,
lib/multimarkdown/version.rb,
ext/multimarkdown.c

Overview

Front-end to fletcher penney’s implementation of MultiMarkdown

A simple processor:

>> puts MultiMarkdown.new("Hello, World.").to_html
<p>Hello, World.</p>

With other stuff:

>> puts MultiMarkdown.new("_Hello World!_", :smart, :filter_html).to_html
<p><em>Hello World!</em></p>

Constant Summary collapse

EXTENSIONS =
{
  "compatibility" => {:desc => "Markdown compatibility mode (disables all other options)", :short => "c"},
  "complete" => {:desc => "Force complete document", :short => "f"},
  "snippet" => {:desc => "Force snippet only", :short => "s"},
  "no_smart_quotes" => {:desc => "Disable Smart quotes", :short => false},
  "no_footnotes" => {:desc => "Disable Footnotes", :short => false},
  "no_anchors" => {:desc => "Don't add anchors to headers, etc.", :short => false},
  "filter_styles" => {:desc => "Filter out style blocks", :short => false},
  "filter_html" => {:desc => "Filter out raw HTML", :short => false},
  "process_html" => {:desc => "Process Markdown inside HTML", :short => false},
  "no_metadata" => {:desc => "Don't parse Metadata", :short => false},
  "obfuscate_email_addresses" => {:desc => "Mask email addresses", :short => false},
  "critic_markup_accept_all" => {:desc => "CriticMarkup: Accept all proposed changes", :short => "a"},
  "critic_markup_reject_all" => {:desc => "CriticMarkup: Reject all proposed changes", :short => "r"},
  "random_footnote_anchor_numbers" => {:desc => "Use random numbers for footnote link anchors", :short => false},
  "escaped_line_breaks" => {:desc => "Escaped line break", :short => false}
}
VERSION =

The ruby ‘multimarkdown’ gem version

"5.3.0.1"
MMD_VERSION =
rb_str_new2("5.2.0")

Instance Method Summary collapse

Constructor Details

#initialize(text, *extensions) ⇒ MultiMarkdown

Create a new MultiMarkdown processor. The ‘text` argument is a string containing MultiMarkdown text. Variable other arguments may be supplied to set various processing options. See MultiMarkdown::EXTENSIONS for more.



41
42
43
44
45
46
47
# File 'lib/multimarkdown.rb', line 41

def initialize(text, *extensions)
  @text = text
  extensions.each do |ext|
    raise "Unknown extension: #{ext.inspect}" unless EXTENSIONS.keys.include?(ext.to_s)
    send("#{ext}=", true)
  end
end

Instance Method Details

#extract_metadata_keysObject

Return Array of metadata keys



80
81
82
83
84
85
86
# File 'ext/multimarkdown.c', line 80

static VALUE (VALUE self) {
  char * = (get_text(self), get_exts(self));
  VALUE str = encoded_str_new2(, "UTF-8");
  free();

  return rb_funcall(str, rb_intern("split"), 1, rb_str_new2("\n"));
}

#extract_metadata_value(key) ⇒ Object Also known as: extract_metadata

:call-seq: extract_metadata_value(key)

Fetches metadata specified by key from MultiMarkdown text



88
89
90
91
92
93
94
95
96
97
# File 'ext/multimarkdown.c', line 88

static VALUE (VALUE self, VALUE key) {
  Check_Type(key, T_STRING);
  char *pkey = StringValuePtr(key);

  char * = (get_text(self), get_exts(self), pkey);
  VALUE result = encoded_str_new2(, "UTF-8");
  free();

  return result;
}

#metadata(key = nil) ⇒ Object

Returns a Hash cointaining all Metadata



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/multimarkdown.rb', line 54

def (key = nil)
  if .nil?
     = {}
    .each do |k|
      [k.downcase] = (k)
    end
  end

  if key
    [key.to_s.downcase]
  else
    .dup
  end
end

#to_htmlObject

Return string containing HTML generated from MultiMarkdown text



64
65
66
67
68
69
70
# File 'ext/multimarkdown.c', line 64

static VALUE rb_multimarkdown_to_html(VALUE self) {
  char *html = markdown_to_string(get_text(self), get_exts(self), HTML_FORMAT);
  VALUE result = encoded_str_new2(html, "UTF-8");
  free(html);

  return result;
}

#to_latexObject

Return string containing latex generated from MultiMarkdown text



72
73
74
75
76
77
78
# File 'ext/multimarkdown.c', line 72

static VALUE rb_multimarkdown_to_latex(VALUE self) {
  char *latex = markdown_to_string(get_text(self), get_exts(self), LATEX_FORMAT);
  VALUE result = encoded_str_new2(latex, "UTF-8");
  free(latex);

  return result;
}