multimarkdown 4.5.0.r1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +75 -0
- data/MultiMarkdown-4/GLibFacade.c +294 -0
- data/MultiMarkdown-4/GLibFacade.h +95 -0
- data/MultiMarkdown-4/beamer.c +179 -0
- data/MultiMarkdown-4/beamer.h +11 -0
- data/MultiMarkdown-4/critic.c +111 -0
- data/MultiMarkdown-4/critic.h +15 -0
- data/MultiMarkdown-4/glib.h +11 -0
- data/MultiMarkdown-4/html.c +1060 -0
- data/MultiMarkdown-4/html.h +14 -0
- data/MultiMarkdown-4/latex.c +1137 -0
- data/MultiMarkdown-4/latex.h +16 -0
- data/MultiMarkdown-4/libMultiMarkdown.h +156 -0
- data/MultiMarkdown-4/lyx.c +2163 -0
- data/MultiMarkdown-4/lyx.h +36 -0
- data/MultiMarkdown-4/lyxbeamer.c +267 -0
- data/MultiMarkdown-4/lyxbeamer.h +11 -0
- data/MultiMarkdown-4/memoir.c +79 -0
- data/MultiMarkdown-4/memoir.h +10 -0
- data/MultiMarkdown-4/multimarkdown.c +483 -0
- data/MultiMarkdown-4/odf.c +1201 -0
- data/MultiMarkdown-4/odf.h +18 -0
- data/MultiMarkdown-4/opml.c +188 -0
- data/MultiMarkdown-4/opml.h +15 -0
- data/MultiMarkdown-4/parse_utilities.c +752 -0
- data/MultiMarkdown-4/parser.c +15582 -0
- data/MultiMarkdown-4/parser.h +186 -0
- data/MultiMarkdown-4/rng.c +117 -0
- data/MultiMarkdown-4/rtf.c +648 -0
- data/MultiMarkdown-4/rtf.h +17 -0
- data/MultiMarkdown-4/strtok.c +56 -0
- data/MultiMarkdown-4/strtok.h +9 -0
- data/MultiMarkdown-4/text.c +53 -0
- data/MultiMarkdown-4/text.h +11 -0
- data/MultiMarkdown-4/transclude.c +213 -0
- data/MultiMarkdown-4/transclude.h +26 -0
- data/MultiMarkdown-4/writer.c +576 -0
- data/MultiMarkdown-4/writer.h +34 -0
- data/README.md +70 -0
- data/Rakefile +85 -0
- data/bin/ruby_multi_markdown +128 -0
- data/ext/extconf.h +3 -0
- data/ext/extconf.rb +17 -0
- data/ext/multi_markdown.c +100 -0
- data/lib/multi_markdown.bundle +0 -0
- data/lib/multi_markdown.rb +88 -0
- data/lib/multi_markdown/version.rb +6 -0
- data/lib/multimarkdown.rb +1 -0
- data/multi_markdown.gemspec +37 -0
- data/test/multi_markdown_test.rb +64 -0
- metadata +119 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
#include "parser.h"
|
2
|
+
|
3
|
+
#include "text.h"
|
4
|
+
#include "html.h"
|
5
|
+
#include "latex.h"
|
6
|
+
#include "memoir.h"
|
7
|
+
#include "beamer.h"
|
8
|
+
#include "lyx.h"
|
9
|
+
#include "lyxbeamer.h"
|
10
|
+
#include "opml.h"
|
11
|
+
#include "odf.h"
|
12
|
+
#include "rtf.h"
|
13
|
+
#include "critic.h"
|
14
|
+
|
15
|
+
char * export_node_tree(node *list, int format, unsigned long extensions);
|
16
|
+
|
17
|
+
void extract_references(node *list, scratch_pad *scratch);
|
18
|
+
link_data * extract_link_data(char *label, scratch_pad *scratch);
|
19
|
+
|
20
|
+
void pad(GString *out, int num, scratch_pad *scratch);
|
21
|
+
|
22
|
+
int note_number_for_label(char *text, scratch_pad *scratch);
|
23
|
+
int note_number_for_node(node *ref, scratch_pad *scratch);
|
24
|
+
node * node_matching_label(char *label, node *n);
|
25
|
+
int count_node_from_end(node *n);
|
26
|
+
int cite_count_node_from_end(node *n);
|
27
|
+
node * node_for_count(node *n, int count);
|
28
|
+
void move_note_to_used(node *list, scratch_pad *scratch);
|
29
|
+
void use_inline_footnote(node *ref, scratch_pad *scratch);
|
30
|
+
node * node_for_attribute(char *querystring, node *list);
|
31
|
+
|
32
|
+
char * dimension_for_attribute(char *querystring, node *list);
|
33
|
+
|
34
|
+
link_data * load_link_data(node *n, scratch_pad *scratch);
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
Ruby MultiMarkdown 4
|
2
|
+
====================
|
3
|
+
|
4
|
+
[](https://travis-ci.org/tillsc/multi_markdown)
|
5
|
+
|
6
|
+
An extension library around
|
7
|
+
[Fletcher Penney's MultiMarkdown](http://github.com/fletcher/MultiMarkdown-4/)
|
8
|
+
library in C. It is based upon the ruby
|
9
|
+
[rpeg-markdown](https://github.com/rtomayko/rpeg-markdown/) and
|
10
|
+
[rpeg-multimarkdown](https://github.com/djungelvral/rpeg-multimarkdown) libraries by
|
11
|
+
[Ryan Tomayko](https://github.com/rtomayko) and [Oliver "djungelvral"](https://github.com/djungelvral).
|
12
|
+
|
13
|
+
Synopsis
|
14
|
+
--------
|
15
|
+
|
16
|
+
>> require 'multimarkdown'
|
17
|
+
|
18
|
+
>> MultiMarkdown.new('Hello, world.').to_html
|
19
|
+
#=> "<p>Hello, world.</p>"
|
20
|
+
|
21
|
+
>> MultiMarkdown.new('_Hello World!_', :smart, :filter_html).to_html
|
22
|
+
#=> "<p><em>Hello World!</em></p>"
|
23
|
+
|
24
|
+
>> MultiMarkdown.new('_Hello World!_').to_latex
|
25
|
+
#=> "\emph{Hello World!}"
|
26
|
+
|
27
|
+
>> doc = MultiMarkdown.new("Title: Some document \n\nSome text in the document")
|
28
|
+
|
29
|
+
>> doc.metadata
|
30
|
+
#=> {"title" => "Some document"}
|
31
|
+
|
32
|
+
>> doc.metadata("Title")
|
33
|
+
#=> "Some document"
|
34
|
+
|
35
|
+
See [MultiMarkdown documentation](http://fletcher.github.io/MultiMarkdown-4/)
|
36
|
+
and `MultiMarkdown`'s [RDoc](http://rubydoc.info/gems/multimarkdown) for further Details.
|
37
|
+
|
38
|
+
Installation / Hacking
|
39
|
+
----------------------
|
40
|
+
|
41
|
+
This library requires a recent version of glib2. All modern GNU userland
|
42
|
+
systems should be fine.
|
43
|
+
|
44
|
+
Install from [Rubygems](http://rubygems.org/gems/multimarkdown):
|
45
|
+
|
46
|
+
$ [sudo] gem install multimarkdown
|
47
|
+
|
48
|
+
Bundle via [Bundler](http://bundler.io):
|
49
|
+
|
50
|
+
gem 'multimarkdown'
|
51
|
+
|
52
|
+
Hacking:
|
53
|
+
|
54
|
+
$ git clone --recursive git://github.com/tillsc/multi_markdown.git
|
55
|
+
$ cd multi_markdown
|
56
|
+
$ bundle install
|
57
|
+
$ bundle exec rake test
|
58
|
+
|
59
|
+
Changes
|
60
|
+
-------
|
61
|
+
|
62
|
+
* [Version 4.5.0.r1](http://github.com/tillsc/multi_markdown/tree/v4.5.0.r1):
|
63
|
+
First Version based upon [rpeg-markdown](https://github.com/rtomayko/rpeg-markdown/)
|
64
|
+
and [rpeg-multimarkdown](https://github.com/djungelvral/rpeg-multimarkdown).
|
65
|
+
|
66
|
+
COPYING
|
67
|
+
-------
|
68
|
+
|
69
|
+
MultiMarkdown-4, multi_markdown are both licensed under the GPL and the MIT License.
|
70
|
+
See [LICENSE](LICENCSE) for more information.
|
data/Rakefile
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'rake/clean'
|
2
|
+
require 'rdoc/task'
|
3
|
+
require 'bundler'
|
4
|
+
|
5
|
+
Bundler::GemHelper.install_tasks
|
6
|
+
|
7
|
+
task :default => :test
|
8
|
+
|
9
|
+
# ***** Build
|
10
|
+
|
11
|
+
DLEXT = RbConfig::CONFIG['DLEXT']
|
12
|
+
|
13
|
+
# For Mac OS X -- prevents prevent additional ._* files being added to tarball
|
14
|
+
ENV['COPYFILE_DISABLE'] = 'true'
|
15
|
+
|
16
|
+
namespace "MultiMarkdown-4" do
|
17
|
+
|
18
|
+
desc "Initialize the submodule"
|
19
|
+
task "init" => "generate_parser"
|
20
|
+
|
21
|
+
desc "Generate needed parser files"
|
22
|
+
task "generate_parser" do
|
23
|
+
chdir('MultiMarkdown-4') do
|
24
|
+
sh 'make parser.c'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
file 'ext/Makefile' => ["MultiMarkdown-4:init"] + FileList['ext/{extconf.rb,*.c,*.h,*.rb}', 'MultiMarkdown-4/*.{c,h}'] do
|
32
|
+
chdir('ext') do
|
33
|
+
ruby 'extconf.rb'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
CLEAN.include 'ext/Makefile'
|
37
|
+
|
38
|
+
file "ext/multi_markdown.#{DLEXT}" => FileList['ext/Makefile', 'ext/*.{c,h,rb}', 'MultiMarkdown-4/*.{c,h}'] do |f|
|
39
|
+
chdir('ext') do
|
40
|
+
sh 'make'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
CLEAN.include 'ext/*.{o,bundle,so}'
|
44
|
+
CLEAN.include 'MultiMarkdown-4/*.o'
|
45
|
+
|
46
|
+
file "lib/multi_markdown.#{DLEXT}" => "ext/multi_markdown.#{DLEXT}" do |f|
|
47
|
+
cp f.prerequisites, "lib/", :preserve => true
|
48
|
+
end
|
49
|
+
CLEAN.include "lib/*.{so,bundle}"
|
50
|
+
|
51
|
+
desc 'Build the multi_markdown extension'
|
52
|
+
task :build => "lib/multi_markdown.#{DLEXT}"
|
53
|
+
|
54
|
+
# ***** Test
|
55
|
+
|
56
|
+
desc 'Run unit and conformance tests'
|
57
|
+
task :test => [ 'test:unit', 'test:conformance' ]
|
58
|
+
|
59
|
+
namespace :test do
|
60
|
+
|
61
|
+
desc 'Run unit tests'
|
62
|
+
task :unit => :build do |t|
|
63
|
+
ruby 'test/multi_markdown_test.rb'
|
64
|
+
end
|
65
|
+
|
66
|
+
desc "Run conformance tests"
|
67
|
+
task :conformance => :build do |t|
|
68
|
+
script = "#{pwd}/bin/ruby_multi_markdown"
|
69
|
+
chdir("MultiMarkdown-4/MarkdownTest") do
|
70
|
+
sh "./MarkdownTest.pl --script='#{script}' --flags='-c' --tidy"
|
71
|
+
sh "./MarkdownTest.pl --script='#{script}' --testdir='MultiMarkdownTests'"
|
72
|
+
sh "./MarkdownTest.pl --script='#{script}' --testdir='MultiMarkdownTests' --flags='-t latex' --ext='.tex'"
|
73
|
+
sh "./MarkdownTest.pl --script='#{script}' --testdir='BeamerTests' --flags='-t latex' --ext='.tex'"
|
74
|
+
sh "./MarkdownTest.pl --script='#{script}' --testdir='MemoirTests' --flags='-t latex' --ext='.tex'"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
# ***** RDoc
|
81
|
+
|
82
|
+
Rake::RDocTask.new do |rd|
|
83
|
+
rd.main = "README.md"
|
84
|
+
rd.rdoc_files.include("README.md", "ext/**/*.c", "lib/**/*.rb")
|
85
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'multi_markdown'
|
5
|
+
rescue LoadError => boom
|
6
|
+
local_path = File.expand_path(File.dirname(__FILE__))
|
7
|
+
$: << "#{local_path}/../lib"
|
8
|
+
require 'multi_markdown'
|
9
|
+
end
|
10
|
+
|
11
|
+
# Option parser -- http://florianpilz.github.com/micro-optparse/
|
12
|
+
|
13
|
+
require 'ostruct'
|
14
|
+
require 'optparse'
|
15
|
+
|
16
|
+
class Parser
|
17
|
+
attr_accessor :banner, :version
|
18
|
+
def initialize
|
19
|
+
@options = []
|
20
|
+
@used_short = []
|
21
|
+
yield self if block_given?
|
22
|
+
end
|
23
|
+
|
24
|
+
def option(name, desc, settings = {})
|
25
|
+
@options << [name, desc, settings]
|
26
|
+
end
|
27
|
+
|
28
|
+
def short_from(name)
|
29
|
+
name.to_s.chars.each do |c|
|
30
|
+
next if @used_short.include?(c) || c == "_"
|
31
|
+
return c # returns from short_from method
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def validate(options) # remove this method if you want fewer lines of code and don't need validations
|
36
|
+
options.each_pair do |key, value|
|
37
|
+
opt = @options.find_all{ |o| o[0] == key }.first
|
38
|
+
key = "--" << key.to_s.gsub("_", "-")
|
39
|
+
unless opt[2][:value_in_set].nil? || opt[2][:value_in_set].include?(value)
|
40
|
+
puts "Parameter for #{key} must be in [" << opt[2][:value_in_set].join(", ") << "]" ; exit(1)
|
41
|
+
end
|
42
|
+
unless opt[2][:value_matches].nil? || opt[2][:value_matches] =~ value
|
43
|
+
puts "Parameter for #{key} must match /" << opt[2][:value_matches].source << "/" ; exit(1)
|
44
|
+
end
|
45
|
+
unless opt[2][:value_satisfies].nil? || opt[2][:value_satisfies].call(value)
|
46
|
+
puts "Parameter for #{key} must satisfy given conditions (see description)" ; exit(1)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def process!(arguments = ARGV)
|
52
|
+
@result = (@default_values || {}).clone # reset or new
|
53
|
+
@optionparser ||= OptionParser.new do |p| # prepare only once
|
54
|
+
@options.each do |o|
|
55
|
+
@used_short << short = o[2][:short] || short_from(o[0])
|
56
|
+
@result[o[0]] = o[2][:default] || false # set default
|
57
|
+
klass = o[2][:default].class == Fixnum ? Integer : o[2][:default].class
|
58
|
+
desk = o[1] + (o[2][:nodefault] ? "" : " (default is #{@result[o[0]]})")
|
59
|
+
if [TrueClass, FalseClass, NilClass].include?(klass) # boolean switch
|
60
|
+
p.on("-" << short, "--[no-]" << o[0].to_s.gsub("_", "-"), desk) {|x| @result[o[0]] = x}
|
61
|
+
else # argument with parameter
|
62
|
+
p.on("-" << short, "--" << o[0].to_s.gsub("_", "-") << " " << (o[2][:name] ? "[#{o[2][:name].to_s}]" : ""), klass, desk) {|x| @result[o[0]] = x}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
p.banner = @banner unless @banner.nil?
|
67
|
+
p.on_tail("-h", "--help", "Show this message") {puts p ; exit}
|
68
|
+
short = @used_short.include?("v") ? "-V" : "-v"
|
69
|
+
p.on_tail(short, "--version", "Print version") {puts @version ; exit} unless @version.nil?
|
70
|
+
@default_values = @result.clone # save default values to reset @result in subsequent calls
|
71
|
+
end
|
72
|
+
|
73
|
+
begin
|
74
|
+
@optionparser.parse!(arguments)
|
75
|
+
rescue OptionParser::ParseError => e
|
76
|
+
puts e.message ; exit(1)
|
77
|
+
end
|
78
|
+
|
79
|
+
validate(@result) if self.respond_to?("validate")
|
80
|
+
@result
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Parse options
|
85
|
+
options = Parser.new do |p|
|
86
|
+
p.banner = "Ruby interface to MultiMarkdown"
|
87
|
+
p.version = "ruby_multi_markdown #{MultiMarkdown::VERSION}"
|
88
|
+
p.option :compatibility, "markdown compatibility mode", :default => false
|
89
|
+
p.option :filter_html, "filter out raw HTML except styles", :default => false
|
90
|
+
p.option :process_html, "process MultiMarkdown inside of raw HTML", :default => false
|
91
|
+
p.option :filter_styles, "filter out HTML styles", :default => false
|
92
|
+
p.option :smart, "use smart typography extension", :default => true
|
93
|
+
p.option :notes, "use notes extension", :default => true
|
94
|
+
p.option :output, "send output to FILE (default is stdout)", :name => "FILE", :default => "", :nodefault => true
|
95
|
+
p.option :to, "convert to FORMAT", :name => "FORMAT", :default => "html", :value_in_set => ["html","latex","memoir","beamer","odf","opml"]
|
96
|
+
p.option :extract, "extract and display metadata specified by KEY", :name => "KEY", :default => "", :nodefault => true
|
97
|
+
end.process!
|
98
|
+
|
99
|
+
# Convert options to MultiMarkdown module's options
|
100
|
+
mmopts = []
|
101
|
+
mmopts << :filter_html if options[:filter_html]
|
102
|
+
mmopts << :filter_styles if options[:filter_styles]
|
103
|
+
mmopts << :process_html if options[:process_html]
|
104
|
+
mmopts << :smart if options[:smart]
|
105
|
+
mmopts << :notes if options[:notes]
|
106
|
+
mmopts << :compatibility if options[:compatibility]
|
107
|
+
|
108
|
+
# ARGV will now only contain input filename, if it contains anything
|
109
|
+
STDIN.reopen(ARGV[0], 'rb') if ARGV.any?
|
110
|
+
multimarkdown = MultiMarkdown.new(STDIN.read,*mmopts)
|
111
|
+
STDOUT.reopen(options[:output], 'w') if options[:output]!=""
|
112
|
+
|
113
|
+
# Print specified metadata if requested
|
114
|
+
if options[:extract]!=""
|
115
|
+
puts multimarkdown.extract_metadata(options[:extract])
|
116
|
+
exit(0)
|
117
|
+
end
|
118
|
+
|
119
|
+
# Do processing
|
120
|
+
case options[:to]
|
121
|
+
when "html"
|
122
|
+
STDOUT.write(multimarkdown.to_html)
|
123
|
+
when "latex"
|
124
|
+
STDOUT.write(multimarkdown.to_latex)
|
125
|
+
else
|
126
|
+
puts "Output other than html & latex not currently supported"
|
127
|
+
exit(1)
|
128
|
+
end
|
data/ext/extconf.h
ADDED
data/ext/extconf.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
dir_config('multi_markdown')
|
4
|
+
|
5
|
+
mmd_objs = %w[parse_utilities.o parser.o GLibFacade.o writer.o text.o html.o latex.o memoir.o beamer.o lyx.o lyxbeamer.o opml.o odf.o critic.o rng.o rtf.o transclude.o]
|
6
|
+
|
7
|
+
$objs = mmd_objs.map { |s| "../MultiMarkdown-4/#{s}" } + ["multi_markdown.o"]
|
8
|
+
|
9
|
+
if pkg_config = find_executable('pkg-config')
|
10
|
+
$CFLAGS = "-fcommon "+`#{pkg_config} --cflags glib-2.0`
|
11
|
+
$LDFLAGS = `#{pkg_config} --libs glib-2.0`
|
12
|
+
else
|
13
|
+
fail "glib2 not found"
|
14
|
+
end
|
15
|
+
|
16
|
+
create_header
|
17
|
+
create_makefile('multi_markdown')
|
@@ -0,0 +1,100 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
#include "../MultiMarkdown-4/parser.h"
|
3
|
+
|
4
|
+
static VALUE rb_cMultiMarkdown;
|
5
|
+
|
6
|
+
int get_exts(VALUE self) {
|
7
|
+
int extensions = 0;
|
8
|
+
if (rb_funcall(self, rb_intern("smart"), 0) == Qtrue)
|
9
|
+
extensions = extensions | EXT_SMART;
|
10
|
+
if (rb_funcall(self, rb_intern("notes"), 0) == Qtrue)
|
11
|
+
extensions = extensions | EXT_NOTES;
|
12
|
+
if (rb_funcall(self, rb_intern("filter_html"), 0) == Qtrue)
|
13
|
+
extensions = extensions | EXT_FILTER_HTML;
|
14
|
+
if (rb_funcall(self, rb_intern("filter_styles"), 0) == Qtrue)
|
15
|
+
extensions = extensions | EXT_FILTER_STYLES;
|
16
|
+
if (rb_funcall(self, rb_intern("process_html"), 0) == Qtrue)
|
17
|
+
extensions = extensions | EXT_PROCESS_HTML;
|
18
|
+
/* Compatibility overwrites all other extensions */
|
19
|
+
if (rb_funcall(self, rb_intern("compatibility"), 0) == Qtrue)
|
20
|
+
extensions = EXT_COMPATIBILITY;
|
21
|
+
return extensions;
|
22
|
+
}
|
23
|
+
|
24
|
+
char *get_text(VALUE self) {
|
25
|
+
/* grab char pointer to multimarkdown input text */
|
26
|
+
VALUE text = rb_iv_get(self, "@text");
|
27
|
+
Check_Type(text, T_STRING);
|
28
|
+
return StringValuePtr(text);
|
29
|
+
}
|
30
|
+
|
31
|
+
static VALUE rb_multimarkdown_to_html(VALUE self) {
|
32
|
+
char *html = markdown_to_string(get_text(self), get_exts(self), HTML_FORMAT);
|
33
|
+
VALUE result = rb_str_new2(html);
|
34
|
+
free(html);
|
35
|
+
|
36
|
+
return result;
|
37
|
+
}
|
38
|
+
|
39
|
+
static VALUE rb_multimarkdown_to_latex(VALUE self) {
|
40
|
+
char *latex = markdown_to_string(get_text(self), get_exts(self), LATEX_FORMAT);
|
41
|
+
VALUE result = rb_str_new2(latex);
|
42
|
+
free(latex);
|
43
|
+
|
44
|
+
return result;
|
45
|
+
}
|
46
|
+
|
47
|
+
static VALUE rb_multimarkdown_extract_metadata_keys(VALUE self) {
|
48
|
+
char *metadata_keys = extract_metadata_keys(get_text(self), get_exts(self));
|
49
|
+
VALUE str = rb_str_new2(metadata_keys);
|
50
|
+
free(metadata_keys);
|
51
|
+
|
52
|
+
return rb_funcall(str, rb_intern("split"), 1, rb_str_new2("\n"));
|
53
|
+
}
|
54
|
+
|
55
|
+
static VALUE rb_multimarkdown_extract_metadata_value(VALUE self, VALUE key) {
|
56
|
+
Check_Type(key, T_STRING);
|
57
|
+
char *pkey = StringValuePtr(key);
|
58
|
+
|
59
|
+
char *metadata = extract_metadata_value(get_text(self), get_exts(self), pkey);
|
60
|
+
VALUE result = rb_str_new2(metadata);
|
61
|
+
free(metadata);
|
62
|
+
|
63
|
+
return result;
|
64
|
+
}
|
65
|
+
|
66
|
+
void Init_multi_markdown() {
|
67
|
+
|
68
|
+
rb_cMultiMarkdown = rb_define_class("MultiMarkdown", rb_cObject);
|
69
|
+
|
70
|
+
/* Document-method: MultiMarkdown#to_html
|
71
|
+
*
|
72
|
+
* Return string containing HTML generated from MultiMarkdown text
|
73
|
+
*/
|
74
|
+
rb_define_method(rb_cMultiMarkdown, "to_html", rb_multimarkdown_to_html, 0);
|
75
|
+
|
76
|
+
/* Document-method: MultiMarkdown#to_latex
|
77
|
+
*
|
78
|
+
* Return string containing latex generated from MultiMarkdown text
|
79
|
+
*/
|
80
|
+
rb_define_method(rb_cMultiMarkdown, "to_latex", rb_multimarkdown_to_latex, 0);
|
81
|
+
|
82
|
+
/* Document-method: MultiMarkdown#extract_metadata_keys
|
83
|
+
*
|
84
|
+
* Return Array of metadata keys
|
85
|
+
*/
|
86
|
+
rb_define_method(rb_cMultiMarkdown, "extract_metadata_keys", rb_multimarkdown_extract_metadata_keys, 0);
|
87
|
+
|
88
|
+
/* Document-method: MultiMarkdown#extract_metadata_value
|
89
|
+
* :call-seq: extract_metadata_value(key)
|
90
|
+
*
|
91
|
+
* Fetches metadata specified by +key+ from MultiMarkdown text
|
92
|
+
*/
|
93
|
+
rb_define_method(rb_cMultiMarkdown, "extract_metadata_value", rb_multimarkdown_extract_metadata_value, 1);
|
94
|
+
|
95
|
+
rb_define_const(rb_cMultiMarkdown, "MMD_VERSION", rb_str_new2(MMD_VERSION));
|
96
|
+
/* Document-const: MultiMarkdown::MMD_VERSION
|
97
|
+
*
|
98
|
+
* The version of the MultiMarkdown-4 library
|
99
|
+
*/
|
100
|
+
}
|
Binary file
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'multi_markdown.so'
|
2
|
+
require 'multi_markdown/version'
|
3
|
+
|
4
|
+
# Front-end to fletcher penney's implementation of MultiMarkdown
|
5
|
+
#
|
6
|
+
# A simple processor:
|
7
|
+
# >> puts MultiMarkdown.new("Hello, World.").to_html
|
8
|
+
# <p>Hello, World.</p>
|
9
|
+
#
|
10
|
+
# With other stuff:
|
11
|
+
# >> puts MultiMarkdown.new("_Hello World!_", :smart, :filter_html).to_html
|
12
|
+
# <p><em>Hello World!</em></p>
|
13
|
+
#
|
14
|
+
class MultiMarkdown
|
15
|
+
|
16
|
+
# Set `true` to have smarty-like quote translation performed.
|
17
|
+
attr_accessor :smart
|
18
|
+
|
19
|
+
# Set `true` to have footnotes processed.
|
20
|
+
attr_accessor :notes
|
21
|
+
|
22
|
+
# Do not output `<style>` tags included in the source text.
|
23
|
+
attr_accessor :filter_styles
|
24
|
+
|
25
|
+
# Do not output any raw HTML included in the source text.
|
26
|
+
attr_accessor :filter_html
|
27
|
+
|
28
|
+
# Process MultiMarkdown inside of raw HTML
|
29
|
+
attr_accessor :process_html
|
30
|
+
|
31
|
+
# Markdown compatibility mode
|
32
|
+
attr_accessor :compatibility
|
33
|
+
|
34
|
+
# Included for compatibility with RedCloth's interface.
|
35
|
+
attr_accessor :fold_lines
|
36
|
+
|
37
|
+
# Create a new MultiMarkdown processor. The `text` argument is a string
|
38
|
+
# containing MultiMarkdown text. Variable other arguments may be supplied to
|
39
|
+
# set various processing options:
|
40
|
+
#
|
41
|
+
# * `:smart` - Enable SmartyPants processing.
|
42
|
+
# * `:notes` - Enable footnotes.
|
43
|
+
# * `:filter_styles` - Do not output `<style>` tags included in the
|
44
|
+
# source text.
|
45
|
+
# * `:filter_html` - Do not output raw HTML included in the
|
46
|
+
# source text.
|
47
|
+
# * `:process_html` - Process MultiMarkdown code inside HTML tags.
|
48
|
+
# * `:compatibility` - Process MultiMarkdown code in Markdown
|
49
|
+
# compatibility mode (disables all other extensions)
|
50
|
+
# * `:fold_lines` - RedCloth compatible line folding (not used).
|
51
|
+
#
|
52
|
+
def initialize(text, *extensions)
|
53
|
+
@text = text
|
54
|
+
@smart = true
|
55
|
+
@notes = true
|
56
|
+
@filter_styles = false
|
57
|
+
@filter_html = false
|
58
|
+
@process_html = false
|
59
|
+
@compatibility = false
|
60
|
+
extensions.each { |e| send("#{e}=", true) }
|
61
|
+
if @compatibility
|
62
|
+
@smart = false
|
63
|
+
@notes = false
|
64
|
+
@process_html = false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
alias extract_metadata extract_metadata_value
|
69
|
+
|
70
|
+
# Returns a Hash cointaining all Metadata
|
71
|
+
#
|
72
|
+
#
|
73
|
+
def metadata(key = nil)
|
74
|
+
if @cached_metadata.nil?
|
75
|
+
@cached_metadata = {}
|
76
|
+
extract_metadata_keys.each do |k|
|
77
|
+
@cached_metadata[k.downcase] = extract_metadata_value(k)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
if key
|
82
|
+
@cached_metadata[key.to_s.downcase]
|
83
|
+
else
|
84
|
+
@cached_metadata.dup
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|