commonmarker 0.17.7.1 → 0.17.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62db9ada9b0ec7e95b771d2ddf75f6062b5f4434
4
- data.tar.gz: 4b2fc6430b0cfdbdff042429511d5cb82415c3dc
3
+ metadata.gz: 69c41f8d0a015334fbd220a9e2145505a4be9c65
4
+ data.tar.gz: 488ba4741fb7a2d2d35d7e6e809258117b3be7e9
5
5
  SHA512:
6
- metadata.gz: d817521a55244e3f9f1632e827b998fe72adcaa2975b8d79615cc03347ac4c1105f81eee423d5ae36fcbf64ef5f54d4fc36d18d77e70c5da820f11568e559e4d
7
- data.tar.gz: 5c4afeae4736e9122721a0052a77e494c3925c974d3f32689b6fdf40aa94e2bf3aaa4d01f23f36cd7935cf0c18dc1780d0792b25ac5448c947745f880b48d7bb
6
+ metadata.gz: 862e194be41831558ef5df2863f5ff4ff041472c2036d6fdd15f85667657de6cf33431da1571acb5ded8c4ce697b4c897bafabcea8d3cc80e66a9d61e76b7a05
7
+ data.tar.gz: fe5f480b49c4f93ab1becf7c22ec074afb8bfd6b478de569de1e6f076d49a2f88e3898999c16c1ad4b49f98f25a6c6d78fb1f23b34e1039f956aa2e47bbe74df
data/README.md CHANGED
@@ -147,6 +147,7 @@ CommonMarker accepts the same options that CMark does, as symbols. Note that the
147
147
  | `:NOBREAKS` | Translate `\n` in the source to a single whitespace.
148
148
  | `:SAFE` | Suppress raw HTML and unsafe links.
149
149
  | `:GITHUB_PRE_LANG` | Use GitHub-style `<pre lang>` for fenced code blocks.
150
+ | `:TABLE_PREFER_STYLE_ATTRIBUTES` | Use `style` insted of `align` for table cells
150
151
 
151
152
  ### Passing options
152
153
 
@@ -175,7 +176,6 @@ The available extensions are:
175
176
  * `:strikethrough` - This provides support for strikethroughs.
176
177
  * `:autolink` - This provides support for automatically converting URLs to anchor tags.
