rmultimarkdown 4.6.0.1 → 4.6.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d09abf7122bde215cae33570b460aa1d63874cfc
4
- data.tar.gz: a9cf6ae5f6f8738f471266cd9594285dc32c32a8
3
+ metadata.gz: 167af5d3d0863a48d28427711ecbc8bcd42fe9cd
4
+ data.tar.gz: 83c2e5097b502293ae34ce4ba5ad293f4acf6af6
5
5
  SHA512:
6
- metadata.gz: feba15b48f3fe5ba7340d3c2037b48ebb44d8f1ba82a125216018e646081cf4ce5dd2d67c23c2acc00d8bf3f4854cb2335ea9f885f63d4368221aa9f550dd192
7
- data.tar.gz: 0f47cae9ff4087bd5ca8c1780a8aafcdc0b378e71387e580fa892708633f743cc571c66bea40444a447af172604e1495c6b632791a6c4cb9aa7b657dcbaabf1c
6
+ metadata.gz: 7ea5083a0b5d47cc067f35db9152ce9245e1991eb525be81cef504f883a593122dd0c7b2f98341b634ce01e3a1e47aae7f089347b553774e0844efd77da7419e
7
+ data.tar.gz: 7cd100553e21772c28fedb0a56ede9f8b87790f3bc0a8c58ed7dde10dc1b65c578b30cd8370ebf35480ba7c4eba83e746607fd6a63a2282a7efc31ea934b9dc3
data/Rakefile CHANGED
@@ -60,7 +60,9 @@ namespace :test do
60
60
 
61
61
  desc 'Run unit tests'
62
62
  task :unit => :build do |t|
63
- ruby 'test/multi_markdown_test.rb'
63
+ FileList['test/*.rb'].each do |f|
64
+ ruby f
65
+ end
64
66
  end
65
67
 
66
68
  desc "Run conformance tests"
@@ -30,6 +30,7 @@ class Parser
30
30
  next if @used_short.include?(c) || c == "_"
31
31
  return c # returns from short_from method
32
32
  end
33
+ nil
33
34
  end
34
35
 
35
36
  def validate(options) # remove this method if you want fewer lines of code and don't need validations
@@ -52,14 +53,14 @@ class Parser
52
53
  @result = (@default_values || {}).clone # reset or new
53
54
  @optionparser ||= OptionParser.new do |p| # prepare only once
54
55
  @options.each do |o|
55
- @used_short << short = o[2][:short] || short_from(o[0])
56
+ @used_short << short = o[2][:short] == false ? nil : o[2][:short] || short_from(o[0])
56
57
  @result[o[0]] = o[2][:default] || false # set default
57
58
  klass = o[2][:default].class == Fixnum ? Integer : o[2][:default].class
58
59
  desk = o[1] + (o[2][:nodefault] ? "" : " (default is #{@result[o[0]]})")
59
60
  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
+ p.on(short && "-" << short, "--" << o[0].to_s.gsub("_", "-"), desk) {|x| @result[o[0]] = x}
61
62
  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
+ p.on(short && "-" << short, "--" << o[0].to_s.gsub("_", "-") << " " << (o[2][:name] ? "[#{o[2][:name].to_s}]" : ""), klass, desk) {|x| @result[o[0]] = x}
63
64
  end
64
65
  end
65
66
 
@@ -85,25 +86,19 @@ end
85
86
  options = Parser.new do |p|
86
87
  p.banner = "Ruby interface to MultiMarkdown"
87
88
  p.version = "rmultimarkdown #{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
89
+ p.option :output, "send output to FILE (default is stdout)", :name => "FILE", :default => "", :nodefault => true, :short => "o"
90
+ p.option :to, "convert to FORMAT", :name => "FORMAT", :default => "html", :value_in_set => ["html","latex"], :short => "t"
91
+ p.option :extract, "extract and display metadata specified by KEY", :name => "KEY", :default => "", :nodefault => true, :short => "e"
92
+ MultiMarkdown::EXTENSIONS.each do |ext, opts|
93
+ p.option ext.to_sym, opts[:desc], :default => false, :short => opts[:short] || false
94
+ end
97
95
  end.process!
98
96
 
99
97
  # Convert options to MultiMarkdown module's options
