commonmarker 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of commonmarker might be problematic. Click here for more details.

Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -10
  3. data/ext/commonmarker/cmark/Makefile.nmake +2 -2
  4. data/ext/commonmarker/cmark/build/CMakeCache.txt +66 -23
  5. data/ext/commonmarker/cmark/build/CMakeFiles/3.3.2/CMakeCCompiler.cmake +63 -0
  6. data/ext/commonmarker/cmark/build/CMakeFiles/3.3.2/CMakeCXXCompiler.cmake +64 -0
  7. data/ext/commonmarker/cmark/build/CMakeFiles/3.3.2/CMakeDetermineCompilerABI_C.bin +0 -0
  8. data/ext/commonmarker/cmark/build/CMakeFiles/3.3.2/CMakeDetermineCompilerABI_CXX.bin +0 -0
  9. data/ext/commonmarker/cmark/build/CMakeFiles/3.3.2/CMakeSystem.cmake +15 -0
  10. data/ext/commonmarker/cmark/build/CMakeFiles/3.3.2/CompilerIdC/CMakeCCompilerId.c +508 -0
  11. data/ext/commonmarker/cmark/build/CMakeFiles/3.3.2/CompilerIdC/a.out +0 -0
  12. data/ext/commonmarker/cmark/build/CMakeFiles/3.3.2/CompilerIdCXX/CMakeCXXCompilerId.cpp +498 -0
  13. data/ext/commonmarker/cmark/build/CMakeFiles/3.3.2/CompilerIdCXX/a.out +0 -0
  14. data/ext/commonmarker/cmark/build/CMakeFiles/CMakeDirectoryInformation.cmake +8 -8
  15. data/ext/commonmarker/cmark/build/CMakeFiles/CMakeOutput.log +453 -0
  16. data/ext/commonmarker/cmark/build/CMakeFiles/Makefile.cmake +110 -59
  17. data/ext/commonmarker/cmark/build/CMakeFiles/Makefile2 +42 -18
  18. data/ext/commonmarker/cmark/build/CMakeFiles/TargetDirectories.txt +1 -1
  19. data/ext/commonmarker/cmark/build/CMakeFiles/feature_tests.bin +0 -0
  20. data/ext/commonmarker/cmark/build/CMakeFiles/feature_tests.c +34 -0
  21. data/ext/commonmarker/cmark/build/CMakeFiles/feature_tests.cxx +405 -0
  22. data/ext/commonmarker/cmark/build/CMakeFiles/progress.marks +1 -1
  23. data/ext/commonmarker/cmark/build/CTestTestfile.cmake +5 -5
  24. data/ext/commonmarker/cmark/build/Makefile +66 -53
  25. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/CMakeDirectoryInformation.cmake +8 -8
  26. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/DependInfo.cmake +17 -14
  27. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/build.make +23 -13
  28. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/cmake_clean.cmake +4 -4
  29. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/flags.make +1 -1
  30. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/link.txt +1 -1
  31. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/progress.make +1 -0
  32. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/progress.marks +1 -1
  33. data/ext/commonmarker/cmark/build/api_test/Makefile +76 -53
  34. data/ext/commonmarker/cmark/build/api_test/cmake_install.cmake +20 -20
  35. data/ext/commonmarker/cmark/build/cmake_install.cmake +35 -35
  36. data/ext/commonmarker/cmark/build/man/CMakeFiles/CMakeDirectoryInformation.cmake +8 -8
  37. data/ext/commonmarker/cmark/build/man/Makefile +65 -52
  38. data/ext/commonmarker/cmark/build/man/cmake_install.cmake +26 -26
  39. data/ext/commonmarker/cmark/build/src/CMakeFiles/CMakeDirectoryInformation.cmake +8 -8
  40. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/DependInfo.cmake +8 -11
  41. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/build.make +134 -107
  42. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/cmake_clean.cmake +4 -4
  43. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/flags.make +2 -4
  44. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/progress.make +21 -20
  45. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/DependInfo.cmake +11 -14
  46. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/build.make +72 -45
  47. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/cmake_clean.cmake +4 -4
  48. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/flags.make +1 -1
  49. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/link.txt +1 -1
  50. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/progress.make +20 -19
  51. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/DependInfo.cmake +8 -11
  52. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/blocks.c.o +0 -0
  53. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/buffer.c.o +0 -0
  54. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/build.make +128 -102
  55. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmake_clean.cmake +4 -4
  56. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmake_clean_target.cmake +1 -1
  57. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmark.c.o +0 -0
  58. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmark_ctype.c.o +0 -0
  59. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/commonmark.c.o +0 -0
  60. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/depend.internal +1 -1
  61. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/depend.make +1 -1
  62. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/flags.make +2 -4
  63. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/houdini_href_e.c.o +0 -0
  64. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/houdini_html_e.c.o +0 -0
  65. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/houdini_html_u.c.o +0 -0
  66. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/html.c.o +0 -0
  67. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/inlines.c.o +0 -0
  68. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/iterator.c.o +0 -0
  69. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/latex.c.o +0 -0
  70. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/link.txt +1 -1
  71. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/man.c.o +0 -0
  72. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/node.c.o +0 -0
  73. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/progress.make +20 -19
  74. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/references.c.o +0 -0
  75. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/render.c.o +0 -0
  76. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/scanners.c.o +0 -0
  77. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/utf8.c.o +0 -0
  78. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/xml.c.o +0 -0
  79. data/ext/commonmarker/cmark/build/src/CMakeFiles/progress.marks +1 -1
  80. data/ext/commonmarker/cmark/build/src/Makefile +127 -51
  81. data/ext/commonmarker/cmark/build/src/cmake_install.cmake +44 -47
  82. data/ext/commonmarker/cmark/build/src/cmark_export.h +8 -2
  83. data/ext/commonmarker/cmark/build/src/libcmark.a +0 -0
  84. data/ext/commonmarker/cmark/build/testdir/CMakeFiles/CMakeDirectoryInformation.cmake +8 -8
  85. data/ext/commonmarker/cmark/build/testdir/CTestTestfile.cmake +7 -7
  86. data/ext/commonmarker/cmark/build/testdir/Makefile +65 -52
  87. data/ext/commonmarker/cmark/build/testdir/cmake_install.cmake +20 -20
  88. data/ext/commonmarker/cmark/src/commonmark.c +1 -1
  89. data/ext/commonmarker/cmark/src/xml.c +1 -1
  90. data/lib/commonmarker.rb +14 -7
  91. data/lib/commonmarker/config.rb +27 -19
  92. data/lib/commonmarker/version.rb +1 -1
  93. data/test/test_encoding.rb +2 -1
  94. data/test/test_linebreaks.rb +0 -6
  95. data/test/test_maliciousness.rb +10 -0
  96. data/test/test_smartpunct.rb +8 -1
  97. metadata +15 -3