177
178
  * `:tagfilter` - This strips out [several "unsafe" HTML tags](https://github.github.com/gfm/#disallowed-raw-html-extension-) from being used.
178
- * `:tasklist` - This enables support for task list rendering.
179
179
 
180
180
  ## Developing locally
181
181
 
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.version = CommonMarker::VERSION
9
9
  s.summary = 'CommonMark parser and renderer. Written in C, wrapped in Ruby.'
10
10
  s.description = 'A fast, safe, extensible parser for CommonMark. This wraps the official libcmark library.'
11
- s.authors = ['Garen Torikian', 'Yuki Izumi']
11
+ s.authors = ['Garen Torikian', 'Ashe Connor']
12
12
  s.homepage = 'http://github.com/gjtorikian/commonmarker'
13
13
  s.license = 'MIT'
14
14
  s.required_ruby_version = '>= 2.0.0'
@@ -724,6 +724,15 @@ char *cmark_render_latex_with_mem(cmark_node *root, int options, int width, cmar
724
724
  */
725
725
  #define CMARK_OPT_FOOTNOTES (1 << 13)
726
726
 
727
+ /** Only parse strikethroughs if surrounded by exactly 2 tildes.
728
+ * Gives some compatibility with redcarpet.
729
+ */
730
+ #define CMARK_OPT_STRIKETHROUGH_DOUBLE_TILDE (1 << 14)
731
+
732
+ /** Use style attributes to align table cells instead of align attributes.
733
+ */
734
+ #define CMARK_OPT_TABLE_PREFER_STYLE_ATTRIBUTES (1 << 15)
735
+
727
736
  /**
728
737
  * ## Version information
729
738
  */
@@ -1,8 +1,8 @@
1
1
  #ifndef CMARK_VERSION_H
2
2
  #define CMARK_VERSION_H
3
3
 
4
- #define CMARK_VERSION ((0 << 24) | (28 << 16) | (3 << 8) | 11)
5
- #define CMARK_VERSION_STRING "0.28.3.gfm.11"
6
- #define CMARK_GFM_VERSION 11
4
+ #define CMARK_VERSION ((0 << 24) | (28 << 16) | (3 << 8) | 12)
5
+ #define CMARK_VERSION_STRING "0.28.3.gfm.12"
6
+ #define CMARK_GFM_VERSION 12
7
7
 
8
8
  #endif
@@ -524,7 +524,7 @@ static VALUE rb_node_insert_before(VALUE self, VALUE sibling) {
524
524
  *
525
525
  * Returns a {String}.
526
526
  */
527
- static VALUE rb_render_html(VALUE n, VALUE rb_options, VALUE rb_extensions) {
527
+ static VALUE rb_render_html(VALUE self, VALUE rb_options, VALUE rb_extensions) {
528
528
  int options, extensions_len;
529
529
  VALUE rb_ext_name;
530
530
  int i;
@@ -537,7 +537,7 @@ static VALUE rb_render_html(VALUE n, VALUE rb_options, VALUE rb_extensions) {
537
537
  options = FIX2INT(rb_options);
538
538
  extensions_len = RARRAY_LEN(rb_extensions);
539
539
 
540
- Data_Get_Struct(n, cmark_node, node);
540
+ Data_Get_Struct(self, cmark_node, node);
541
541
 
542
542
  for (i = 0; i < extensions_len; ++i) {
543
543
  rb_ext_name = RARRAY_PTR(rb_extensions)[i];
@@ -571,15 +571,24 @@ static VALUE rb_render_html(VALUE n, VALUE rb_options, VALUE rb_extensions) {
571
571
  *
572
572
  * Returns a {String}.
573
573
  */
574
- static VALUE rb_render_commonmark(VALUE n, VALUE rb_options) {
574
+ static VALUE rb_render_commonmark(int argc, VALUE *argv, VALUE self) {
575
+ VALUE rb_options, rb_width;
576
+ rb_scan_args(argc, argv, "11", &rb_options, &rb_width);
577
+
578
+ int width = 120;
579
+ if (!NIL_P(rb_width)) {
580
+ Check_Type(rb_width, T_FIXNUM);
581
+ width = FIX2INT(rb_width);
582
+ }
583
+
575
584
  int options;
576
585
  cmark_node *node;
577
586
  Check_Type(rb_options, T_FIXNUM);
578
587
 
579
588
  options = FIX2INT(rb_options);
580
- Data_Get_Struct(n, cmark_node, node);
589
+ Data_Get_Struct(self, cmark_node, node);
581
590
 
582
- char *cmark = cmark_render_commonmark(node, options, 120);
591
+ char *cmark = cmark_render_commonmark(node, options, width);
583
592
  VALUE ruby_cmark = rb_str_new2(cmark);
584
593
  free(cmark);
585
594
 
@@ -590,15 +599,24 @@ static VALUE rb_render_commonmark(VALUE n, VALUE rb_options) {
590
599
  *
591
600
  * Returns a {String}.
592
601
  */
593
- static VALUE rb_render_plaintext(VALUE n, VALUE rb_options) {
602
+ static VALUE rb_render_plaintext(int argc, VALUE *argv, VALUE self) {
603
+ VALUE rb_options, rb_width;
604
+ rb_scan_args(argc, argv, "11", &rb_options, &rb_width);
605
+
606
+ int width = 120;
607
+ if (!NIL_P(rb_width)) {
608
+ Check_Type(rb_width, T_FIXNUM);
609
+ width = FIX2INT(rb_width);
610
+ }
611
+
594
612
  int options;
595
613
  cmark_node *node;
596
614
  Check_Type(rb_options, T_FIXNUM);
597
615
 
598
616
  options = FIX2INT(rb_options);
599
- Data_Get_Struct(n, cmark_node, node);
617
+ Data_Get_Struct(self, cmark_node, node);
600
618
 
601
- char *text = cmark_render_plaintext(node, options, 120);
619
+ char *text = cmark_render_plaintext(node, options, width);
602
620
  VALUE ruby_text = rb_str_new2(text);
603
621
  free(text);
604
622
 
@@ -1148,8 +1166,8 @@ __attribute__((visibility("default"))) void Init_commonmarker() {
1148
1166
  rb_define_method(rb_mNode, "next", rb_node_next, 0);
1149
1167
  rb_define_method(rb_mNode, "insert_before", rb_node_insert_before, 1);
1150
1168
  rb_define_method(rb_mNode, "_render_html", rb_render_html, 2);
1151
- rb_define_method(rb_mNode, "_render_commonmark", rb_render_commonmark, 1);
1152
- rb_define_method(rb_mNode, "_render_plaintext", rb_render_plaintext, 1);
1169
+ rb_define_method(rb_mNode, "_render_commonmark", rb_render_commonmark, -1);
1170
+ rb_define_method(rb_mNode, "_render_plaintext", rb_render_plaintext, -1);
1153
1171
  rb_define_method(rb_mNode, "insert_after", rb_node_insert_after, 1);
1154
1172
  rb_define_method(rb_mNode, "prepend_child", rb_node_prepend_child, 1);
1155
1173
  rb_define_method(rb_mNode, "append_child", rb_node_append_child, 1);
@@ -27,7 +27,8 @@ static cmark_node *match(cmark_syntax_extension *self, cmark_parser *parser,
27
27
  res->start_line = res->end_line = cmark_inline_parser_get_line(inline_parser);
28
28
  res->start_column = cmark_inline_parser_get_column(inline_parser) - delims;
29
29
 
30
- if (left_flanking || right_flanking) {
30
+ if ((left_flanking || right_flanking) &&
31
+ (!(parser->options & CMARK_OPT_STRIKETHROUGH_DOUBLE_TILDE) || delims == 2)) {
31
32
  cmark_inline_parser_push_delimiter(inline_parser, character, left_flanking,
32
33
  right_flanking, res);
33
34
  }
@@ -542,6 +542,18 @@ static void man_render(cmark_syntax_extension *extension,
542
542
  }
543
543
  }
544
544
 
545
+ static void html_table_add_align(cmark_strbuf* html, const char* align, int options) {
546
+ if (options & CMARK_OPT_TABLE_PREFER_STYLE_ATTRIBUTES) {
547
+ cmark_strbuf_puts(html, " style=\"text-align: ");
548
+ cmark_strbuf_puts(html, align);
549
+ cmark_strbuf_puts(html, "\"");
550
+ } else {
551
+ cmark_strbuf_puts(html, " align=\"");
552
+ cmark_strbuf_puts(html, align);
553
+ cmark_strbuf_puts(html, "\"");
554
+ }
555
+ }
556
+
545
557
  struct html_table_state {
546
558
  unsigned need_closing_table_body : 1;
547
559
  unsigned in_table_header : 1;
@@ -611,9 +623,9 @@ static void html_render(cmark_syntax_extension *extension,
611
623
  break;
612
624
 
613
625
  switch (alignments[i]) {
614
- case 'l': cmark_strbuf_puts(html, " align=\"left\""); break;
615
- case 'c': cmark_strbuf_puts(html, " align=\"center\""); break;
616
- case 'r': cmark_strbuf_puts(html, " align=\"right\""); break;
626
+ case 'l': html_table_add_align(html, "left", options); break;
627
+ case 'c': html_table_add_align(html, "center", options); break;
628
+ case 'r': html_table_add_align(html, "right", options); break;
617
629
  }
618
630
 
619
631
  cmark_html_render_sourcepos(node, html, options);
@@ -10,6 +10,7 @@ module CommonMarker
10
10
  define :SMART, (1 << 10)
11
11
  define :LIBERAL_HTML_TAG, (1 << 12)
12
12
  define :FOOTNOTES, (1 << 13)
13
+ define :STRIKETHROUGH_DOUBLE_TILDE, (1 << 14)
13
14
  end
14
15
 
15
16
  class Render
@@ -21,6 +22,7 @@ module CommonMarker
21
22
  define :SAFE, (1 << 3)
22
23
  define :NOBREAKS, (1 << 4)
23
24
  define :GITHUB_PRE_LANG, (1 << 11)
25
+ define :TABLE_PREFER_STYLE_ATTRIBUTES, (1 << 15)
24
26
  end
25
27
 
26
28
  def self.process_options(option, type)
@@ -31,21 +31,23 @@ module CommonMarker
31
31
  # Public: Convert the node to a CommonMark string.
32
32
  #
33
33
  # options - A {Symbol} or {Array of Symbol}s indicating the render options
34
+ # width - Column to wrap the output at
34
35
  #
35
36
  # Returns a {String}.
36
- def to_commonmark(options = :DEFAULT)
37
+ def to_commonmark(options = :DEFAULT, width = 120)
37
38
  opts = Config.process_options(options, :render)
38
- _render_commonmark(opts).force_encoding('utf-8')
39
+ _render_commonmark(opts, width).force_encoding('utf-8')
39
40
  end
40
41
 
41
42
  # Public: Convert the node to a plain text string.
42
43
  #
43
44
  # options - A {Symbol} or {Array of Symbol}s indicating the render options
45
+ # width - Column to wrap the output at
44
46
  #
45
47
  # Returns a {String}.
46
- def to_plaintext(options = :DEFAULT)
48
+ def to_plaintext(options = :DEFAULT, width = 120)
47
49
  opts = Config.process_options(options, :render)
48
- _render_plaintext(opts).force_encoding('utf-8')
50
+ _render_plaintext(opts, width).force_encoding('utf-8')
49
51
  end
50
52
 
51
53
  # Public: Iterate over the children (if any) of the current pointer.
@@ -1,3 +1,3 @@
1
1
  module CommonMarker
2
- VERSION = '0.17.7.1'.freeze
2
+ VERSION = '0.17.8'.freeze
3
3
  end
@@ -35,6 +35,9 @@ Another extension:
35
35
  assert out.include?("<del>hi</del>")
36
36
  end
37
37
 
38
+ doc = CommonMarker.render_doc("~a~ ~~b~~ ~~~c~~~", :STRIKETHROUGH_DOUBLE_TILDE, [:strikethrough])
39
+ assert_equal doc.to_html, "<p>~a~ <del>b</del> ~~~c~~~</p>\n"
40
+
38
41
  CommonMarker.render_html(@markdown, :DEFAULT, %i[table strikethrough]).tap do |out|
39
42
  refute out.include?("| a")
40
43
  refute out.include?("| <strong>x</strong>")
@@ -57,6 +60,9 @@ Another extension:
57
60
  %w(<table> <tr> <th> a </th> <td> c </td> <strong>x</strong>).each {|html| assert out.include?(html) }
58
61
  assert out.include?("~~hi~~")
59
62
  end
63
+
64
+ doc = CommonMarker.render_doc("~a~ ~~b~~ ~~~c~~~", :STRIKETHROUGH_DOUBLE_TILDE, [:strikethrough])
65
+ assert_equal HtmlRenderer.new.render(doc), "<p>~a~ <del>b</del> ~~~c~~~</p>\n"
60
66
  end
61
67
 
62
68
  def test_bad_extension_specifications
@@ -69,4 +75,31 @@ Another extension:
69
75
  assert_equal "<!--hello--> <blah> &lt;xmp>\n",
70
76
  CommonMarker.render_html("<!--hello--> <blah> <xmp>\n", :DEFAULT, %i[tagfilter])
71
77
  end
78
+
79
+ def test_table_prefer_style_attributes
80
+ assert_equal(<<-HTML, CommonMarker.render_html(<<-MD, :TABLE_PREFER_STYLE_ATTRIBUTES, %i[table]))
81
+ <table>
82
+ <thead>
83
+ <tr>
84
+ <th style="text-align: left">aaa</th>
85
+ <th>bbb</th>
86
+ <th style="text-align: center">ccc</th>
87
+ <th>ddd</th>
88
+ <th style="text-align: right">eee</th>
89
+ </tr>
90
+ </thead>
91
+ <tbody>
92
+ <tr>
93
+ <td style="text-align: left">fff</td>
94
+ <td>ggg</td>
95
+ <td style="text-align: center">hhh</td>
96
+ <td>iii</td>
97
+ <td style="text-align: right">jjj</td>
98
+ </tr></tbody></table>
99
+ HTML
100
+ aaa | bbb | ccc | ddd | eee
101
+ :-- | --- | :-: | --- | --:
102
+ fff | ggg | hhh | iii | jjj
103
+ MD
104
+ end
72
105
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commonmarker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.7.1
4
+ version: 0.17.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian
8
- - Yuki Izumi
8
+ - Ashe Connor
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-12-10 00:00:00.000000000 Z
12
+ date: 2018-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby-enum