commonmarker 0.14.4 → 0.14.5
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.
- checksums.yaml +4 -4
- data/README.md +12 -12
- data/commonmarker.gemspec +1 -1
- data/ext/commonmarker/cmark/extensions/CMakeLists.txt +1 -1
- data/ext/commonmarker/cmark/src/CMakeLists.txt +1 -1
- data/ext/commonmarker/extconf.rb +1 -1
- data/lib/commonmarker.rb +2 -2
- data/lib/commonmarker/config.rb +8 -8
- data/lib/commonmarker/node.rb +2 -2
- data/lib/commonmarker/version.rb +1 -1
- data/test/test_commonmark.rb +1 -1
- data/test/test_encoding.rb +1 -1
- data/test/test_extensions.rb +9 -9
- data/test/test_linebreaks.rb +2 -2
- data/test/test_smartpunct.rb +3 -3
- data/test/test_spec.rb +2 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2464d1ed429720b63b234bbd8a57114c18c0f80f
|
4
|
+
data.tar.gz: 9f58b78d8a6e2262da5a78948ef73da2d55722fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebafa228760dfd38353a459726f4090638f1e007a7e80c29f45548a2fed122379a5ba6c7b3900e98885248725dd23a6daec2c5ef7e09c11f80335c9e81b69ce3
|
7
|
+
data.tar.gz: 862331cc8c3b5d90566e07dcf4b2fc572c60d36a8a5d4078517256fed201d2988d4c27df08f5662d509bbe3914c3f5ac6bf8c14f7fc46e013424f8539199a390
|
data/README.md
CHANGED
@@ -27,7 +27,7 @@ Call `render_html` on a string to convert it to HTML:
|
|
27
27
|
|
28
28
|
``` ruby
|
29
29
|
require 'commonmarker'
|
30
|
-
CommonMarker.render_html('Hi *there*', :
|
30
|
+
CommonMarker.render_html('Hi *there*', :DEFAULT)
|
31
31
|
# <p>Hi <em>there</em></p>\n
|
32
32
|
```
|
33
33
|
|
@@ -40,7 +40,7 @@ You can also parse a string to receive a `Document` node. You can than print tha
|
|
40
40
|
``` ruby
|
41
41
|
require 'commonmarker'
|
42
42
|
|
43
|
-
doc = CommonMarker.render_doc('*Hello* world', :
|
43
|
+
doc = CommonMarker.render_doc('*Hello* world', :DEFAULT)
|
44
44
|
puts(doc.to_html) # <p>Hi <em>there</em></p>\n
|
45
45
|
|
46
46
|
doc.walk do |node|
|
@@ -129,33 +129,33 @@ CommonMarker accepts the same options that CMark does, as symbols. Note that the
|
|
129
129
|
|
130
130
|
| Name | Description |
|
131
131
|
|-------|--------------|
|
132
|
-
| `:
|
133
|
-
| `:
|
134
|
-
| `:
|
135
|
-
| `:
|
132
|
+
| `:DEFAULT` | The default parsing system.
|
133
|
+
| `:NORMALIZE` | Attempt to normalize the HTML.
|
134
|
+
| `:SMART` | Use smart punctuation (curly quotes, etc.).
|
135
|
+
| `:VALIDATE_UTF8` | Replace illegal sequences with the replacement character `U+FFFD`.
|
136
136
|
|
137
137
|
### Render options
|
138
138
|
|
139
139
|
| Name | Description |
|
140
140
|
|-------|--------------|
|
141
|
-
| `:
|
142
|
-
| `:
|
143
|
-
| `:
|
144
|
-
| `:
|
141
|
+
| `:DEFAULT` | The default rendering system.
|
142
|
+
| `:SOURCEPOS` | Include source position in rendered HTML.
|
143
|
+
| `:HARDBREAKS` | Treat `\n` as hardbreaks (by adding `<br/>`).
|
144
|
+
| `:SAFE` | Suppress raw HTML and unsafe links.
|
145
145
|
|
146
146
|
### Passing options
|
147
147
|
|
148
148
|
To apply a single option, pass it in as a symbol argument:
|
149
149
|
|
150
150
|
``` ruby
|
151
|
-
CommonMarker.render_doc("\"Hello,\" said the spider.", :
|
151
|
+
CommonMarker.render_doc("\"Hello,\" said the spider.", :SMART)
|
152
152
|
# <p>“Hello,” said the spider.</p>\n
|
153
153
|
```
|
154
154
|
|
155
155
|
To have multiple options applied, pass in an array of symbols:
|
156
156
|
|
157
157
|
``` ruby
|
158
|
-
CommonMarker.render_html("\"'Shelob' is my name.\"", [:
|
158
|
+
CommonMarker.render_html("\"'Shelob' is my name.\"", [:HARDBREAKS, :SOURCEPOS])
|
159
159
|
```
|
160
160
|
|
161
161
|
For more information on these options, see [the CMark documentation](http://git.io/vlQii).
|
data/commonmarker.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.executables = ['commonmarker']
|
25
25
|
s.require_paths = %w(lib ext)
|
26
26
|
|
27
|
-
s.add_dependency 'ruby-enum', '
|
27
|
+
s.add_dependency 'ruby-enum', '~> 0.5'
|
28
28
|
|
29
29
|
s.add_development_dependency 'minitest', '~> 5.6'
|
30
30
|
s.add_development_dependency 'rake-compiler', '~> 0.9'
|
@@ -58,7 +58,7 @@ if (CMARK_STATIC)
|
|
58
58
|
add_library(${STATICLIBRARY} STATIC ${LIBRARY_SOURCES})
|
59
59
|
|
60
60
|
set_target_properties(${STATICLIBRARY} PROPERTIES
|
61
|
-
COMPILE_FLAGS -DCMARKEXTENSIONS_STATIC_DEFINE
|
61
|
+
COMPILE_FLAGS "-DCMARK_STATIC_DEFINE -DCMARKEXTENSIONS_STATIC_DEFINE"
|
62
62
|
POSITION_INDEPENDENT_CODE ON)
|
63
63
|
|
64
64
|
if (MSVC)
|
@@ -70,7 +70,7 @@ include (GenerateExportHeader)
|
|
70
70
|
add_executable(${PROGRAM} ${PROGRAM_SOURCES})
|
71
71
|
add_compiler_export_flags()
|
72
72
|
|
73
|
-
target_link_libraries(${PROGRAM}
|
73
|
+
target_link_libraries(${PROGRAM} libcmark_static)
|
74
74
|
|
75
75
|
add_dependencies(${PROGRAM} libcmarkextensions_static)
|
76
76
|
target_link_libraries(${PROGRAM} libcmarkextensions_static)
|
data/ext/commonmarker/extconf.rb
CHANGED
@@ -47,6 +47,6 @@ end
|
|
47
47
|
|
48
48
|
$LDFLAGS << " -L#{CMARK_BUILD_DIR}/src -L#{CMARK_BUILD_DIR}/extensions -lcmark -lcmarkextensions"
|
49
49
|
$CFLAGS << " -O2 -I#{CMARK_DIR}/src -I#{CMARK_DIR}/extensions -I#{CMARK_BUILD_DIR}/src -I#{CMARK_BUILD_DIR}/extensions"
|
50
|
-
$CFLAGS << " -DCMARK_STATIC_DEFINE"
|
50
|
+
$CFLAGS << " -DCMARK_STATIC_DEFINE -DCMARKEXTENSIONS_STATIC_DEFINE"
|
51
51
|
|
52
52
|
create_makefile('commonmarker/commonmarker')
|
data/lib/commonmarker.rb
CHANGED
@@ -18,7 +18,7 @@ module CommonMarker
|
|
18
18
|
# extensions - An {Array of Symbol}s indicating the extensions to use
|
19
19
|
#
|
20
20
|
# Returns a {String} of converted HTML.
|
21
|
-
def self.render_html(text, options = :
|
21
|
+
def self.render_html(text, options = :DEFAULT, extensions = [])
|
22
22
|
fail TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String)
|
23
23
|
opts = Config.process_options(options, :render)
|
24
24
|
text = text.encode('UTF-8')
|
@@ -33,7 +33,7 @@ module CommonMarker
|
|
33
33
|
# extensions - An {Array of Symbol}s indicating the extensions to use
|
34
34
|
#
|
35
35
|
# Returns the `document` node.
|
36
|
-
def self.render_doc(text, options = :
|
36
|
+
def self.render_doc(text, options = :DEFAULT, extensions = [])
|
37
37
|
fail TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String)
|
38
38
|
opts = Config.process_options(options, :parse)
|
39
39
|
text = text.encode('UTF-8')
|
data/lib/commonmarker/config.rb
CHANGED
@@ -5,19 +5,19 @@ module CommonMarker
|
|
5
5
|
class Parse
|
6
6
|
include Ruby::Enum
|
7
7
|
|
8
|
-
define :
|
9
|
-
define :
|
10
|
-
define :
|
11
|
-
define :
|
8
|
+
define :DEFAULT, 0
|
9
|
+
define :NORMALIZE, (1 << 8)
|
10
|
+
define :VALIDATE_UTF8, (1 << 9)
|
11
|
+
define :SMART, (1 << 10)
|
12
12
|
end
|
13
13
|
|
14
14
|
class Render
|
15
15
|
include Ruby::Enum
|
16
16
|
|
17
|
-
define :
|
18
|
-
define :
|
19
|
-
define :
|
20
|
-
define :
|
17
|
+
define :DEFAULT, 0
|
18
|
+
define :SOURCEPOS, (1 << 1)
|
19
|
+
define :HARDBREAKS, (1 << 2)
|
20
|
+
define :SAFE, (1 << 3)
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.process_options(option, type)
|
data/lib/commonmarker/node.rb
CHANGED
@@ -20,7 +20,7 @@ module CommonMarker
|
|
20
20
|
# extensions - An {Array of Symbol}s indicating the extensions to use
|
21
21
|
#
|
22
22
|
# Returns a {String}.
|
23
|
-
def to_html(options = :
|
23
|
+
def to_html(options = :DEFAULT, extensions = [])
|
24
24
|
opts = Config.process_options(options, :render)
|
25
25
|
_render_html(opts, extensions).force_encoding('utf-8')
|
26
26
|
end
|
@@ -30,7 +30,7 @@ module CommonMarker
|
|
30
30
|
# options - A {Symbol} or {Array of Symbol}s indicating the render options
|
31
31
|
#
|
32
32
|
# Returns a {String}.
|
33
|
-
def to_commonmark(options = :
|
33
|
+
def to_commonmark(options = :DEFAULT)
|
34
34
|
opts = Config.process_options(options, :render)
|
35
35
|
_render_commonmark(opts).force_encoding('utf-8')
|
36
36
|
end
|
data/lib/commonmarker/version.rb
CHANGED
data/test/test_commonmark.rb
CHANGED
data/test/test_encoding.rb
CHANGED
@@ -5,7 +5,7 @@ class TestEncoding < Minitest::Test
|
|
5
5
|
# see http://git.io/vq4FR
|
6
6
|
def test_encoding
|
7
7
|
contents = File.read(File.join(FIXTURES_DIR, 'curly.md'), encoding: 'utf-8')
|
8
|
-
doc = CommonMarker.render_doc(contents, :
|
8
|
+
doc = CommonMarker.render_doc(contents, :SMART)
|
9
9
|
render = doc.to_html
|
10
10
|
assert_equal render.rstrip, '<p>This curly quote “makes commonmarker throw an exception”.</p>'
|
11
11
|
end
|
data/test/test_extensions.rb
CHANGED
@@ -17,25 +17,25 @@ Another extension:
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_uses_specified_extensions
|
20
|
-
CommonMarker.render_html(@markdown, :
|
20
|
+
CommonMarker.render_html(@markdown, :DEFAULT, %i[]).tap do |out|
|
21
21
|
assert out.include?("| a")
|
22
22
|
assert out.include?("| <strong>x</strong>")
|
23
23
|
assert out.include?("~~hi~~")
|
24
24
|
end
|
25
25
|
|
26
|
-
CommonMarker.render_html(@markdown, :
|
26
|
+
CommonMarker.render_html(@markdown, :DEFAULT, %i[table]).tap do |out|
|
27
27
|
refute out.include?("| a")
|
28
28
|
%w(<table> <tr> <th> a </th> <td> c </td> <strong>x</strong>).each {|html| assert out.include?(html) }
|
29
29
|
assert out.include?("~~hi~~")
|
30
30
|
end
|
31
31
|
|
32
|
-
CommonMarker.render_html(@markdown, :
|
32
|
+
CommonMarker.render_html(@markdown, :DEFAULT, %i[strikethrough]).tap do |out|
|
33
33
|
assert out.include?("| a")
|
34
34
|
refute out.include?("~~hi~~")
|
35
35
|
assert out.include?("<del>hi</del>")
|
36
36
|
end
|
37
37
|
|
38
|
-
CommonMarker.render_html(@markdown, :
|
38
|
+
CommonMarker.render_html(@markdown, :DEFAULT, %i[table strikethrough]).tap do |out|
|
39
39
|
refute out.include?("| a")
|
40
40
|
refute out.include?("| <strong>x</strong>")
|
41
41
|
refute out.include?("~~hi~~")
|
@@ -44,7 +44,7 @@ Another extension:
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def test_extensions_with_renderers
|
47
|
-
doc = CommonMarker.render_doc(@markdown, :
|
47
|
+
doc = CommonMarker.render_doc(@markdown, :DEFAULT, %i[table])
|
48
48
|
|
49
49
|
doc.to_html.tap do |out|
|
50
50
|
refute out.include?("| a")
|
@@ -60,13 +60,13 @@ Another extension:
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def test_bad_extension_specifications
|
63
|
-
assert_raises(TypeError) { CommonMarker.render_html(@markdown, :
|
64
|
-
assert_raises(TypeError) { CommonMarker.render_html(@markdown, :
|
65
|
-
assert_raises(ArgumentError) { CommonMarker.render_html(@markdown, :
|
63
|
+
assert_raises(TypeError) { CommonMarker.render_html(@markdown, :DEFAULT, "nope") }
|
64
|
+
assert_raises(TypeError) { CommonMarker.render_html(@markdown, :DEFAULT, ["table"]) }
|
65
|
+
assert_raises(ArgumentError) { CommonMarker.render_html(@markdown, :DEFAULT, %i[table bad]) }
|
66
66
|
end
|
67
67
|
|
68
68
|
def test_comments_are_kept_as_expected
|
69
69
|
assert_equal "<!--hello--> <blah> <xmp>\n",
|
70
|
-
CommonMarker.render_html("<!--hello--> <blah> <xmp>\n", :
|
70
|
+
CommonMarker.render_html("<!--hello--> <blah> <xmp>\n", :DEFAULT, %i[tagfilter])
|
71
71
|
end
|
72
72
|
end
|
data/test/test_linebreaks.rb
CHANGED
@@ -3,11 +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<br />\nbaz</p>\n", doc.to_html(:
|
6
|
+
assert_equal "<p>foo<br />\nbaz</p>\n", doc.to_html(:HARDBREAKS)
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_hardbreak_with_spaces
|
10
10
|
doc = CommonMarker.render_doc("foo \nbaz")
|
11
|
-
assert_equal "<p>foo<br />\nbaz</p>\n", doc.to_html(:
|
11
|
+
assert_equal "<p>foo<br />\nbaz</p>\n", doc.to_html(:HARDBREAKS)
|
12
12
|
end
|
13
13
|
end
|
data/test/test_smartpunct.rb
CHANGED
@@ -4,7 +4,7 @@ class SmartPunctTest < Minitest::Test
|
|
4
4
|
smart_punct = open_spec_file('smart_punct.txt')
|
5
5
|
|
6
6
|
smart_punct.each do |testcase|
|
7
|
-
doc = CommonMarker.render_doc(testcase[:markdown], :
|
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
|
@@ -16,7 +16,7 @@ class SmartPunctTest < Minitest::Test
|
|
16
16
|
def test_smart_hardbreak_no_spaces_render_doc
|
17
17
|
markdown = "\"foo\"\nbaz"
|
18
18
|
result = "<p>“foo”<br />\nbaz</p>\n"
|
19
|
-
doc = CommonMarker.render_doc(markdown, :
|
20
|
-
assert_equal result, doc.to_html([:
|
19
|
+
doc = CommonMarker.render_doc(markdown, :SMART)
|
20
|
+
assert_equal result, doc.to_html([:HARDBREAKS])
|
21
21
|
end
|
22
22
|
end
|
data/test/test_spec.rb
CHANGED
@@ -6,10 +6,10 @@ class TestSpec < Minitest::Test
|
|
6
6
|
|
7
7
|
spec.each do |testcase|
|
8
8
|
# next unless testcase['example'] == 420
|
9
|
-
doc = CommonMarker.render_doc(testcase[:markdown], :
|
9
|
+
doc = CommonMarker.render_doc(testcase[:markdown], :DEFAULT, testcase[:extensions])
|
10
10
|
|
11
11
|
define_method("test_to_html_example_#{testcase[:example]}") do
|
12
|
-
actual = doc.to_html(:
|
12
|
+
actual = doc.to_html(:DEFAULT, testcase[:extensions]).rstrip
|
13
13
|
assert_equal testcase[:html], actual, testcase[:markdown]
|
14
14
|
end
|
15
15
|
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: commonmarker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.14.
|
4
|
+
version: 0.14.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garen Torikian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-enum
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.5
|
19
|
+
version: '0.5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.5
|
26
|
+
version: '0.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|