data/lib/commonmarker.rb CHANGED
@@ -13,12 +13,15 @@ module CommonMarker
13
13
  # Public: Parses a Markdown string into an HTML string.
14
14
  #
15
15
  # text - A {String} of text
16
- # option - Either a {Symbol} or {Array of Symbol}s indicating the parse options
16
+ # option - Either a {Symbol} or {Array of Symbol}s indicating the render options
17
17
  #
18
18
  # Returns a {String} of converted HTML.
19
- def self.render_html(text, option = :default)
19
+ def self.render_html(text, options = :default)
20
20
  fail TypeError, 'text must be a string!' unless text.is_a?(String)
21
- Node.markdown_to_html(text.encode('UTF-8'), Config.process_options(option)).force_encoding('UTF-8')
21
+ opts = Config.process_options(options, :render)
22
+ text = text.encode('UTF-8')
23
+ html = Node.markdown_to_html(text, opts)
24
+ html.force_encoding('UTF-8')
22
25
  end
23
26
 
24
27
  # Public: Parses a Markdown string into a `document` node.
@@ -27,10 +30,11 @@ module CommonMarker
27
30
  # option - A {Symbol} or {Array of Symbol}s indicating the parse options
28
31
  #
29
32
  # Returns the `document` node.
30
- def self.render_doc(text, option = :default)
33
+ def self.render_doc(text, options = :default)
31
34
  fail TypeError, 'text must be a string!' unless text.is_a?(String)
35
+ opts = Config.process_options(options, :parse)
32
36
  text = text.encode('UTF-8')
33
- Node.parse_document(text, text.bytesize, Config.process_options(option))
37
+ Node.parse_document(text, text.bytesize, opts)
34
38
  end
35
39
 
36
40
  class Node
@@ -46,9 +50,12 @@ module CommonMarker
46
50
 
47
51
  # Public: Convert the node to an HTML string.
48
52
  #
53
+ # options - A {Symbol} or {Array of Symbol}s indicating the render options
54
+ #
49
55
  # Returns a {String}.
50
- def to_html(option = :default)
51
- _render_html(Config.process_options(option)).force_encoding('utf-8')
56
+ def to_html(options = :default)
57
+ opts = Config.process_options(options, :render)
58
+ _render_html(opts).force_encoding('utf-8')
52
59
  end
53
60
 
54
61
  # Internal: Iterate over the children (if any) of the current pointer.
