rpeg-multimarkdown 0.2.1 → 0.2.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 153a563efa3e2d15f47874308fb8ff2060752964
4
- data.tar.gz: 9459fdddb5815ca24026973817a7744b82da97a7
3
+ metadata.gz: 1a2db27270d9a4205d98c91760432207cf2cddcf
4
+ data.tar.gz: 8b3a88efb70610fb70c2db1bd173d7926b5c038f
5
5
  SHA512:
6
- metadata.gz: 375d6044a041d31de74bb7e166900f5f1df03a32bf75694544f0cf455c93475afc8b40d2165331658a8d2a60185116abb9f54f942510e98037062461c019f71c
7
- data.tar.gz: 667c389c1a25ee4abda0acc197bb86a93e6adc91a5505dd6e27a7a9714c0997b459f7929daa3bee6831b7dbc3213a9dc08a414f7d40f5d124bda125821bc2b99
6
+ metadata.gz: 9e5452b984d43c447b563973760b0879fc515257eca20c5f7310fc026bf93e0b46585b6e72ffd80a45104007e2455702be46520c775242f8b7ae5859637ca828
7
+ data.tar.gz: 9182a060242a16d96d62d61db84244c469676b3761c7807b6c49843f00854888cd51e6bdfe3baf0602ba8f192461e169f2e64f6030d2c2c27bdca7c377c5647e
@@ -50,10 +50,10 @@ Hacking:
50
50
  Changes
51
51
  -------
52
52
 
53
- * [Version 0.2.1](http://github.com/djungelvral/rpeg-multimarkdown/tree/v0.2.1)
54
- * Fixed ruby module tests, which weren't actually running
55
- * [Version 0.2](http://github.com/djungelvral/rpeg-multimarkdown/tree/v0.2)
53
+ * [Version 0.2.2](http://github.com/djungelvral/rpeg-multimarkdown/tree/v0.2.2)
56
54
  * Bringing everything up to date with the last version of peg-multimarkdown
55
+ * Fixed ruby module tests, which weren't actually running
56
+ * Preserve encoding, e.g. for UTF-8
57
57
  * [Version 0.1.1](http://github.com/djungelvral/rpeg-multimarkdown/tree/v0.1.1)
58
58
 
59
59
  COPYING
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ require 'rubygems/package_task'
8
8
  task :default => :test
9
9
 
10
10
  DLEXT = RbConfig::CONFIG['DLEXT']
11
- VERS = '0.2.1'
11
+ VERS = '0.2.2'
12
12
 
13
13
  spec = Gem::Specification.new do |s|
14
14
  s.name = "rpeg-multimarkdown"
@@ -35,7 +35,10 @@ rb_multimarkdown_to_html(int argc, VALUE *argv, VALUE self)
35
35
  char *html = markdown_to_string(ptext, extensions, HTML_FORMAT);
36
36
  VALUE result = rb_str_new2(html);
37
37
  free(html);
38
-
38
+
39
+ /* Take the encoding from the input, and apply to output */
40
+ rb_enc_copy(result, text);
41
+
39
42
  return result;
40
43
  }
41
44
 
@@ -53,6 +56,9 @@ rb_multimarkdown_to_latex(int argc, VALUE *argv, VALUE self)
53
56
  VALUE result = rb_str_new2(latex);
54
57
  free(latex);
55
58
 
59
+ /* Take the encoding from the input, and apply to output */
60
+ rb_enc_copy(result, text);
61
+
56
62
  return result;
57
63
  }
58
64
 
@@ -71,9 +77,18 @@ rb_multimarkdown_extract_metadata(VALUE self, VALUE key)
71
77
 
72
78
  /* Display metadata on request */
73
79
  char *metadata = extract_metadata_value(ptext, extensions, pkey);
74
- VALUE result = rb_str_new2(metadata);
80
+ int exists = metadata != NULL;
81
+ /* metadata might be null, if not present */
82
+ /* rb_str_new2 == rb_str_new_cstr */
83
+ VALUE result = exists ? rb_str_new2(metadata) : Qnil;
75
84
  free(metadata);
76
85
 
86
+ /* Take the encoding from the input, and apply to output */
87
+ if(exists)
88
+ {
89
+ rb_enc_copy(result, text);
90
+ }
91
+
77
92
  return result;
78
93
  }
79
94
 
@@ -7,7 +7,7 @@ require 'multimarkdown'
7
7
  MARKDOWN_TEST_DIR = "#{File.dirname(__FILE__)}/MultiMarkdownTest"
8
8
 
9
9
  class MultiMarkdownTest < MiniTest::Test
10
-
10
+
11
11
  def test_that_extension_methods_are_present_on_multimarkdown_class
12
12
  assert MultiMarkdown.instance_methods.include?(:to_html),
13
13
  "MultiMarkdown class should respond to #to_html"
@@ -60,6 +60,33 @@ class MultiMarkdownTest < MiniTest::Test
60
60
  multimarkdown.to_html(true)
61
61
  end
62
62
 
63
+ def test_that_encoding_is_preserved_for_html
64
+ test = "Écouté bien!"
65
+ html = MultiMarkdown.new(test, :smart).to_html
66
+ assert_equal html.encoding, test.encoding
67
+ assert_equal "<p>Écouté bien!</p>", html.strip
68
+ end
69
+
70
+ def test_that_encoding_is_preserved_for_latex
71
+ test = "Écouté bien!"
72
+ latex = MultiMarkdown.new(test, :smart).to_latex
73
+ assert_equal latex.encoding, test.encoding
74
+ assert_equal "Écouté bien!", latex.strip
75
+ end
76
+
77
+ def test_that_encoding_is_preserved_for_metadata
78
+ test = "Title: Some åccentéd document\n\nÉcouté bien!"
79
+ title = MultiMarkdown.new(test, :smart).extract_metadata("title")
80
+ refute_nil title
81
+ assert_equal title.encoding, test.encoding
82
+ assert_equal "Some åccentéd document", title.strip
83
+ end
84
+
85
+ def test_that_missing_metadata_returns_nil
86
+ test = "Title: Some document\n\nHere's some text"
87
+ author = MultiMarkdown.new(test, :smart).extract_metadata("author")
88
+ assert_nil author
89
+ end
63
90
 
64
91
 
65
92
  # Build tests for each file in the MarkdownTest test suite
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rpeg-multimarkdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Whyte