markly 0.2.0 → 0.5.0

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
  SHA256:
3
- metadata.gz: 93a192bb4cf0e216365ffa17fc619ecc726cb7cbd9a3661ae3357ce5a8dbb1c4
4
- data.tar.gz: ec39190db7ad173cdbbcddd73850fc07faa578d37892217cedd329efad060610
3
+ metadata.gz: 382ef4ee5a2e69398268595c59f914fc694c1fa0e450b7ba2f74a6ef06d17ede
4
+ data.tar.gz: 5d7119359d1f485980ac4ba9736384f0c67ac0002133021fccf3aa81896ef46e
5
5
  SHA512:
6
- metadata.gz: 5668b9796316e769f73a6d97c495116e3361b9cc0a12fa92c8ec35461954a63d7568e8975af4720d060605ccb2ecdcc96bf123da2074271216a2e55e3afa378d
7
- data.tar.gz: 132e25acaad81e6953c4c25a206dc6e37ba0f2cff3176887fb81882817edd81fa6c2a8eb24cf274046635b30f1179832f2daeb00ec78e18f4afb537166e4aab7
6
+ metadata.gz: 9b941bb485e19ed83aa4268e5586f39fdc4919e9dc6362dd729980b698a5f35e26299a742382e6055ee644d297393c0c1e95ef8cac5003765beb9ff47f1dc384
7
+ data.tar.gz: 356b61f0db0b4c0fa57d2cca31943264daaad9c31ed2bc5a04d7cdebf0fa27d863215c1ae1a48372d5ccc1b9a52a287ad8fee3657a778667d76cb3bf37592dff
@@ -41,11 +41,15 @@ static VALUE sym_right;
41
41
  static VALUE sym_center;
42
42
 