@@ -1,34 +1,42 @@
1
1
  require 'ruby-enum'
2
-
3
2
  module CommonMarker
4
- # For Ruby::Enum, this must be a class, not a module
5
- class Config
6
- include Ruby::Enum
3
+ # For Ruby::Enum, these must be classes, not modules
4
+ module Config
5
+ class Parse
6
+ include Ruby::Enum
7
+
8
+ define :default, 0
9
+ define :normalize, 4
10
+ define :validate_utf8, 16
11
+ define :smart, 8
12
+ end
7
13
 
8
- define :default, 0
9
- define :sourcepos, 1
10
- define :hardbreaks, 2
11
- define :normalize, 4
12
- define :smart, 8
13
- define :validate_utf8, 16
14
- define :safe, 32
14
+ class Render
15
+ include Ruby::Enum
16
+
17
+ define :default, 0
18
+ define :sourcepos, 1
19
+ define :hardbreaks, 2
20
+ define :safe, 32
21
+ end
15
22
 
16
- def self.process_options(option)
23
+ def self.process_options(option, type)
24
+ type = Config.const_get(type.capitalize)
17
25
  if option.is_a?(Symbol)
18
- check_option(option)
19
- Config.to_h[option]
26
+ check_option(option, type)
27
+ type.to_h[option]
20
28
  elsif option.is_a?(Array)
21
29
  option = [nil] if option.empty?
22
30
  # neckbearding around. the map will both check the opts and then bitwise-OR it
23
- option.map { |o| Config.check_option(o); Config.to_h[o] }.inject(0, :|)
31
+ option.map { |o| check_option(o, type); type.to_h[o] }.inject(0, :|)
24
32
  else
25
- fail TypeError, 'delimiter type must be a valid symbol or array of symbols'
33
+ fail TypeError, 'option type must be a valid symbol or array of symbols'
26
34
  end
27
35
  end
28
36
 
29
- def self.check_option(option)
30
- unless Config.keys.include?(option)
31
- fail TypeError, "option #{option} does not exist"
37
+ def self.check_option(option, type)
38
+ unless type.keys.include?(option)
39
+ fail TypeError, "option ':#{option}' does not exist for #{type}"
32
40
  end
33
41
  end
34
42
  end
@@ -1,3 +1,3 @@
1
1
  module CommonMarker
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.1'
3
3
  end
@@ -4,7 +4,8 @@ class TestEncoding < Minitest::Test
4
4
  # see http://git.io/vq4FR
5
5
  def test_encoding
6
6
  contents = File.read(File.join(FIXTURES_DIR, 'curly.md'))
7
- render = CommonMarker.render_html(contents, :smart)
7
+ doc = CommonMarker.render_doc(contents, :smart)
8
+ render = doc.to_html
8
9
  assert_equal render.rstrip, '<p>This curly quote “makes commonmarker throw an exception”.</p>'
9
10
  end
10
11
  end
@@ -3,17 +3,11 @@ require 'test_helper'
3
3
  class TestLinebreaks < Minitest::Test
4
4
  def test_hardbreak_no_spaces
5
5
  doc = CommonMarker.render_doc("foo\nbaz")
6
- assert_equal "<p>foo\nbaz</p>\n", doc.to_html
7
-
8
- doc = CommonMarker.render_doc("foo\nbaz", :hardbreaks)
9
6
  assert_equal "<p>foo<br />\nbaz</p>\n", doc.to_html(:hardbreaks)
10
7
  end
11
8
 
12
9
  def test_hardbreak_with_spaces
13
10
  doc = CommonMarker.render_doc("foo \nbaz")
14
- assert_equal "<p>foo<br />\nbaz</p>\n", doc.to_html
15
-
16
- doc = CommonMarker.render_doc("foo \nbaz", :hardbreaks)
17
11
  assert_equal "<p>foo<br />\nbaz</p>\n", doc.to_html(:hardbreaks)
18
12
  end
19
13
  end
@@ -64,10 +64,20 @@ class CommonMarker::TestMaliciousness < Minitest::Test
64
64
  CommonMarker.render_html(nil)
65
65
  end
66
66
 
67
+ err = assert_raises TypeError do
68
+ CommonMarker.render_html("foo \n baz", [:smart])
69
+ end
70
+ assert_equal err.message, 'option \':smart\' does not exist for CommonMarker::Config::Render'
71
+
67
72
  assert_raises TypeError do
68
73
  CommonMarker.render_doc("foo \n baz", 123)
69
74
  end
70
75
 