100
98
  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]
99
+ MultiMarkdown::EXTENSIONS.each do |ext, description|
100
+ mmopts << ext.to_sym if options[ext.to_sym]
101
+ end
107
102
 
108
103
  # ARGV will now only contain input filename, if it contains anything
109
104
  STDIN.reopen(ARGV[0], 'rb') if ARGV.any?
@@ -19,16 +19,35 @@ static VALUE rb_cMultiMarkdown;
19
19
 
20
20
  static int get_exts(VALUE self) {
21
21
  int extensions = 0;
22
- if (rb_funcall(self, rb_intern("smart"), 0) == Qtrue)
22
+ if (rb_funcall(self, rb_intern("complete"), 0) == Qtrue)
23
+ extensions = extensions | EXT_COMPLETE;
24
+ if (rb_funcall(self, rb_intern("snippet"), 0) == Qtrue)
25
+ extensions = extensions | EXT_SNIPPET;
26
+ if (rb_funcall(self, rb_intern("no_smart_quotes"), 0) != Qtrue)
23
27
  extensions = extensions | EXT_SMART;
24
- if (rb_funcall(self, rb_intern("notes"), 0) == Qtrue)
28
+ if (rb_funcall(self, rb_intern("no_footnotes"), 0) != Qtrue)
25
29
  extensions = extensions | EXT_NOTES;
26
- if (rb_funcall(self, rb_intern("filter_html"), 0) == Qtrue)
27
- extensions = extensions | EXT_FILTER_HTML;
30
+ if (rb_funcall(self, rb_intern("no_anchors"), 0) == Qtrue)
31
+ extensions = extensions | EXT_NO_LABELS;
28
32
  if (rb_funcall(self, rb_intern("filter_styles"), 0) == Qtrue)
29
33
  extensions = extensions | EXT_FILTER_STYLES;
34
+ if (rb_funcall(self, rb_intern("filter_html"), 0) == Qtrue)
35
+ extensions = extensions | EXT_FILTER_HTML;
30
36
  if (rb_funcall(self, rb_intern("process_html"), 0) == Qtrue)
31
37
  extensions = extensions | EXT_PROCESS_HTML;
38
+ if (rb_funcall(self, rb_intern("no_metadata"), 0) == Qtrue)
39
+ extensions = extensions | EXT_NO_METADATA;
40
+ if (rb_funcall(self, rb_intern("obfuscate_email_addresses"), 0) == Qtrue)
41
+ extensions = extensions | EXT_OBFUSCATE;
42
+ if (rb_funcall(self, rb_intern("critic_markup_accept_all"), 0) == Qtrue)
43
+ extensions = extensions | EXT_CRITIC | EXT_CRITIC_ACCEPT;
44
+ if (rb_funcall(self, rb_intern("critic_markup_reject_all"), 0) == Qtrue)
45
+ extensions = extensions | EXT_CRITIC | EXT_CRITIC_REJECT;
46
+ if (rb_funcall(self, rb_intern("random_footnote_anchor_numbers"), 0) == Qtrue)
47
+ extensions = extensions | EXT_RANDOM_FOOT;
48
+ if (rb_funcall(self, rb_intern("escaped_line_breaks"), 0) == Qtrue)
49
+ extensions = extensions | EXT_ESCAPED_LINE_BREAKS;
50
+
32
51
  /* Compatibility overwrites all other extensions */
33
52
  if (rb_funcall(self, rb_intern("compatibility"), 0) == Qtrue)
34
53
  extensions = EXT_COMPATIBILITY;
Binary file
@@ -13,55 +13,36 @@ require 'multi_markdown/version'
13
13
  #
14
14
  class MultiMarkdown
15
15
 
16
- # Set `true` to have smarty-like quote translation performed.
17
- attr_accessor :smart
16
+ EXTENSIONS = {
17
+ "compatibility" => {:desc => "Markdown compatibility mode (disables all other options)", :short => "c"},
18
+ "complete" => {:desc => "Force complete document", :short => "f"},
19
+ "snippet" => {:desc => "Force snippet only", :short => "s"},
20
+ "no_smart_quotes" => {:desc => "Disable Smart quotes", :short => false},
21
+ "no_footnotes" => {:desc => "Disable Footnotes", :short => false},
22
+ "no_anchors" => {:desc => "Don't add anchors to headers, etc.", :short => false},
23
+ "filter_styles" => {:desc => "Filter out style blocks", :short => false},
24
+ "filter_html" => {:desc => "Filter out raw HTML", :short => false},
25
+ "process_html" => {:desc => "Process Markdown inside HTML", :short => false},
26
+ "no_metadata" => {:desc => "Don't parse Metadata", :short => false},
27
+ "obfuscate_email_addresses" => {:desc => "Mask email addresses", :short => false},
28
+ "critic_markup_accept_all" => {:desc => "CriticMarkup: Accept all proposed changes", :short => "a"},
29
+ "critic_markup_reject_all" => {:desc => "CriticMarkup: Reject all proposed changes", :short => "r"},
30
+ "random_footnote_anchor_numbers" => {:desc => "Use random numbers for footnote link anchors", :short => false},
31
+ "escaped_line_breaks" => {:desc => "Escaped line break", :short => false}
32
+ }
18
33
 
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
34
+ EXTENSIONS.keys.each do |ext|
35
+ attr_accessor ext
36
+ end
36
37
 
37
38
  # Create a new MultiMarkdown processor. The `text` argument is a string
38
39
  # 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
- #
40
+ # set various processing options. See MultiMarkdown::EXTENSIONS for more.
52
41
  def initialize(text, *extensions)
53
42
  @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
43
+ extensions.each do |ext|
44
+ raise "Unknown extension: #{ext.inspect}" unless EXTENSIONS.keys.include?(ext.to_s)
45
+ send("#{ext}=", true)
65
46
  end
66
47
  end
67
48
 
@@ -1,6 +1,6 @@
1
1
  class MultiMarkdown
2
2
 
3
3
  # The ruby 'multimarkdown' gem version
4
- VERSION = "4.6.0.1"
4
+ VERSION = "4.6.0.2"
5
5
 
6
6
  end
@@ -0,0 +1,174 @@
1
+ # encoding: UTF-8
2
+
3
+ $: << File.join(File.dirname(__FILE__), "../lib")
4
+
5
+ require 'test/unit'
6
+ require 'multi_markdown'
7
+
8
+ class ExtensionsTest < Test::Unit::TestCase
9
+
10
+ def test_force_complete_document
11
+ mmd = 'Some very simple _Markdown_'
12
+
13
+ # Don't change anything (default)
14
+ multimarkdown = MultiMarkdown.new(mmd)
15
+ assert !multimarkdown.to_html.include?('<html>'), "Found '<html>' tag: '#{multimarkdown.to_html}'"
16
+
17
+ # Force complete document
18
+ multimarkdown = MultiMarkdown.new(mmd, :complete)
19
+ assert multimarkdown.to_html.include?('<html>'), "Didn't find '<html>' tag: '#{multimarkdown.to_html}'"
20
+ end
21
+
22
+ def test_force_snippet_mode
23
+ mmd = "Meta1: Value\nMeta2: Value2\n\nHello!"
24
+
25
+ # Don't change anything (default)
26
+ multimarkdown = MultiMarkdown.new(mmd)
27
+ assert multimarkdown.to_html.include?('<html>'), "Didn't find '<html>' tag: '#{multimarkdown.to_html}'"
28
+
29
+ # Force snippet
30
+ multimarkdown = MultiMarkdown.new(mmd, :snippet)
31
+ assert !multimarkdown.to_html.include?('<html>'), "Found '<html>' tag: '#{multimarkdown.to_html}'"
32
+ end
33
+
34
+ def test_smart_quotes
35
+ mmd = 'Quotes are "beautiful"'
36
+
37
+ # Don't change anything (default)
38
+ multimarkdown = MultiMarkdown.new(mmd)
39
+ assert multimarkdown.to_html.include?('&#8220;'), "Didn't find nice quote '&#8220;': '#{multimarkdown.to_html}'"
40
+ assert multimarkdown.to_html.include?('&#8221;'), "Didn't find nice quote '&#8221;': '#{multimarkdown.to_html}'"
41
+ assert !multimarkdown.to_html.include?('&quot;'), "Found quote '&quot;': '#{multimarkdown.to_html}'"
42
+
43
+ # Disble smart quotes
44
+ multimarkdown = MultiMarkdown.new(mmd, :no_smart_quotes)
45
+ assert_equal '<p>Quotes are &quot;beautiful&quot;</p>', multimarkdown.to_html.strip
46
+ end
47
+
48
+ def test_footnotes
49
+ mmd = <<eof
50
+ Here is some text containing a footnote.[^somesamplefootnote]
51
+
52
+ [^somesamplefootnote]: Here is the text of the footnote itself.
53
+ eof
54
+
55
+ # Don't change anything (default)
56
+ multimarkdown = MultiMarkdown.new(mmd)
57
+ assert multimarkdown.to_html.include?('class="footnotes"'), "Didn't find footnote container: '#{multimarkdown.to_html}'"
58
+ assert multimarkdown.to_html.include?('text of the footnote itself'), "Didn't find footnote text: '#{multimarkdown.to_html}'"
59
+ assert multimarkdown.to_html.include?('#fnref:1'), "Didn't find footnote anchor '#fnref:1': '#{multimarkdown.to_html}'"
60
+
61
+ multimarkdown = MultiMarkdown.new(mmd, :random_footnote_anchor_numbers)
62
+ assert !multimarkdown.to_html.include?('#fnref:1'), "Found footnote anchor '#fnref:1': '#{multimarkdown.to_html}'"
63
+
64
+ multimarkdown = MultiMarkdown.new(mmd, :no_footnotes)
65
+ assert !multimarkdown.to_html.include?('class="footnotes"'), "Found footnote container: '#{multimarkdown.to_html}'"
66
+ assert multimarkdown.to_html.include?('[^somesamplefootnote]'), "Didn't find footnote markdown text: '#{multimarkdown.to_html}'"
67
+
68
+ end
69
+
70
+ def test_anchors
71
+ mmd = '# A Heading'
72
+
73
+ # Don't change anything (default)
74
+ multimarkdown = MultiMarkdown.new(mmd)
75
+ assert multimarkdown.to_html.include?('id="aheading"'), "Didn't find a tag with 'id=\"aheading\"': '#{multimarkdown.to_html}'"
76
+
77
+ # Turn off auto anchors
78
+ multimarkdown = MultiMarkdown.new(mmd, :no_anchors)
79
+ assert !multimarkdown.to_html.include?('id="aheading"'), "Found a tag with 'id=\"aheading\"': '#{multimarkdown.to_html}'"
80
+ end
81
+
82
+ def test_filter_styles
83
+ mmd = '<style>p {color: red}</style> <span style="color: blue">It is blue!</span>'
84
+
85
+ # Don't change anything (default)
86
+ multimarkdown = MultiMarkdown.new(mmd)
87
+ assert multimarkdown.to_html.include?('<style>p {color: red}</style>'), "Didn't find '<style>' tag: '#{multimarkdown.to_html}'"
88
+ assert multimarkdown.to_html.include?('style="color: blue"'), "Didn't inline 'style': '#{multimarkdown.to_html}'"
89
+
90
+ # Disbale styles
91
+ multimarkdown = MultiMarkdown.new(mmd, :filter_styles)
92
+ assert !multimarkdown.to_html.include?('<style>p {color: red}</style>'), "Found '<style>' tag: '#{multimarkdown.to_html}'"
93
+ # Doesn't work: assert !multimarkdown.to_html.include?('style="color: blue"'), "Found inline 'style': '#{multimarkdown.to_html}'"
94
+ end
95
+
96
+ def test_filter_html
97
+ mmd = '<span>Hello from HTML</span>Pure Markdown'
98
+
99
+ # Don't change anything (default)
100
+ multimarkdown = MultiMarkdown.new(mmd)
101
+ assert multimarkdown.to_html.include?('<span>Hello from HTML</span>'), "Didn't find '<span>' tag: '#{multimarkdown.to_html}'"
102
+ assert multimarkdown.to_html.include?('Pure Markdown<'), "Didn't find Markdown: '#{multimarkdown.to_html}'"
103
+
104
+ # Disbale html
105
+ multimarkdown = MultiMarkdown.new(mmd, :filter_html)
106
+ assert_equal "<p>Hello from HTMLPure Markdown</p>", multimarkdown.to_html.strip
107
+ end
108
+
109
+ # TODO
110
+ # See https://github.com/fletcher/MultiMarkdown-4/issues/97
111
+ def disabled_test_markdown_in_html
112
+ mmd = 'Hello <span>[World](http://world.de)</span>!'
113
+
114
+ # No Markdown in html supported (default)
115
+ multimarkdown = MultiMarkdown.new(mmd)
116
+ assert_equal "<p>Hello <span>_World_</span>!</p>", multimarkdown.to_html.strip
117
+
118
+ # now with the extension turned on
119
+ multimarkdown = MultiMarkdown.new(mmd, :process_html)
120
+ assert_equal "<p>Hello <span><em>World</em></span>!</p>", multimarkdown.to_html.strip
121
+ end
122
+
123
+
124
+ def test_no_metadata
125
+ mmd = "A: B\n\nBlabla"
126
+
127
+ # Don't do anything (default)
128
+ multimarkdown = MultiMarkdown.new(mmd, :no_metadata)
129
+ assert multimarkdown.to_html.include?('A: B'), "Didn't find metadata style text: '#{multimarkdown.to_html}'"
130
+ end
131
+
132
+ def test_obfuscation
133
+ mmd = '[Contact me](mailto:mail@example.com)'
134
+
135
+ # Don't do anything (default)
136
+ multimarkdown = MultiMarkdown.new(mmd)
137
+ assert multimarkdown.to_html.include?('mail@example.com'), "Didn't find email address: '#{multimarkdown.to_html}'"
138
+
139
+ # Obfuscate
140
+ multimarkdown = MultiMarkdown.new(mmd, :obfuscate_email_addresses)
141
+ assert !multimarkdown.to_html.include?('mail@example.com'), "Found email address: '#{multimarkdown.to_html}'"
142
+ end
143
+
144
+ def test_critic_markup
145
+ mmd = 'This is a {++green ++} test.'
146
+
147
+ # Don't do anything (default)
148
+ multimarkdown = MultiMarkdown.new(mmd)
149
+ assert_equal "<p>This is a {++green ++} test.</p>", multimarkdown.to_html.strip
150
+
151
+ # Include changes
152
+ multimarkdown = MultiMarkdown.new(mmd, :critic_markup_accept_all)
153
+ assert_equal "<p>This is a green test.</p>", multimarkdown.to_html.strip
154
+
155
+ # Ignore changes
156
+ multimarkdown = MultiMarkdown.new(mmd, :critic_markup_reject_all)
157
+ assert_equal "<p>This is a test.</p>", multimarkdown.to_html.strip
158
+ end
159
+
160
+ def test_escaped_line_breaks
161
+ mmd = <<eof
162
+ This is a cool MultiMarkdown\\
163
+ Feature
164
+ eof
165
+
166
+ # Don't do anything (default)
167
+ multimarkdown = MultiMarkdown.new(mmd)
168
+ assert !multimarkdown.to_html.include?('<br/>'), "Found '<br/>' tag: '#{multimarkdown.to_html}'"
169
+
170
+ multimarkdown = MultiMarkdown.new(mmd, :escaped_line_breaks)
171
+ assert multimarkdown.to_html.include?('<br/>'), "Didn't find '<br/>' tag: '#{multimarkdown.to_html}'"
172
+ end
173
+
174
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmultimarkdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.6.0.1
4
+ version: 4.6.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Till Schulte-Coerne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-29 00:00:00.000000000 Z
11
+ date: 2014-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,6 +44,7 @@ files:
44
44
  - lib/multi_markdown.bundle
45
45
  - lib/multi_markdown.rb
46
46
  - lib/rmultimarkdown.rb
47
+ - test/extensions_test.rb.rb
47
48
  - test/multi_markdown_test.rb
48
49
  - ext/multi_markdown.c
49
50
  - ext/extconf.h
@@ -109,4 +110,5 @@ signing_key:
109
110
  specification_version: 4
110
111
  summary: A MultiMarkdown 4 binding for Ruby
111
112
  test_files:
113
+ - test/extensions_test.rb.rb
112
114
  - test/multi_markdown_test.rb