Class: MultiMarkdown
- Inherits:
-
Object
- Object
- MultiMarkdown
- Defined in:
- lib/multi_markdown.rb,
lib/multi_markdown/version.rb,
ext/multi_markdown.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
- VERSION =
The ruby ‘multimarkdown’ gem version
"4.5.0.2"
- MMD_VERSION =
rb_str_new2(MMD_VERSION)
Instance Attribute Summary collapse
-
#compatibility ⇒ Object
Markdown compatibility mode.
-
#filter_html ⇒ Object
Do not output any raw HTML included in the source text.
-
#filter_styles ⇒ Object
Do not output ‘<style>` tags included in the source text.
-
#fold_lines ⇒ Object
Included for compatibility with RedCloth’s interface.
-
#notes ⇒ Object
Set ‘true` to have footnotes processed.
-
#process_html ⇒ Object
Process MultiMarkdown inside of raw HTML.
-
#smart ⇒ Object
Set ‘true` to have smarty-like quote translation performed.
Instance Method Summary collapse
-
#extract_metadata_keys ⇒ Object
Return Array of metadata keys.
-
#extract_metadata_value(key) ⇒ Object
(also: #extract_metadata)
:call-seq: extract_metadata_value(key).
-
#initialize(text, *extensions) ⇒ MultiMarkdown
constructor
Create a new MultiMarkdown processor.
-
#metadata(key = nil) ⇒ Object
Returns a Hash cointaining all Metadata.
-
#to_html ⇒ Object
Return string containing HTML generated from MultiMarkdown text.
-
#to_latex ⇒ Object
Return string containing latex generated from MultiMarkdown text.
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:
-
‘:smart` - Enable SmartyPants processing.
-
‘:notes` - Enable footnotes.
-
‘:filter_styles` - Do not output `<style>` tags included in the source text.
-
‘:filter_html` - Do not output raw HTML included in the source text.
-
‘:process_html` - Process MultiMarkdown code inside HTML tags.
-
‘:compatibility` - Process MultiMarkdown code in Markdown compatibility mode (disables all other extensions)
-
‘:fold_lines` - RedCloth compatible line folding (not used).
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/multi_markdown.rb', line 52 def initialize(text, *extensions) @text = text @smart = true @notes = true @filter_styles = false @filter_html = false @process_html = false @compatibility = false extensions.each { |e| send("#{e}=", true) } if @compatibility @smart = false @notes = false @process_html = false end end |
Instance Attribute Details
#compatibility ⇒ Object
Markdown compatibility mode
32 33 34 |
# File 'lib/multi_markdown.rb', line 32 def compatibility @compatibility end |
#filter_html ⇒ Object
Do not output any raw HTML included in the source text.
26 27 28 |
# File 'lib/multi_markdown.rb', line 26 def filter_html @filter_html end |
#filter_styles ⇒ Object
Do not output ‘<style>` tags included in the source text.
23 24 25 |
# File 'lib/multi_markdown.rb', line 23 def filter_styles @filter_styles end |
#fold_lines ⇒ Object
Included for compatibility with RedCloth’s interface.
35 36 37 |
# File 'lib/multi_markdown.rb', line 35 def fold_lines @fold_lines end |
#notes ⇒ Object
Set ‘true` to have footnotes processed.
20 21 22 |
# File 'lib/multi_markdown.rb', line 20 def notes @notes end |
#process_html ⇒ Object
Process MultiMarkdown inside of raw HTML
29 30 31 |
# File 'lib/multi_markdown.rb', line 29 def process_html @process_html end |
#smart ⇒ Object
Set ‘true` to have smarty-like quote translation performed.
17 18 19 |
# File 'lib/multi_markdown.rb', line 17 def smart @smart end |
Instance Method Details
#extract_metadata_keys ⇒ Object
Return Array of metadata keys
47 48 49 50 51 52 53 |
# File 'ext/multi_markdown.c', line 47 static VALUE (VALUE self) { char * = (get_text(self), get_exts(self)); VALUE str = rb_str_new2(); 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
55 56 57 58 59 60 61 62 63 64 |
# File 'ext/multi_markdown.c', line 55
static VALUE rb_multimarkdown_extract_metadata_value(VALUE self, VALUE key) {
Check_Type(key, T_STRING);
char *pkey = StringValuePtr(key);
char *metadata = extract_metadata_value(get_text(self), get_exts(self), pkey);
VALUE result = rb_str_new2(metadata);
free(metadata);
return result;
}
|
#metadata(key = nil) ⇒ Object
Returns a Hash cointaining all Metadata
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/multi_markdown.rb', line 73 def (key = nil) if @cached_metadata.nil? @cached_metadata = {} .each do |k| @cached_metadata[k.downcase] = (k) end end if key @cached_metadata[key.to_s.downcase] else @cached_metadata.dup end end |
#to_html ⇒ Object
Return string containing HTML generated from MultiMarkdown text
31 32 33 34 35 36 37 |
# File 'ext/multi_markdown.c', line 31 static VALUE rb_multimarkdown_to_html(VALUE self) { char *html = markdown_to_string(get_text(self), get_exts(self), HTML_FORMAT); VALUE result = rb_str_new2(html); free(html); return result; } |
#to_latex ⇒ Object
Return string containing latex generated from MultiMarkdown text
39 40 41 42 43 44 45 |
# File 'ext/multi_markdown.c', line 39 static VALUE rb_multimarkdown_to_latex(VALUE self) { char *latex = markdown_to_string(get_text(self), get_exts(self), LATEX_FORMAT); VALUE result = rb_str_new2(latex); free(latex); return result; } |