76
+ err = assert_raises TypeError do
77
+ CommonMarker.render_doc("foo \n baz", :safe)
78
+ end
79
+ assert_equal err.message, 'option \':safe\' does not exist for CommonMarker::Config::Parse'
80
+
71
81
  assert_raises TypeError do
72
82
  CommonMarker.render_doc("foo \n baz", :totes_fake)
73
83
  end
@@ -4,7 +4,7 @@ class SmartPunctTest < Minitest::Test
4
4
  smart_punct = open_spec_file('smart_punct.txt', normalize: true)
5
5
 
6
6
  smart_punct.each do |testcase|
7
- doc = CommonMarker.render_doc(testcase[:markdown], [:smart])
7
+ doc = CommonMarker.render_doc(testcase[:markdown], :smart)
8
8
 
9
9
  define_method("test_smart_punct_example_#{testcase[:example]}") do
10
10
  actual = doc.to_html.strip
@@ -12,4 +12,11 @@ class SmartPunctTest < Minitest::Test
12
12
  assert_equal testcase[:html], actual, testcase[:markdown]
13
13
  end
14
14
  end
15
+
16
+ def test_smart_hardbreak_no_spaces_render_doc
17
+ markdown = "\"foo\"\nbaz"
18
+ result = "<p>“foo”<br />\nbaz</p>\n"
19
+ doc = CommonMarker.render_doc(markdown, :smart)
20
+ assert_equal result, doc.to_html([:hardbreaks])
21
+ end
15
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commonmarker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-25 00:00:00.000000000 Z
11
+ date: 2015-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-enum
@@ -149,6 +149,15 @@ files:
149
149
  - ext/commonmarker/cmark/build/CMakeFiles/2.8.10.1/CompilerIdC/a.out
150
150
  - ext/commonmarker/cmark/build/CMakeFiles/2.8.10.1/CompilerIdCXX/CMakeCXXCompilerId.cpp
151
151
  - ext/commonmarker/cmark/build/CMakeFiles/2.8.10.1/CompilerIdCXX/a.out
152
+ - ext/commonmarker/cmark/build/CMakeFiles/3.3.2/CMakeCCompiler.cmake
153
+ - ext/commonmarker/cmark/build/CMakeFiles/3.3.2/CMakeCXXCompiler.cmake
154
+ - ext/commonmarker/cmark/build/CMakeFiles/3.3.2/CMakeDetermineCompilerABI_C.bin
155
+ - ext/commonmarker/cmark/build/CMakeFiles/3.3.2/CMakeDetermineCompilerABI_CXX.bin
156
+ - ext/commonmarker/cmark/build/CMakeFiles/3.3.2/CMakeSystem.cmake
157
+ - ext/commonmarker/cmark/build/CMakeFiles/3.3.2/CompilerIdC/CMakeCCompilerId.c
158
+ - ext/commonmarker/cmark/build/CMakeFiles/3.3.2/CompilerIdC/a.out
159
+ - ext/commonmarker/cmark/build/CMakeFiles/3.3.2/CompilerIdCXX/CMakeCXXCompilerId.cpp
160
+ - ext/commonmarker/cmark/build/CMakeFiles/3.3.2/CompilerIdCXX/a.out
152
161
  - ext/commonmarker/cmark/build/CMakeFiles/CMakeDirectoryInformation.cmake
153
162
  - ext/commonmarker/cmark/build/CMakeFiles/CMakeError.log
154
163
  - ext/commonmarker/cmark/build/CMakeFiles/CMakeOutput.log
@@ -156,6 +165,9 @@ files:
156
165
  - ext/commonmarker/cmark/build/CMakeFiles/Makefile2
157
166
  - ext/commonmarker/cmark/build/CMakeFiles/TargetDirectories.txt
158
167
  - ext/commonmarker/cmark/build/CMakeFiles/cmake.check_cache
168
+ - ext/commonmarker/cmark/build/CMakeFiles/feature_tests.bin
169
+ - ext/commonmarker/cmark/build/CMakeFiles/feature_tests.c
170
+ - ext/commonmarker/cmark/build/CMakeFiles/feature_tests.cxx
159
171
  - ext/commonmarker/cmark/build/CMakeFiles/progress.marks
160
172
  - ext/commonmarker/cmark/build/CTestTestfile.cmake
161
173
  - ext/commonmarker/cmark/build/Makefile
@@ -390,7 +402,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
390
402
  version: '0'
391
403
  requirements: []
392
404
  rubyforge_project:
393
- rubygems_version: 2.2.3
405
+ rubygems_version: 2.4.5
394
406
  signing_key:
395
407
  specification_version: 4
396
408
  summary: CommonMark parser and renderer. Written in C, wrapped in Ruby.