43
43
  static void rb_Markly_Node_free(void *data) {
44
- // It's important that the `free` function does not inspect the node data, as it may be part of a tree that was already freed.
45
- cmark_node *node = (cmark_node*)data;
46
-
47
- if (cmark_node_parent(node) == NULL) {
48
- cmark_node_free(node);
44
+ // If a parent of this node is already freed, `rb_Markly_Node_freed` will ensure all the nodes are nullified.
45
+ if (data) {
46
+ cmark_node *node = (cmark_node*)data;
47
+
48
+ if (cmark_node_parent(node) == NULL) {
49
+ cmark_node_free(node);
50
+ } else {
51
+ cmark_node_set_user_data(node, NULL);
52
+ }
49
53
  }
50
54
  }
51
55
 
@@ -79,6 +83,12 @@ static const rb_data_type_t rb_Markly_Node_Type = {
79
83
  .flags = RUBY_TYPED_FREE_IMMEDIATELY,
80
84
  };
81
85
 
86
+ static void rb_Markly_Node_freed(cmark_mem *mem, void *user_data) {
87
+ VALUE self = (VALUE)user_data;
88
+
89
+ RTYPEDDATA_DATA(self) = NULL;
90
+ }
91
+
82
92
  static VALUE rb_Markly_Node_wrap(cmark_node *node) {
83
93
  if (node == NULL)
84
94
  return Qnil;
@@ -91,6 +101,7 @@ static VALUE rb_Markly_Node_wrap(cmark_node *node) {
91
101
 
92
102
  VALUE self = TypedData_Wrap_Struct(rb_Markly_Node, &rb_Markly_Node_Type, node);
93
103
  cmark_node_set_user_data(node, (void *)self);
104
+ cmark_node_set_user_data_free_func(node, rb_Markly_Node_freed);
94
105
 
95
106
  return self;
96
107
  }
@@ -121,16 +132,6 @@ static const rb_data_type_t rb_Markly_Parser_Type = {
121
132
  .flags = RUBY_TYPED_FREE_IMMEDIATELY,
122
133
  };
123
134
 
124
- static VALUE rb_Markly_Parser_root(VALUE self) {
125
- cmark_parser *parser = NULL;
126
-
127
- TypedData_Get_Struct(self, cmark_parser, &rb_Markly_Parser_Type, parser);
128
-
129
- assert(parser != NULL);
130
-
131
- return rb_Markly_Node_wrap(parser->root);
132
- }
133
-
134
135
  static VALUE rb_Markly_Parser_alloc(VALUE self) {
135
136
  return TypedData_Wrap_Struct(self, &rb_Markly_Parser_Type, NULL);
136
137
  }
@@ -330,10 +331,10 @@ static VALUE rb_node_set_string_content(VALUE self, VALUE s) {
330
331
  * Returns a {Symbol} representing the node's type.
331
332
  */
332
333
  static VALUE rb_node_get_type(VALUE self) {
333
- int node_type;
334
- cmark_node *node;
335
- VALUE symbol;
336
- const char *s;
334
+ int node_type = 0;
335
+ cmark_node *node = NULL;
336
+ VALUE symbol = NULL;
337
+ const char *s = NULL;
337
338
 
338
339
  TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
339
340
 
@@ -1193,7 +1194,6 @@ __attribute__((visibility("default"))) void Init_markly() {
1193
1194
  rb_define_method(rb_Markly_Parser, "initialize", rb_Markly_Parser_initialize, 1);
1194
1195
  rb_define_method(rb_Markly_Parser, "enable", rb_Markly_Parser_enable, 1);
1195
1196
  rb_define_method(rb_Markly_Parser, "parse", rb_Markly_Parser_parse, 1);
1196
- rb_define_method(rb_Markly_Parser, "root", rb_Markly_Parser_root, 0);
1197
1197
 
1198
1198
  rb_Markly_Node = rb_define_class_under(rb_Markly, "Node", rb_cObject);
1199
1199
  rb_define_singleton_method(rb_Markly_Node, "new", rb_node_new, 1);
Binary file
@@ -1,14 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'cgi'
4
+
3
5
  module Markly
4
- class HtmlRenderer < Renderer
6
+ class HTMLRenderer < Renderer
7
+ def initialize(ids: false, **options)
8
+ super(**options)
9
+
10
+ @ids = ids
11
+ @section = nil
12
+ end
13
+
5
14
  def document(_)
15
+ @section = false
6
16
  super
7
17
  out("</ol>\n</section>\n") if @written_footnote_ix
18
+ out("</section>") if @section
19
+ end
20
+
21
+ def id_for(node)
22
+ if @ids
23
+ id = node.to_plaintext.chomp.downcase.gsub(/\s+/, '-')
24
+
25
+ return " id=\"#{CGI.escape_html id}\""
26
+ end
8
27
  end
9
28
 
10
29
  def header(node)
11
30
  block do
31
+ out('</section>') if @section
32
+ @section = true
33
+ out("<section #{id_for(node)}>")
12
34
  out('<h', node.header_level, "#{source_position(node)}>", :children,
13
35
  '</h', node.header_level, '>')
14
36
  end
@@ -249,4 +271,7 @@ module Markly
249
271
  node.tasklist_item_checked?
250
272
  end
251
273
  end
274
+
275
+ # Legacy.
276
+ HtmlRenderer = HTMLRenderer
252
277
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Markly
4
- VERSION = '0.2.0'
4
+ VERSION = '0.5.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-06-13 00:00:00.000000000 Z
13
+ date: 2020-07-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bake
@@ -26,34 +26,6 @@ dependencies:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0'
29
- - !ruby/object:Gem::Dependency
30
- name: bake-bundler
31
- requirement: !ruby/object:Gem::Requirement
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
35
- version: '0'
36
- type: :development
37
- prerelease: false
38
- version_requirements: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- version: '0'
43
- - !ruby/object:Gem::Dependency
44
- name: bake-modernize
45
- requirement: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: '0'
50
- type: :development
51
- prerelease: false
52
- version_requirements: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: '0'
57
29
  - !ruby/object:Gem::Dependency
58
30
  name: minitest
59
31
  requirement: !ruby/object:Gem::Requirement
@@ -178,7 +150,7 @@ files:
178
150
  - ext/markly/xml.c
179
151
  - lib/markly.rb
180
152
  - lib/markly/flags.rb
181
- - lib/markly/markly.so
153
+ - lib/markly/markly.bundle
182
154
  - lib/markly/node.rb
183
155
  - lib/markly/node/inspect.rb
184
156
  - lib/markly/renderer.rb
Binary file