markly 0.1.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/markly/markly.c +38 -20
- data/lib/markly/markly.bundle +0 -0
- data/lib/markly/node.rb +2 -0
- data/lib/markly/renderer/html_renderer.rb +21 -2
- data/lib/markly/version.rb +1 -1
- metadata +8 -36
- data/lib/markly/markly.so +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 770b81ed57426a591eaa4335ad913df94f61017e08f5e19872766e59ec3d33db
|
4
|
+
data.tar.gz: 45f5295c1fae1747c841a85b8f17f1442d47ad91194a38874e1313e8c95313f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75bdb5b83d6ca7685fb659d27f45bfaaefe1241f306ec21281bbbd5906612663c8e4ba7ad3abf59069ff6501c72933c6770d09176dd119de946e5baea0b826ff
|
7
|
+
data.tar.gz: 0c0aa153efcbbb7914a805e52bf80fdda4bdc5d1ddb0352f7bb00c334f2730d8cd342a19fa273082c07597c16166c666b8f86be66a197729f902e0539903af8f
|
data/ext/markly/markly.c
CHANGED
@@ -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
|
-
//
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
}
|
@@ -262,6 +263,21 @@ static VALUE rb_node_new(VALUE self, VALUE type) {
|
|
262
263
|
return rb_Markly_Node_wrap(node);
|
263
264
|
}
|
264
265
|
|
266
|
+
static VALUE rb_node_replace(VALUE self, VALUE other) {
|
267
|
+
cmark_node *current_node = NULL, *replacement_node = NULL;
|
268
|
+
|
269
|
+
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, current_node);
|
270
|
+
TypedData_Get_Struct(other, cmark_node, &rb_Markly_Node_Type, replacement_node);
|
271
|
+
|
272
|
+
int result = cmark_node_replace(current_node, replacement_node);
|
273
|
+
|
274
|
+
if (result == 0) {
|
275
|
+
rb_raise(rb_Markly_Error, "could not replace node");
|
276
|
+
}
|
277
|
+
|
278
|
+
return other;
|
279
|
+
}
|
280
|
+
|
265
281
|
static VALUE encode_utf8_string(const char *c_string) {
|
266
282
|
VALUE string = rb_str_new2(c_string);
|
267
283
|
int enc = rb_enc_find_index("UTF-8");
|
@@ -315,10 +331,10 @@ static VALUE rb_node_set_string_content(VALUE self, VALUE s) {
|
|
315
331
|
* Returns a {Symbol} representing the node's type.
|
316
332
|
*/
|
317
333
|
static VALUE rb_node_get_type(VALUE self) {
|
318
|
-
int node_type;
|
319
|
-
cmark_node *node;
|
320
|
-
VALUE symbol;
|
321
|
-
const char *s;
|
334
|
+
int node_type = 0;
|
335
|
+
cmark_node *node = NULL;
|
336
|
+
VALUE symbol = NULL;
|
337
|
+
const char *s = NULL;
|
322
338
|
|
323
339
|
TypedData_Get_Struct(self, cmark_node, &rb_Markly_Node_Type, node);
|
324
340
|
|
@@ -1178,10 +1194,12 @@ __attribute__((visibility("default"))) void Init_markly() {
|
|
1178
1194
|
rb_define_method(rb_Markly_Parser, "initialize", rb_Markly_Parser_initialize, 1);
|
1179
1195
|
rb_define_method(rb_Markly_Parser, "enable", rb_Markly_Parser_enable, 1);
|
1180
1196
|
rb_define_method(rb_Markly_Parser, "parse", rb_Markly_Parser_parse, 1);
|
1181
|
-
rb_define_method(rb_Markly_Parser, "root", rb_Markly_Parser_root, 0);
|
1182
1197
|
|
1183
1198
|
rb_Markly_Node = rb_define_class_under(rb_Markly, "Node", rb_cObject);
|
1184
1199
|
rb_define_singleton_method(rb_Markly_Node, "new", rb_node_new, 1);
|
1200
|
+
|
1201
|
+
rb_define_method(rb_Markly_Node, "replace", rb_node_replace, 1);
|
1202
|
+
|
1185
1203
|
rb_define_method(rb_Markly_Node, "string_content", rb_node_get_string_content, 0);
|
1186
1204
|
rb_define_method(rb_Markly_Node, "string_content=", rb_node_set_string_content, 1);
|
1187
1205
|
rb_define_method(rb_Markly_Node, "type", rb_node_get_type, 0);
|
Binary file
|
data/lib/markly/node.rb
CHANGED
@@ -1,15 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'cgi'
|
4
|
+
|
3
5
|
module Markly
|
4
|
-
class
|
6
|
+
class HTMLRenderer < Renderer
|
7
|
+
def initialize(ids: false, **options)
|
8
|
+
super(**options)
|
9
|
+
|
10
|
+
@ids = ids
|
11
|
+
end
|
12
|
+
|
5
13
|
def document(_)
|
6
14
|
super
|
7
15
|
out("</ol>\n</section>\n") if @written_footnote_ix
|
8
16
|
end
|
9
17
|
|
18
|
+
def id_for(node)
|
19
|
+
if @ids
|
20
|
+
id = node.to_plaintext.chomp.downcase.gsub(/\s+/, '-')
|
21
|
+
|
22
|
+
return " id=\"#{CGI.escape_html id}\""
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
10
26
|
def header(node)
|
11
27
|
block do
|
12
|
-
out('<h', node.header_level, "#{source_position(node)}>", :children,
|
28
|
+
out('<h', node.header_level, "#{id_for(node)}#{source_position(node)}>", :children,
|
13
29
|
'</h', node.header_level, '>')
|
14
30
|
end
|
15
31
|
end
|
@@ -249,4 +265,7 @@ module Markly
|
|
249
265
|
node.tasklist_item_checked?
|
250
266
|
end
|
251
267
|
end
|
268
|
+
|
269
|
+
# Legacy.
|
270
|
+
HtmlRenderer = HTMLRenderer
|
252
271
|
end
|
data/lib/markly/version.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: markly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garen Torikian
|
8
8
|
- Ashe Connor
|
9
9
|
- Samuel Williams
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-
|
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
|
@@ -96,8 +68,8 @@ dependencies:
|
|
96
68
|
- - "~>"
|
97
69
|
- !ruby/object:Gem::Version
|
98
70
|
version: '0.9'
|
99
|
-
description:
|
100
|
-
email:
|
71
|
+
description:
|
72
|
+
email:
|
101
73
|
executables:
|
102
74
|
- markly
|
103
75
|
extensions:
|
@@ -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.
|
153
|
+
- lib/markly/markly.bundle
|
182
154
|
- lib/markly/node.rb
|
183
155
|
- lib/markly/node/inspect.rb
|
184
156
|
- lib/markly/renderer.rb
|
@@ -189,7 +161,7 @@ licenses:
|
|
189
161
|
- MIT
|
190
162
|
metadata:
|
191
163
|
funding_uri: https://github.com/sponsors/ioquatix/
|
192
|
-
post_install_message:
|
164
|
+
post_install_message:
|
193
165
|
rdoc_options: []
|
194
166
|
require_paths:
|
195
167
|
- lib
|
@@ -205,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
205
177
|
version: '0'
|
206
178
|
requirements: []
|
207
179
|
rubygems_version: 3.1.2
|
208
|
-
signing_key:
|
180
|
+
signing_key:
|
209
181
|
specification_version: 4
|
210
182
|
summary: CommonMark parser and renderer. Written in C, wrapped in Ruby.
|
211
183
|
test_files: []
|
data/lib/markly/markly.so
DELETED
Binary file
|