commonmarker 0.8.0 → 0.9.0

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 (38) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -1
  3. data/Rakefile +3 -3
  4. data/ext/commonmarker/cmark/build/CMakeCache.txt +8 -8
  5. data/ext/commonmarker/cmark/build/CMakeFiles/{3.5.1 → 3.5.2}/CMakeCCompiler.cmake +0 -0
  6. data/ext/commonmarker/cmark/build/CMakeFiles/{3.5.1 → 3.5.2}/CMakeCXXCompiler.cmake +0 -0
  7. data/ext/commonmarker/cmark/build/CMakeFiles/{3.5.1 → 3.5.2}/CMakeDetermineCompilerABI_C.bin +0 -0
  8. data/ext/commonmarker/cmark/build/CMakeFiles/{3.5.1 → 3.5.2}/CMakeDetermineCompilerABI_CXX.bin +0 -0
  9. data/ext/commonmarker/cmark/build/CMakeFiles/{3.5.1 → 3.5.2}/CMakeSystem.cmake +0 -0
  10. data/ext/commonmarker/cmark/build/CMakeFiles/{3.5.1 → 3.5.2}/CompilerIdC/CMakeCCompilerId.c +0 -0
  11. data/ext/commonmarker/cmark/build/CMakeFiles/{3.5.1 → 3.5.2}/CompilerIdC/a.out +0 -0
  12. data/ext/commonmarker/cmark/build/CMakeFiles/{3.5.1 → 3.5.2}/CompilerIdCXX/CMakeCXXCompilerId.cpp +0 -0
  13. data/ext/commonmarker/cmark/build/CMakeFiles/{3.5.1 → 3.5.2}/CompilerIdCXX/a.out +0 -0
  14. data/ext/commonmarker/cmark/build/CMakeFiles/CMakeError.log +6 -6
  15. data/ext/commonmarker/cmark/build/CMakeFiles/CMakeOutput.log +143 -143
  16. data/ext/commonmarker/cmark/build/CMakeFiles/Makefile.cmake +106 -106
  17. data/ext/commonmarker/cmark/build/CMakeFiles/Makefile2 +2 -2
  18. data/ext/commonmarker/cmark/build/Makefile +9 -9
  19. data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/build.make +2 -2
  20. data/ext/commonmarker/cmark/build/api_test/Makefile +9 -9
  21. data/ext/commonmarker/cmark/build/man/Makefile +9 -9
  22. data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/build.make +2 -2
  23. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/build.make +2 -2
  24. data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/build.make +2 -2
  25. data/ext/commonmarker/cmark/build/src/Makefile +9 -9
  26. data/ext/commonmarker/cmark/build/src/libcmark.a +0 -0
  27. data/ext/commonmarker/cmark/build/testdir/Makefile +9 -9
  28. data/ext/commonmarker/commonmarker.c +579 -662
  29. data/ext/commonmarker/commonmarker.c.orig +1041 -0
  30. data/ext/commonmarker/commonmarker.h +1 -1
  31. data/lib/commonmarker.rb +1 -32
  32. data/lib/commonmarker/node.rb +45 -0
  33. data/lib/commonmarker/renderer.rb +2 -2
  34. data/lib/commonmarker/version.rb +1 -1
  35. data/test/test_basics.rb +1 -40
  36. data/test/test_node.rb +78 -0
  37. data/test/test_renderer.rb +13 -0
  38. metadata +17 -11
@@ -34,10 +34,10 @@ cmake_force:
34
34
  SHELL = /bin/sh
35
35
 
36
36
  # The CMake executable.
37
- CMAKE_COMMAND = /usr/local/Cellar/cmake/3.5.1/bin/cmake
37
+ CMAKE_COMMAND = /usr/local/Cellar/cmake/3.5.2/bin/cmake
38
38
 
39
39
  # The command to remove a file.
40
- RM = /usr/local/Cellar/cmake/3.5.1/bin/cmake -E remove -f
40
+ RM = /usr/local/Cellar/cmake/3.5.2/bin/cmake -E remove -f
41
41
 
42
42
  # Escaping for special characters.
43
43
  EQUALS = =
@@ -34,10 +34,10 @@ cmake_force:
34
34
  SHELL = /bin/sh
35
35
 
36
36
  # The CMake executable.
37
- CMAKE_COMMAND = /usr/local/Cellar/cmake/3.5.1/bin/cmake
37
+ CMAKE_COMMAND = /usr/local/Cellar/cmake/3.5.2/bin/cmake
38
38
 
39
39
  # The command to remove a file.
40
- RM = /usr/local/Cellar/cmake/3.5.1/bin/cmake -E remove -f
40
+ RM = /usr/local/Cellar/cmake/3.5.2/bin/cmake -E remove -f
41
41
 
42
42
  # Escaping for special characters.
43
43
  EQUALS = =
@@ -34,10 +34,10 @@ cmake_force:
34
34
  SHELL = /bin/sh
35
35
 
36
36
  # The CMake executable.
37
- CMAKE_COMMAND = /usr/local/Cellar/cmake/3.5.1/bin/cmake
37
+ CMAKE_COMMAND = /usr/local/Cellar/cmake/3.5.2/bin/cmake
38
38
 
39
39
  # The command to remove a file.
40
- RM = /usr/local/Cellar/cmake/3.5.1/bin/cmake -E remove -f
40
+ RM = /usr/local/Cellar/cmake/3.5.2/bin/cmake -E remove -f
41
41
 
42
42
  # Escaping for special characters.
43
43
  EQUALS = =
@@ -39,10 +39,10 @@ cmake_force:
39
39
  SHELL = /bin/sh
40
40
 
41
41
  # The CMake executable.
42
- CMAKE_COMMAND = /usr/local/Cellar/cmake/3.5.1/bin/cmake
42
+ CMAKE_COMMAND = /usr/local/Cellar/cmake/3.5.2/bin/cmake
43
43
 
44
44
  # The command to remove a file.
45
- RM = /usr/local/Cellar/cmake/3.5.1/bin/cmake -E remove -f
45
+ RM = /usr/local/Cellar/cmake/3.5.2/bin/cmake -E remove -f
46
46
 
47
47
  # Escaping for special characters.
48
48
  EQUALS = =
@@ -59,7 +59,7 @@ CMAKE_BINARY_DIR = /Users/gjtorikian/Development/commonmarker/ext/commonmarker/c
59
59
  # Special rule for the target test
60
60
  test:
61
61
  @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running tests..."
62
- /usr/local/Cellar/cmake/3.5.1/bin/ctest --force-new-ctest-process $(ARGS)
62
+ /usr/local/Cellar/cmake/3.5.2/bin/ctest --force-new-ctest-process $(ARGS)
63
63
  .PHONY : test
64
64
 
65
65
  # Special rule for the target test
@@ -70,7 +70,7 @@ test/fast: test
70
70
  # Special rule for the target install/local
71
71
  install/local: preinstall
72
72
  @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..."
73
- /usr/local/Cellar/cmake/3.5.1/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake
73
+ /usr/local/Cellar/cmake/3.5.2/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake
74
74
  .PHONY : install/local
75
75
 
76
76
  # Special rule for the target install/local
@@ -91,19 +91,19 @@ list_install_components/fast: list_install_components
91
91
  # Special rule for the target install
92
92
  install: preinstall
93
93
  @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
94
- /usr/local/Cellar/cmake/3.5.1/bin/cmake -P cmake_install.cmake
94
+ /usr/local/Cellar/cmake/3.5.2/bin/cmake -P cmake_install.cmake
95
95
  .PHONY : install
96
96
 
97
97
  # Special rule for the target install
98
98
  install/fast: preinstall/fast
99
99
  @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
100
- /usr/local/Cellar/cmake/3.5.1/bin/cmake -P cmake_install.cmake
100
+ /usr/local/Cellar/cmake/3.5.2/bin/cmake -P cmake_install.cmake
101
101
  .PHONY : install/fast
102
102
 
103
103
  # Special rule for the target install/strip
104
104
  install/strip: preinstall
105
105
  @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..."
106
- /usr/local/Cellar/cmake/3.5.1/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake
106
+ /usr/local/Cellar/cmake/3.5.2/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake
107
107
  .PHONY : install/strip
108
108
 
109
109
  # Special rule for the target install/strip
@@ -114,7 +114,7 @@ install/strip/fast: install/strip
114
114
  # Special rule for the target rebuild_cache
115
115
  rebuild_cache:
116
116
  @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
117
- /usr/local/Cellar/cmake/3.5.1/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
117
+ /usr/local/Cellar/cmake/3.5.2/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
118
118
  .PHONY : rebuild_cache
119
119
 
120
120
  # Special rule for the target rebuild_cache
@@ -125,7 +125,7 @@ rebuild_cache/fast: rebuild_cache
125
125
  # Special rule for the target edit_cache
126
126
  edit_cache:
127
127
  @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
128
- /usr/local/Cellar/cmake/3.5.1/bin/ccmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
128
+ /usr/local/Cellar/cmake/3.5.2/bin/ccmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
129
129
  .PHONY : edit_cache
130
130
 
131
131
  # Special rule for the target edit_cache
@@ -39,10 +39,10 @@ cmake_force:
39
39
  SHELL = /bin/sh
40
40
 
41
41
  # The CMake executable.
42
- CMAKE_COMMAND = /usr/local/Cellar/cmake/3.5.1/bin/cmake
42
+ CMAKE_COMMAND = /usr/local/Cellar/cmake/3.5.2/bin/cmake
43
43
 
44
44
  # The command to remove a file.
45
- RM = /usr/local/Cellar/cmake/3.5.1/bin/cmake -E remove -f
45
+ RM = /usr/local/Cellar/cmake/3.5.2/bin/cmake -E remove -f
46
46
 
47
47
  # Escaping for special characters.
48
48
  EQUALS = =
@@ -59,7 +59,7 @@ CMAKE_BINARY_DIR = /Users/gjtorikian/Development/commonmarker/ext/commonmarker/c
59
59
  # Special rule for the target test
60
60
  test:
61
61
  @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running tests..."
62
- /usr/local/Cellar/cmake/3.5.1/bin/ctest --force-new-ctest-process $(ARGS)
62
+ /usr/local/Cellar/cmake/3.5.2/bin/ctest --force-new-ctest-process $(ARGS)
63
63
  .PHONY : test
64
64
 
65
65
  # Special rule for the target test
@@ -70,7 +70,7 @@ test/fast: test
70
70
  # Special rule for the target install/local
71
71
  install/local: preinstall
72
72
  @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..."
73
- /usr/local/Cellar/cmake/3.5.1/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake
73
+ /usr/local/Cellar/cmake/3.5.2/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake
74
74
  .PHONY : install/local
75
75
 
76
76
  # Special rule for the target install/local
@@ -81,7 +81,7 @@ install/local/fast: install/local
81
81
  # Special rule for the target edit_cache
82
82
  edit_cache:
83
83
  @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
84
- /usr/local/Cellar/cmake/3.5.1/bin/ccmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
84
+ /usr/local/Cellar/cmake/3.5.2/bin/ccmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
85
85
  .PHONY : edit_cache
86
86
 
87
87
  # Special rule for the target edit_cache
@@ -92,7 +92,7 @@ edit_cache/fast: edit_cache
92
92
  # Special rule for the target rebuild_cache
93
93
  rebuild_cache:
94
94
  @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
95
- /usr/local/Cellar/cmake/3.5.1/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
95
+ /usr/local/Cellar/cmake/3.5.2/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
96
96
  .PHONY : rebuild_cache
97
97
 
98
98
  # Special rule for the target rebuild_cache
@@ -113,19 +113,19 @@ list_install_components/fast: list_install_components
113
113
  # Special rule for the target install
114
114
  install: preinstall
115
115
  @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
116
- /usr/local/Cellar/cmake/3.5.1/bin/cmake -P cmake_install.cmake
116
+ /usr/local/Cellar/cmake/3.5.2/bin/cmake -P cmake_install.cmake
117
117
  .PHONY : install
118
118
 
119
119
  # Special rule for the target install
120
120
  install/fast: preinstall/fast
121
121
  @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
122
- /usr/local/Cellar/cmake/3.5.1/bin/cmake -P cmake_install.cmake
122
+ /usr/local/Cellar/cmake/3.5.2/bin/cmake -P cmake_install.cmake
123
123
  .PHONY : install/fast
124
124
 
125
125
  # Special rule for the target install/strip
126
126
  install/strip: preinstall
127
127
  @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..."
128
- /usr/local/Cellar/cmake/3.5.1/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake
128
+ /usr/local/Cellar/cmake/3.5.2/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake
129
129
  .PHONY : install/strip
130
130
 
131
131
  # Special rule for the target install/strip
@@ -1,7 +1,7 @@
1
1
  #include "commonmarker.h"
2
2
  #include "cmark.h"
3
- #include "node.h"
4
3
  #include "houdini.h"
4
+ #include "node.h"
5
5
 
6
6
  static VALUE rb_mNodeError;
7
7
  static VALUE rb_mNode;
@@ -28,110 +28,92 @@ static VALUE sym_image;
28
28
  static VALUE sym_bullet_list;
29
29
  static VALUE sym_ordered_list;
30
30
 
31
- static void
32
- rb_mark_c_struct(void *data)
33
- {
34
- cmark_node *node = data;
35
- cmark_node *child;
36
-
37
- /* Mark the parent to make sure that the tree won't be freed as
38
- long as a child node is referenced. */
39
- cmark_node *parent = cmark_node_parent(node);
40
- if (parent) {
41
- void *user_data = cmark_node_get_user_data(parent);
42
- if (!user_data) {
43
- /* This should never happen. Child can nodes can only
44
- be returned from parents that already are
45
- associated with a Ruby object. */
46
- fprintf(stderr, "parent without user_data\n");
47
- abort();
48
- }
49
- rb_gc_mark((VALUE)user_data);
50
- }
51
-
52
- /* Mark all children to make sure their cached Ruby objects won't
53
- be freed. */
54
- for (child = cmark_node_first_child(node);
55
- child != NULL;
56
- child = cmark_node_next(child)
57
- ) {
58
- void *user_data = cmark_node_get_user_data(child);
59
- if (user_data)
60
- rb_gc_mark((VALUE)user_data);
61
- }
62
- }
63
-
64
- static void
65
- rb_free_c_struct(void *data)
66
- {
67
- /* It's important that the `free` function does not inspect the
68
- node data, as it may be part of a tree that was already freed. */
69
- cmark_node_free(data);
70
- }
71
-
72
- static VALUE
73
- rb_node_to_value(cmark_node *node)
74
- {
75
- void *user_data;
76
- RUBY_DATA_FUNC free_func;
77
- VALUE val;
78
-
79
- if (node == NULL)
80
- return Qnil;
81
-
82
- user_data = cmark_node_get_user_data(node);
83
- if (user_data)
84
- return (VALUE)user_data;
85
-
86
- /* Only free tree roots. */
87
- free_func = cmark_node_parent(node)
88
- ? NULL
89
- : rb_free_c_struct;
90
- val = Data_Wrap_Struct(rb_mNode, rb_mark_c_struct, free_func,
91
- node);
92
- cmark_node_set_user_data(node, (void *)val);
93
-
94
- return val;
31
+ static void rb_mark_c_struct(void *data) {
32
+ cmark_node *node = data;
33
+ cmark_node *child;
34
+
35
+ /* Mark the parent to make sure that the tree won't be freed as
36
+ long as a child node is referenced. */
37
+ cmark_node *parent = cmark_node_parent(node);
38
+ if (parent) {
39
+ void *user_data = cmark_node_get_user_data(parent);
40
+ if (!user_data) {
41
+ /* This should never happen. Child can nodes can only
42
+ be returned from parents that already are
43
+ associated with a Ruby object. */
44
+ fprintf(stderr, "parent without user_data\n");
45
+ abort();
46
+ }
47
+ rb_gc_mark((VALUE)user_data);
48
+ }
49
+
50
+ /* Mark all children to make sure their cached Ruby objects won't
51
+ be freed. */
52
+ for (child = cmark_node_first_child(node); child != NULL;
53
+ child = cmark_node_next(child)) {
54
+ void *user_data = cmark_node_get_user_data(child);
55
+ if (user_data)
56
+ rb_gc_mark((VALUE)user_data);
57
+ }
58
+ }
59
+
60
+ static void rb_free_c_struct(void *data) {
61
+ /* It's important that the `free` function does not inspect the
62
+ node data, as it may be part of a tree that was already freed. */
63
+ cmark_node_free(data);
64
+ }
65
+
66
+ static VALUE rb_node_to_value(cmark_node *node) {
67
+ void *user_data;
68
+ RUBY_DATA_FUNC free_func;
69
+ VALUE val;
70
+
71
+ if (node == NULL)
72
+ return Qnil;
73
+
74
+ user_data = cmark_node_get_user_data(node);
75
+ if (user_data)
76
+ return (VALUE)user_data;
77
+
78
+ /* Only free tree roots. */
79
+ free_func = cmark_node_parent(node) ? NULL : rb_free_c_struct;
80
+ val = Data_Wrap_Struct(rb_mNode, rb_mark_c_struct, free_func, node);
81
+ cmark_node_set_user_data(node, (void *)val);
82
+
83
+ return val;
95
84
  }
96
85
 
97
86
  /* If the node structure is changed, the finalizers must be updated. */
98
87
 
99
- static void
100
- rb_parent_added(VALUE val)
101
- {
102
- RDATA(val)->dfree = NULL;
103
- }
88
+ static void rb_parent_added(VALUE val) { RDATA(val)->dfree = NULL; }
104
89
 
105
- static void
106
- rb_parent_removed(VALUE val)
107
- {
108
- RDATA(val)->dfree = rb_free_c_struct;
90
+ static void rb_parent_removed(VALUE val) {
91
+ RDATA(val)->dfree = rb_free_c_struct;
109
92
  }
110
93
 
111
94
  /*
112
95
  * Internal: Parses a Markdown string into an HTML string.
113
96
  *
114
97
  */
115
- static VALUE
116
- rb_markdown_to_html(VALUE self, VALUE rb_text, VALUE rb_options)
117
- {
118
- char *str;
119
- int len, options;
98
+ static VALUE rb_markdown_to_html(VALUE self, VALUE rb_text, VALUE rb_options) {
99
+ char *str;
100
+ int len, options;
120
101
 
121
- Check_Type(rb_text, T_STRING);
122
- Check_Type(rb_options, T_FIXNUM);
102
+ Check_Type(rb_text, T_STRING);
103
+ Check_Type(rb_options, T_FIXNUM);
123
104
 
124
- str = (char *)RSTRING_PTR(rb_text);
125
- len = RSTRING_LEN(rb_text);
126
- options = FIX2INT(rb_options);
105
+ str = (char *)RSTRING_PTR(rb_text);
106
+ len = RSTRING_LEN(rb_text);
107
+ options = FIX2INT(rb_options);
127
108
 
128
- return rb_str_new2(cmark_markdown_to_html(str, len, options));
109
+ return rb_str_new2(cmark_markdown_to_html(str, len, options));
129
110
  }
130
111
 
131
112
  /*
132
113
  * Internal: Creates a node based on a node type.
133
114
  *
134
- * type - A {Symbol} representing the node to be created. Must be one of the following:
115
+ * type - A {Symbol} representing the node to be created. Must be one of the
116
+ * following:
135
117
  * - `:document`
136
118
  * - `:blockquote`
137
119
  * - `:list`
@@ -151,85 +133,82 @@ rb_markdown_to_html(VALUE self, VALUE rb_text, VALUE rb_options)
151
133
  * - `:link`
152
134
  * - `:image`
153
135
  */
154
- static VALUE
155
- rb_node_new(VALUE self, VALUE type)
156
- {
157
- cmark_node_type node_type = 0;
158
- cmark_node *node;
159
-
160
- Check_Type(type, T_SYMBOL);
161
-
162
- if (type == sym_document)
163
- node_type = CMARK_NODE_DOCUMENT;
164
- else if (type == sym_blockquote)
165
- node_type = CMARK_NODE_BLOCK_QUOTE;
166
- else if (type == sym_list)
167
- node_type = CMARK_NODE_LIST;
168
- else if (type == sym_list_item)
169
- node_type = CMARK_NODE_ITEM;
170
- else if (type == sym_code_block)
171
- node_type = CMARK_NODE_CODE_BLOCK;
172
- else if (type == sym_html)
173
- node_type = CMARK_NODE_HTML;
174
- else if (type == sym_paragraph)
175
- node_type = CMARK_NODE_PARAGRAPH;
176
- else if (type == sym_header)
177
- node_type = CMARK_NODE_HEADER;
178
- else if (type == sym_hrule)
179
- node_type = CMARK_NODE_HRULE;
180
- else if (type == sym_text)
181
- node_type = CMARK_NODE_TEXT;
182
- else if (type == sym_softbreak)
183
- node_type = CMARK_NODE_SOFTBREAK;
184
- else if (type == sym_linebreak)
185
- node_type = CMARK_NODE_LINEBREAK;
186
- else if (type == sym_code)
187
- node_type = CMARK_NODE_CODE;
188
- else if (type == sym_inline_html)
189
- node_type = CMARK_NODE_INLINE_HTML;
190
- else if (type == sym_emph)
191
- node_type = CMARK_NODE_EMPH;
192
- else if (type == sym_strong)
193
- node_type = CMARK_NODE_STRONG;
194
- else if (type == sym_link)
195
- node_type = CMARK_NODE_LINK;
196
- else if (type == sym_image)
197
- node_type = CMARK_NODE_IMAGE;
198
- else
199
- rb_raise(rb_mNodeError, "invalid node of type %d", node_type);
200
-
201
- node = cmark_node_new(node_type);
202
- if (node == NULL) {
203
- rb_raise(rb_mNodeError, "could not create node of type %d", node_type);
204
- }
205
-
206
- return rb_node_to_value(node);
136
+ static VALUE rb_node_new(VALUE self, VALUE type) {
137
+ cmark_node_type node_type = 0;
138
+ cmark_node *node;
139
+
140
+ Check_Type(type, T_SYMBOL);
141
+
142
+ if (type == sym_document)
143
+ node_type = CMARK_NODE_DOCUMENT;
144
+ else if (type == sym_blockquote)
145
+ node_type = CMARK_NODE_BLOCK_QUOTE;
146
+ else if (type == sym_list)
147
+ node_type = CMARK_NODE_LIST;
148
+ else if (type == sym_list_item)
149
+ node_type = CMARK_NODE_ITEM;
150
+ else if (type == sym_code_block)
151
+ node_type = CMARK_NODE_CODE_BLOCK;
152
+ else if (type == sym_html)
153
+ node_type = CMARK_NODE_HTML;
154
+ else if (type == sym_paragraph)
155
+ node_type = CMARK_NODE_PARAGRAPH;
156
+ else if (type == sym_header)
157
+ node_type = CMARK_NODE_HEADER;
158
+ else if (type == sym_hrule)
159
+ node_type = CMARK_NODE_HRULE;
160
+ else if (type == sym_text)
161
+ node_type = CMARK_NODE_TEXT;
162
+ else if (type == sym_softbreak)
163
+ node_type = CMARK_NODE_SOFTBREAK;
164
+ else if (type == sym_linebreak)
165
+ node_type = CMARK_NODE_LINEBREAK;
166
+ else if (type == sym_code)
167
+ node_type = CMARK_NODE_CODE;
168
+ else if (type == sym_inline_html)
169
+ node_type = CMARK_NODE_INLINE_HTML;
170
+ else if (type == sym_emph)
171
+ node_type = CMARK_NODE_EMPH;
172
+ else if (type == sym_strong)
173
+ node_type = CMARK_NODE_STRONG;
174
+ else if (type == sym_link)
175
+ node_type = CMARK_NODE_LINK;
176
+ else if (type == sym_image)
177
+ node_type = CMARK_NODE_IMAGE;
178
+ else
179
+ rb_raise(rb_mNodeError, "invalid node of type %d", node_type);
180
+
181
+ node = cmark_node_new(node_type);
182
+ if (node == NULL) {
183
+ rb_raise(rb_mNodeError, "could not create node of type %d", node_type);
184
+ }
185
+
186
+ return rb_node_to_value(node);
207
187
  }
208
188
 
209
189
  /*
210
190
  * Internal: Parses a Markdown string into a document.
211
191
  *
212
192
  */
213
- static VALUE
214
- rb_parse_document(VALUE self, VALUE rb_text, VALUE rb_len, VALUE rb_options)
215
- {
216
- char *text;
217
- int len, options;
218
- cmark_node *doc;
219
- Check_Type(rb_text, T_STRING);
220
- Check_Type(rb_len, T_FIXNUM);
221
- Check_Type(rb_options, T_FIXNUM);
222
-
223
- text = (char *)RSTRING_PTR(rb_text);
224
- len = FIX2INT(rb_len);
225
- options = FIX2INT(rb_options);
226
-
227
- doc = cmark_parse_document(text, len, options);
228
- if (doc == NULL) {
229
- rb_raise(rb_mNodeError, "error parsing document");
230
- }
231
-
232
- return rb_node_to_value(doc);
193
+ static VALUE rb_parse_document(VALUE self, VALUE rb_text, VALUE rb_len,
194
+ VALUE rb_options) {
195
+ char *text;
196
+ int len, options;
197
+ cmark_node *doc;
198
+ Check_Type(rb_text, T_STRING);
199
+ Check_Type(rb_len, T_FIXNUM);
200
+ Check_Type(rb_options, T_FIXNUM);
201
+
202
+ text = (char *)RSTRING_PTR(rb_text);
203
+ len = FIX2INT(rb_len);
204
+ options = FIX2INT(rb_options);
205
+
206
+ doc = cmark_parse_document(text, len, options);
207
+ if (doc == NULL) {
208
+ rb_raise(rb_mNodeError, "error parsing document");
209
+ }
210
+
211
+ return rb_node_to_value(doc);
233
212
  }
234
213
 
235
214
  /*
@@ -237,19 +216,17 @@ rb_parse_document(VALUE self, VALUE rb_text, VALUE rb_len, VALUE rb_options)
237
216
  *
238
217
  * Returns a {String}.
239
218
  */
240
- static VALUE
241
- rb_node_get_string_content(VALUE self)
242
- {
243
- const char *text;
244
- cmark_node *node;
245
- Data_Get_Struct(self, cmark_node, node);
246
-
247
- text = cmark_node_get_literal(node);
248
- if (text == NULL) {
249
- rb_raise(rb_mNodeError, "could not get string content");
250
- }
251
-
252
- return rb_str_new2(text);
219
+ static VALUE rb_node_get_string_content(VALUE self) {
220
+ const char *text;
221
+ cmark_node *node;
222
+ Data_Get_Struct(self, cmark_node, node);
223
+
224
+ text = cmark_node_get_literal(node);
225
+ if (text == NULL) {
226
+ rb_raise(rb_mNodeError, "could not get string content");
227
+ }
228
+
229
+ return rb_str_new2(text);
253
230
  }
254
231
 
255
232
  /*
@@ -259,21 +236,19 @@ rb_node_get_string_content(VALUE self)
259
236
  *
260
237
  * Raises NodeError if the string content can't be set.
261
238
  */
262
- static VALUE
263
- rb_node_set_string_content(VALUE self, VALUE s)
264
- {
265
- char *text;
266
- cmark_node *node;
267
- Check_Type(s, T_STRING);
239
+ static VALUE rb_node_set_string_content(VALUE self, VALUE s) {
240
+ char *text;
241
+ cmark_node *node;
242
+ Check_Type(s, T_STRING);
268
243
 
269
- Data_Get_Struct(self, cmark_node, node);
270
- text = StringValueCStr(s);
244
+ Data_Get_Struct(self, cmark_node, node);
245
+ text = StringValueCStr(s);
271
246
 
272
- if (!cmark_node_set_literal(node, text)) {
273
- rb_raise(rb_mNodeError, "could not set string content");
274
- }
247
+ if (!cmark_node_set_literal(node, text)) {
248
+ rb_raise(rb_mNodeError, "could not set string content");
249
+ }
275
250
 
276
- return Qnil;
251
+ return Qnil;
277
252
  }
278
253
 
279
254
  /*
@@ -281,78 +256,76 @@ rb_node_set_string_content(VALUE self, VALUE s)
281
256
  *
282
257
  * Returns a {Symbol} representing the node's type.
283
258
  */
284
- static VALUE
285
- rb_node_get_type(VALUE self)
286
- {
287
- int node_type;
288
- cmark_node *node;
289
- VALUE symbol;
290
-
291
- Data_Get_Struct(self, cmark_node, node);
292
-
293
- node_type = cmark_node_get_type(node);
294
- symbol = Qnil;
295
-
296
- switch (node_type) {
297
- case CMARK_NODE_DOCUMENT:
298
- symbol = sym_document;
299
- break;
300
- case CMARK_NODE_BLOCK_QUOTE:
301
- symbol = sym_blockquote;
302
- break;
303
- case CMARK_NODE_LIST:
304
- symbol = sym_list;
305
- break;
306
- case CMARK_NODE_ITEM:
307
- symbol = sym_list_item;
308
- break;
309
- case CMARK_NODE_CODE_BLOCK:
310
- symbol = sym_code_block;
311
- break;
312
- case CMARK_NODE_HTML:
313
- symbol = sym_html;
314
- break;
315
- case CMARK_NODE_PARAGRAPH:
316
- symbol = sym_paragraph;
317
- break;
318
- case CMARK_NODE_HEADER:
319
- symbol = sym_header;
320
- break;
321
- case CMARK_NODE_HRULE:
322
- symbol = sym_hrule;
323
- break;
324
- case CMARK_NODE_TEXT:
325
- symbol = sym_text;
326
- break;
327
- case CMARK_NODE_SOFTBREAK:
328
- symbol = sym_softbreak;
329
- break;
330
- case CMARK_NODE_LINEBREAK:
331
- symbol = sym_linebreak;
332
- break;
333
- case CMARK_NODE_CODE:
334
- symbol = sym_code;
335
- break;
336
- case CMARK_NODE_INLINE_HTML:
337
- symbol = sym_inline_html;
338
- break;
339
- case CMARK_NODE_EMPH:
340
- symbol = sym_emph;
341
- break;
342
- case CMARK_NODE_STRONG:
343
- symbol = sym_strong;
344
- break;
345
- case CMARK_NODE_LINK:
346
- symbol = sym_link;
347
- break;
348
- case CMARK_NODE_IMAGE:
349
- symbol = sym_image;
350
- break;
351
- default:
352
- rb_raise(rb_mNodeError, "invalid node type %d", node_type);
353
- }
354
-
355
- return symbol;
259
+ static VALUE rb_node_get_type(VALUE self) {
260
+ int node_type;
261
+ cmark_node *node;
262
+ VALUE symbol;
263
+
264
+ Data_Get_Struct(self, cmark_node, node);
265
+
266
+ node_type = cmark_node_get_type(node);
267
+ symbol = Qnil;
268
+
269
+ switch (node_type) {
270
+ case CMARK_NODE_DOCUMENT:
271
+ symbol = sym_document;
272
+ break;
273
+ case CMARK_NODE_BLOCK_QUOTE:
274
+ symbol = sym_blockquote;
275
+ break;
276
+ case CMARK_NODE_LIST:
277
+ symbol = sym_list;
278
+ break;
279
+ case CMARK_NODE_ITEM:
280
+ symbol = sym_list_item;
281
+ break;
282
+ case CMARK_NODE_CODE_BLOCK:
283
+ symbol = sym_code_block;
284
+ break;
285
+ case CMARK_NODE_HTML:
286
+ symbol = sym_html;
287
+ break;
288
+ case CMARK_NODE_PARAGRAPH:
289
+ symbol = sym_paragraph;
290
+ break;
291
+ case CMARK_NODE_HEADER:
292
+ symbol = sym_header;
293
+ break;
294
+ case CMARK_NODE_HRULE:
295
+ symbol = sym_hrule;
296
+ break;
297
+ case CMARK_NODE_TEXT:
298
+ symbol = sym_text;
299
+ break;
300
+ case CMARK_NODE_SOFTBREAK:
301
+ symbol = sym_softbreak;
302
+ break;
303
+ case CMARK_NODE_LINEBREAK:
304
+ symbol = sym_linebreak;
305
+ break;
306
+ case CMARK_NODE_CODE:
307
+ symbol = sym_code;
308
+ break;
309
+ case CMARK_NODE_INLINE_HTML:
310
+ symbol = sym_inline_html;
311
+ break;
312
+ case CMARK_NODE_EMPH:
313
+ symbol = sym_emph;
314
+ break;
315
+ case CMARK_NODE_STRONG:
316
+ symbol = sym_strong;
317
+ break;
318
+ case CMARK_NODE_LINK:
319
+ symbol = sym_link;
320
+ break;
321
+ case CMARK_NODE_IMAGE:
322
+ symbol = sym_image;
323
+ break;
324
+ default:
325
+ rb_raise(rb_mNodeError, "invalid node type %d", node_type);
326
+ }
327
+
328
+ return symbol;
356
329
  }
357
330
 
358
331
  /*
@@ -360,27 +333,25 @@ rb_node_get_type(VALUE self)
360
333
  *
361
334
  * Returns a {Hash} containing {Symbol} keys of the positions.
362
335
  */
363
- static VALUE
364
- rb_node_get_sourcepos(VALUE self)
365
- {
366
- int start_line, start_column, end_line, end_column;
367
- VALUE result;
368
-
369
- cmark_node *node;
370
- Data_Get_Struct(self, cmark_node, node);
371
-
372
- start_line = cmark_node_get_start_line(node);
373
- start_column = cmark_node_get_start_column(node);
374
- end_line = cmark_node_get_end_line(node);
375
- end_column = cmark_node_get_end_column(node);
376
-
377
- result = rb_hash_new();
378
- rb_hash_aset(result, CSTR2SYM("start_line"), INT2NUM(start_line));
379
- rb_hash_aset(result, CSTR2SYM("start_column"), INT2NUM(start_column));
380
- rb_hash_aset(result, CSTR2SYM("end_line"), INT2NUM(end_line));
381
- rb_hash_aset(result, CSTR2SYM("end_column"), INT2NUM(end_column));
382
-
383
- return result;
336
+ static VALUE rb_node_get_sourcepos(VALUE self) {
337
+ int start_line, start_column, end_line, end_column;
338
+ VALUE result;
339
+
340
+ cmark_node *node;
341
+ Data_Get_Struct(self, cmark_node, node);
342
+
343
+ start_line = cmark_node_get_start_line(node);
344
+ start_column = cmark_node_get_start_column(node);
345
+ end_line = cmark_node_get_end_line(node);
346
+ end_column = cmark_node_get_end_column(node);
347
+
348
+ result = rb_hash_new();
349
+ rb_hash_aset(result, CSTR2SYM("start_line"), INT2NUM(start_line));
350
+ rb_hash_aset(result, CSTR2SYM("start_column"), INT2NUM(start_column));
351
+ rb_hash_aset(result, CSTR2SYM("end_line"), INT2NUM(end_line));
352
+ rb_hash_aset(result, CSTR2SYM("end_column"), INT2NUM(end_column));
353
+
354
+ return result;
384
355
  }
385
356
 
386
357
  /*
@@ -388,60 +359,52 @@ rb_node_get_sourcepos(VALUE self)
388
359
  *
389
360
  * Returns a {String}.
390
361
  */
391
- static VALUE
392
- rb_node_get_type_string(VALUE self)
393
- {
394
- cmark_node *node;
395
- Data_Get_Struct(self, cmark_node, node);
362
+ static VALUE rb_node_get_type_string(VALUE self) {
363
+ cmark_node *node;
364
+ Data_Get_Struct(self, cmark_node, node);
396
365
 
397
- return rb_str_new2(cmark_node_get_type_string(node));
366
+ return rb_str_new2(cmark_node_get_type_string(node));
398
367
  }
399
368
 
400
369
  /*
401
370
  * Internal: Unlinks the node from the tree (fixing pointers in
402
371
  * parents and siblings appropriately).
403
372
  */
404
- static VALUE
405
- rb_node_unlink(VALUE self)
406
- {
407
- cmark_node *node;
408
- Data_Get_Struct(self, cmark_node, node);
373
+ static VALUE rb_node_unlink(VALUE self) {
374
+ cmark_node *node;
375
+ Data_Get_Struct(self, cmark_node, node);
409
376
 
410
- cmark_node_unlink(node);
377
+ cmark_node_unlink(node);
411
378
 
412
- rb_parent_removed(self);
379
+ rb_parent_removed(self);
413
380
 
414
- return Qnil;
381
+ return Qnil;
415
382
  }
416
383
 
417
384
  /* Public: Fetches the first child of the node.
418
385
  *
419
386
  * Returns a {Node} if a child exists, `nil` otherise.
420
387
  */
421
- static VALUE
422
- rb_node_first_child(VALUE self)
423
- {
424
- cmark_node *node, *child;
425
- Data_Get_Struct(self, cmark_node, node);
388
+ static VALUE rb_node_first_child(VALUE self) {
389
+ cmark_node *node, *child;
390
+ Data_Get_Struct(self, cmark_node, node);
426
391
 
427
- child = cmark_node_first_child(node);
392
+ child = cmark_node_first_child(node);
428
393
 
429
- return rb_node_to_value(child);
394
+ return rb_node_to_value(child);
430
395
  }
431
396
 
432
397
  /* Public: Fetches the next sibling of the node.
433
398
  *
434
399
  * Returns a {Node} if a sibling exists, `nil` otherwise.
435
400
  */
436
- static VALUE
437
- rb_node_next(VALUE self)
438
- {
439
- cmark_node *node, *next;
440
- Data_Get_Struct(self, cmark_node, node);
401
+ static VALUE rb_node_next(VALUE self) {
402
+ cmark_node *node, *next;
403
+ Data_Get_Struct(self, cmark_node, node);
441
404
 
442
- next = cmark_node_next(node);
405
+ next = cmark_node_next(node);
443
406
 
444
- return rb_node_to_value(next);
407
+ return rb_node_to_value(next);
445
408
  }
446
409
 
447
410
  /*
@@ -452,39 +415,35 @@ rb_node_next(VALUE self)
452
415
  * Returns `true` if successful.
453
416
  * Raises NodeError if the node can't be inserted.
454
417
  */
455
- static VALUE
456
- rb_node_insert_before(VALUE self, VALUE sibling)
457
- {
458
- cmark_node *node1, *node2;
459
- Data_Get_Struct(self, cmark_node, node1);
418
+ static VALUE rb_node_insert_before(VALUE self, VALUE sibling) {
419
+ cmark_node *node1, *node2;
420
+ Data_Get_Struct(self, cmark_node, node1);
460
421
 
461
- Data_Get_Struct(sibling, cmark_node, node2);
422
+ Data_Get_Struct(sibling, cmark_node, node2);
462
423
 
463
- if (!cmark_node_insert_before(node1, node2)) {
464
- rb_raise(rb_mNodeError, "could not insert before");
465
- }
424
+ if (!cmark_node_insert_before(node1, node2)) {
425
+ rb_raise(rb_mNodeError, "could not insert before");
426
+ }
466
427
 
467
- rb_parent_added(sibling);
428
+ rb_parent_added(sibling);
468
429
 
469
- return Qtrue;
430
+ return Qtrue;
470
431
  }
471
432
 
472
433
  /* Internal: Convert the node to an HTML string.
473
434
  *
474
435
  * Returns a {String}.
475
436
  */
476
- static VALUE
477
- rb_render_html(VALUE n, VALUE rb_options)
478
- {
479
- int options;
480
- cmark_node *node;
481
- Check_Type(rb_options, T_FIXNUM);
437
+ static VALUE rb_render_html(VALUE n, VALUE rb_options) {
438
+ int options;
439
+ cmark_node *node;
440
+ Check_Type(rb_options, T_FIXNUM);
482
441
 
483
- options = FIX2INT(rb_options);
442
+ options = FIX2INT(rb_options);
484
443
 
485
- Data_Get_Struct(n, cmark_node, node);
444
+ Data_Get_Struct(n, cmark_node, node);
486
445
 
487
- return rb_str_new2(cmark_render_html(node, options));
446
+ return rb_str_new2(cmark_render_html(node, options));
488
447
  }
489
448
 
490
449
  /*
@@ -495,21 +454,19 @@ rb_render_html(VALUE n, VALUE rb_options)
495
454
  * Returns `true` if successful.
496
455
  * Raises NodeError if the node can't be inserted.
497
456
  */
498
- static VALUE
499
- rb_node_insert_after(VALUE self, VALUE sibling)
500
- {
501
- cmark_node *node1, *node2;
502
- Data_Get_Struct(self, cmark_node, node1);
457
+ static VALUE rb_node_insert_after(VALUE self, VALUE sibling) {
458
+ cmark_node *node1, *node2;
459
+ Data_Get_Struct(self, cmark_node, node1);
503
460
 
504
- Data_Get_Struct(sibling, cmark_node, node2);
461
+ Data_Get_Struct(sibling, cmark_node, node2);
505
462
 
506
- if (!cmark_node_insert_after(node1, node2)) {
507
- rb_raise(rb_mNodeError, "could not insert after");
508
- }
463
+ if (!cmark_node_insert_after(node1, node2)) {
464
+ rb_raise(rb_mNodeError, "could not insert after");
465
+ }
509
466
 
510
- rb_parent_added(sibling);
467
+ rb_parent_added(sibling);
511
468
 
512
- return Qtrue;
469
+ return Qtrue;
513
470
  }
514
471
 
515
472
  /*
@@ -520,21 +477,19 @@ rb_node_insert_after(VALUE self, VALUE sibling)
520
477
  * Returns `true` if successful.
521
478
  * Raises NodeError if the node can't be inserted.
522
479
  */
523
- static VALUE
524
- rb_node_prepend_child(VALUE self, VALUE child)
525
- {
526
- cmark_node *node1, *node2;
527
- Data_Get_Struct(self, cmark_node, node1);
480
+ static VALUE rb_node_prepend_child(VALUE self, VALUE child) {
481
+ cmark_node *node1, *node2;
482
+ Data_Get_Struct(self, cmark_node, node1);
528
483
 
529
- Data_Get_Struct(child, cmark_node, node2);
484
+ Data_Get_Struct(child, cmark_node, node2);
530
485
 
531
- if (!cmark_node_prepend_child(node1, node2)) {
532
- rb_raise(rb_mNodeError, "could not prepend child");
533
- }
486
+ if (!cmark_node_prepend_child(node1, node2)) {
487
+ rb_raise(rb_mNodeError, "could not prepend child");
488
+ }
534
489
 
535
- rb_parent_added(child);
490
+ rb_parent_added(child);
536
491
 
537
- return Qtrue;
492
+ return Qtrue;
538
493
  }
539
494
 
540
495
  /*
@@ -545,66 +500,58 @@ rb_node_prepend_child(VALUE self, VALUE child)
545
500
  * Returns `true` if successful.
546
501
  * Raises NodeError if the node can't be inserted.
547
502
  */
548
- static VALUE
549
- rb_node_append_child(VALUE self, VALUE child)
550
- {
551
- cmark_node *node1, *node2;
552
- Data_Get_Struct(self, cmark_node, node1);
503
+ static VALUE rb_node_append_child(VALUE self, VALUE child) {
504
+ cmark_node *node1, *node2;
505
+ Data_Get_Struct(self, cmark_node, node1);
553
506
 
554
- Data_Get_Struct(child, cmark_node, node2);
507
+ Data_Get_Struct(child, cmark_node, node2);
555
508
 
556
- if (!cmark_node_append_child(node1, node2)) {
557
- rb_raise(rb_mNodeError, "could not append child");
558
- }
509
+ if (!cmark_node_append_child(node1, node2)) {
510
+ rb_raise(rb_mNodeError, "could not append child");
511
+ }
559
512
 
560
- rb_parent_added(child);
513
+ rb_parent_added(child);
561
514
 
562
- return Qtrue;
515
+ return Qtrue;
563
516
  }
564
517
 
565
518
  /* Public: Fetches the first child of the current node.
566
519
  *
567
520
  * Returns a {Node} if a child exists, `nil` otherise.
568
521
  */
569
- static VALUE
570
- rb_node_last_child(VALUE self)
571
- {
572
- cmark_node *node, *child;
573
- Data_Get_Struct(self, cmark_node, node);
522
+ static VALUE rb_node_last_child(VALUE self) {
523
+ cmark_node *node, *child;
524
+ Data_Get_Struct(self, cmark_node, node);
574
525
 
575
- child = cmark_node_last_child(node);
526
+ child = cmark_node_last_child(node);
576
527
 
577
- return rb_node_to_value(child);
528
+ return rb_node_to_value(child);
578
529
  }
579
530
 
580
531
  /* Public: Fetches the parent of the current node.
581
532
  *
582
533
  * Returns a {Node} if a parent exists, `nil` otherise.
583
534
  */
584
- static VALUE
585
- rb_node_parent(VALUE self)
586
- {
587
- cmark_node *node, *parent;
588
- Data_Get_Struct(self, cmark_node, node);
535
+ static VALUE rb_node_parent(VALUE self) {
536
+ cmark_node *node, *parent;
537
+ Data_Get_Struct(self, cmark_node, node);
589
538
 
590
- parent = cmark_node_parent(node);
539
+ parent = cmark_node_parent(node);
591
540
 
592
- return rb_node_to_value(parent);
541
+ return rb_node_to_value(parent);
593
542
  }
594
543
 
595
544
  /* Public: Fetches the previous sibling of the current node.
596
545
  *
597
546
  * Returns a {Node} if a parent exists, `nil` otherise.
598
547
  */
599
- static VALUE
600
- rb_node_previous(VALUE self)
601
- {
602
- cmark_node *node, *previous;
603
- Data_Get_Struct(self, cmark_node, node);
548
+ static VALUE rb_node_previous(VALUE self) {
549
+ cmark_node *node, *previous;
550
+ Data_Get_Struct(self, cmark_node, node);
604
551
 
605
- previous = cmark_node_previous(node);
552
+ previous = cmark_node_previous(node);
606
553
 
607
- return rb_node_to_value(previous);
554
+ return rb_node_to_value(previous);
608
555
  }
609
556
 
610
557
  /*
@@ -613,19 +560,17 @@ rb_node_previous(VALUE self)
613
560
  * Returns a {String}.
614
561
  * Raises a NodeError if the URL can't be retrieved.
615
562
  */
616
- static VALUE
617
- rb_node_get_url(VALUE self)
618
- {
619
- const char *text;
620
- cmark_node *node;
621
- Data_Get_Struct(self, cmark_node, node);
622
-
623
- text = cmark_node_get_url(node);
624
- if (text == NULL) {
625
- rb_raise(rb_mNodeError, "could not get url");
626
- }
627
-
628
- return rb_str_new2(text);
563
+ static VALUE rb_node_get_url(VALUE self) {
564
+ const char *text;
565
+ cmark_node *node;
566
+ Data_Get_Struct(self, cmark_node, node);
567
+
568
+ text = cmark_node_get_url(node);
569
+ if (text == NULL) {
570
+ rb_raise(rb_mNodeError, "could not get url");
571
+ }
572
+
573
+ return rb_str_new2(text);
629
574
  }
630
575
 
631
576
  /*
@@ -635,21 +580,19 @@ rb_node_get_url(VALUE self)
635
580
  *
636
581
  * Raises a NodeError if the URL can't be set.
637
582
  */
638
- static VALUE
639
- rb_node_set_url(VALUE self, VALUE url)
640
- {
641
- cmark_node *node;
642
- char *text;
643
- Check_Type(url, T_STRING);
583
+ static VALUE rb_node_set_url(VALUE self, VALUE url) {
584
+ cmark_node *node;
585
+ char *text;
586
+ Check_Type(url, T_STRING);
644
587
 
645
- Data_Get_Struct(self, cmark_node, node);
646
- text = StringValueCStr(url);
588
+ Data_Get_Struct(self, cmark_node, node);
589
+ text = StringValueCStr(url);
647
590
 
648
- if (!cmark_node_set_url(node, text)) {
649
- rb_raise(rb_mNodeError, "could not set url");
650
- }
591
+ if (!cmark_node_set_url(node, text)) {
592
+ rb_raise(rb_mNodeError, "could not set url");
593
+ }
651
594
 
652
- return Qnil;
595
+ return Qnil;
653
596
  }
654
597
 
655
598
  /*
@@ -658,19 +601,17 @@ rb_node_set_url(VALUE self, VALUE url)
658
601
  * Returns a {String}.
659
602
  * Raises a NodeError if the title can't be retrieved.
660
603
  */
661
- static VALUE
662
- rb_node_get_title(VALUE self)
663
- {
664
- const char *text;
665
- cmark_node *node;
666
- Data_Get_Struct(self, cmark_node, node);
667
-
668
- text = cmark_node_get_title(node);
669
- if (text == NULL) {
670
- rb_raise(rb_mNodeError, "could not get title");
671
- }
672
-
673
- return rb_str_new2(text);
604
+ static VALUE rb_node_get_title(VALUE self) {
605
+ const char *text;
606
+ cmark_node *node;
607
+ Data_Get_Struct(self, cmark_node, node);
608
+
609
+ text = cmark_node_get_title(node);
610
+ if (text == NULL) {
611
+ rb_raise(rb_mNodeError, "could not get title");
612
+ }
613
+
614
+ return rb_str_new2(text);
674
615
  }
675
616
 
676
617
  /*
@@ -680,21 +621,19 @@ rb_node_get_title(VALUE self)
680
621
  *
681
622
  * Raises a NodeError if the title can't be set.
682
623
  */
683
- static VALUE
684
- rb_node_set_title(VALUE self, VALUE title)
685
- {
686
- char *text;
687
- cmark_node *node;
688
- Check_Type(title, T_STRING);
624
+ static VALUE rb_node_set_title(VALUE self, VALUE title) {
625
+ char *text;
626
+ cmark_node *node;
627
+ Check_Type(title, T_STRING);
689
628
 
690
- Data_Get_Struct(self, cmark_node, node);
691
- text = StringValueCStr(title);
629
+ Data_Get_Struct(self, cmark_node, node);
630
+ text = StringValueCStr(title);
692
631
 
693
- if (!cmark_node_set_title(node, text)) {
694
- rb_raise(rb_mNodeError, "could not set title");
695
- }
632
+ if (!cmark_node_set_title(node, text)) {
633
+ rb_raise(rb_mNodeError, "could not set title");
634
+ }
696
635
 
697
- return Qnil;
636
+ return Qnil;
698
637
  }
699
638
 
700
639
  /*
@@ -703,20 +642,18 @@ rb_node_set_title(VALUE self, VALUE title)
703
642
  * Returns a {Number} representing the header level.
704
643
  * Raises a NodeError if the header level can't be retrieved.
705
644
  */
706
- static VALUE
707
- rb_node_get_header_level(VALUE self)
708
- {
709
- int header_level;
710
- cmark_node *node;
711
- Data_Get_Struct(self, cmark_node, node);
645
+ static VALUE rb_node_get_header_level(VALUE self) {
646
+ int header_level;
647
+ cmark_node *node;
648
+ Data_Get_Struct(self, cmark_node, node);
712
649
 
713
- header_level = cmark_node_get_header_level(node);
650
+ header_level = cmark_node_get_header_level(node);
714
651
 
715
- if (header_level == 0) {
716
- rb_raise(rb_mNodeError, "could not get header_level");
717
- }
652
+ if (header_level == 0) {
653
+ rb_raise(rb_mNodeError, "could not get header_level");
654
+ }
718
655
 
719
- return INT2NUM(header_level);
656
+ return INT2NUM(header_level);
720
657
  }
721
658
 
722
659
  /*
@@ -726,21 +663,19 @@ rb_node_get_header_level(VALUE self)
726
663
  *
727
664
  * Raises a NodeError if the header level can't be set.
728
665
  */
729
- static VALUE
730
- rb_node_set_header_level(VALUE self, VALUE level)
731
- {
732
- int l;
733
- cmark_node *node;
734
- Check_Type(level, T_FIXNUM);
666
+ static VALUE rb_node_set_header_level(VALUE self, VALUE level) {
667
+ int l;
668
+ cmark_node *node;
669
+ Check_Type(level, T_FIXNUM);
735
670
 
736
- Data_Get_Struct(self, cmark_node, node);
737
- l = FIX2INT(level);
671
+ Data_Get_Struct(self, cmark_node, node);
672
+ l = FIX2INT(level);
738
673
 
739
- if (!cmark_node_set_header_level(node, l)) {
740
- rb_raise(rb_mNodeError, "could not set header_level");
741
- }
674
+ if (!cmark_node_set_header_level(node, l)) {
675
+ rb_raise(rb_mNodeError, "could not set header_level");
676
+ }
742
677
 
743
- return Qnil;
678
+ return Qnil;
744
679
  }
745
680
 
746
681
  /*
@@ -749,25 +684,23 @@ rb_node_set_header_level(VALUE self, VALUE level)
749
684
  * Returns a {Symbol}.
750
685
  * Raises a NodeError if the title can't be retrieved.
751
686
  */
752
- static VALUE
753
- rb_node_get_list_type(VALUE self)
754
- {
755
- int list_type;
756
- cmark_node *node;
757
- VALUE symbol;
758
- Data_Get_Struct(self, cmark_node, node);
759
-
760
- list_type = cmark_node_get_list_type(node);
761
-
762
- if (list_type == CMARK_BULLET_LIST) {
763
- symbol = sym_bullet_list;
764
- } else if (list_type == CMARK_ORDERED_LIST) {
765
- symbol = sym_ordered_list;
766
- } else {
767
- rb_raise(rb_mNodeError, "could not get list_type");
768
- }
769
-
770
- return symbol;
687
+ static VALUE rb_node_get_list_type(VALUE self) {
688
+ int list_type;
689
+ cmark_node *node;
690
+ VALUE symbol;
691
+ Data_Get_Struct(self, cmark_node, node);
692
+
693
+ list_type = cmark_node_get_list_type(node);
694
+
695
+ if (list_type == CMARK_BULLET_LIST) {
696
+ symbol = sym_bullet_list;
697
+ } else if (list_type == CMARK_ORDERED_LIST) {
698
+ symbol = sym_ordered_list;
699
+ } else {
700
+ rb_raise(rb_mNodeError, "could not get list_type");
701
+ }
702
+
703
+ return symbol;
771
704
  }
772
705
 
773
706
  /*
@@ -777,74 +710,69 @@ rb_node_get_list_type(VALUE self)
777
710
  *
778
711
  * Raises a NodeError if the list type can't be set.
779
712
  */
780
- static VALUE
781
- rb_node_set_list_type(VALUE self, VALUE list_type)
782
- {
783
- int type = 0;
784
- cmark_node *node;
785
- Check_Type(list_type, T_SYMBOL);
786
-
787
- Data_Get_Struct(self, cmark_node, node);
788
-
789
- if (list_type == sym_bullet_list) {
790
- type = CMARK_BULLET_LIST;
791
- } else if (list_type == sym_ordered_list) {
792
- type = CMARK_ORDERED_LIST;
793
- } else {
794
- rb_raise(rb_mNodeError, "invalid list_type");
795
- }
796
-
797
- if (!cmark_node_set_list_type(node, type)) {
798
- rb_raise(rb_mNodeError, "could not set list_type");
799
- }
800
-
801
- return Qnil;
713
+ static VALUE rb_node_set_list_type(VALUE self, VALUE list_type) {
714
+ int type = 0;
715
+ cmark_node *node;
716
+ Check_Type(list_type, T_SYMBOL);
717
+
718
+ Data_Get_Struct(self, cmark_node, node);
719
+
720
+ if (list_type == sym_bullet_list) {
721
+ type = CMARK_BULLET_LIST;
722
+ } else if (list_type == sym_ordered_list) {
723
+ type = CMARK_ORDERED_LIST;
724
+ } else {
725
+ rb_raise(rb_mNodeError, "invalid list_type");
726
+ }
727
+
728
+ if (!cmark_node_set_list_type(node, type)) {
729
+ rb_raise(rb_mNodeError, "could not set list_type");
730
+ }
731
+
732
+ return Qnil;
802
733
  }
803
734
 
804
735
  /*
805
- * Public: Gets the starting number the current node (must be an `:ordered_list`).
736
+ * Public: Gets the starting number the current node (must be an
737
+ * `:ordered_list`).
806
738
  *
807
739
  * Returns a {Number} representing the starting number.
808
740
  * Raises a NodeError if the starting number can't be retrieved.
809
741
  */
810
- static VALUE
811
- rb_node_get_list_start(VALUE self)
812
- {
813
- cmark_node *node;
814
- Data_Get_Struct(self, cmark_node, node);
815
-
816
- if (cmark_node_get_type(node) != CMARK_NODE_LIST
817
- || cmark_node_get_list_type(node) != CMARK_ORDERED_LIST) {
818
- rb_raise(rb_mNodeError,
819
- "can't get list_start for non-ordered list %d",
820
- cmark_node_get_list_type(node));
821
- }
822
-
823
- return INT2NUM(cmark_node_get_list_start(node));
742
+ static VALUE rb_node_get_list_start(VALUE self) {
743
+ cmark_node *node;
744
+ Data_Get_Struct(self, cmark_node, node);
745
+
746
+ if (cmark_node_get_type(node) != CMARK_NODE_LIST ||
747
+ cmark_node_get_list_type(node) != CMARK_ORDERED_LIST) {
748
+ rb_raise(rb_mNodeError, "can't get list_start for non-ordered list %d",
749
+ cmark_node_get_list_type(node));
750
+ }
751
+
752
+ return INT2NUM(cmark_node_get_list_start(node));
824
753
  }
825
754
 
826
755
  /*
827
- * Public: Sets the starting number of the current node (must be an `:ordered_list`).
756
+ * Public: Sets the starting number of the current node (must be an
757
+ * `:ordered_list`).
828
758
  *
829
759
  * level - A {Number} representing the new starting number
830
760
  *
831
761
  * Raises a NodeError if the starting number can't be set.
832
762
  */
833
- static VALUE
834
- rb_node_set_list_start(VALUE self, VALUE start)
835
- {
836
- int s;
837
- cmark_node *node;
838
- Check_Type(start, T_FIXNUM);
763
+ static VALUE rb_node_set_list_start(VALUE self, VALUE start) {
764
+ int s;
765
+ cmark_node *node;
766
+ Check_Type(start, T_FIXNUM);
839
767
 
840
- Data_Get_Struct(self, cmark_node, node);
841
- s = FIX2INT(start);
768
+ Data_Get_Struct(self, cmark_node, node);
769
+ s = FIX2INT(start);
842
770
 
843
- if (!cmark_node_set_list_start(node, s)) {
844
- rb_raise(rb_mNodeError, "could not set list_start");
845
- }
771
+ if (!cmark_node_set_list_start(node, s)) {
772
+ rb_raise(rb_mNodeError, "could not set list_start");
773
+ }
846
774
 
847
- return Qnil;
775
+ return Qnil;
848
776
  }
849
777
 
850
778
  /*
@@ -853,21 +781,18 @@ rb_node_set_list_start(VALUE self, VALUE start)
853
781
  * Returns a `true` if the list is tight, `false` otherwise.
854
782
  * Raises a NodeError if the starting number can't be retrieved.
855
783
  */
856
- static VALUE
857
- rb_node_get_list_tight(VALUE self)
858
- {
859
- int flag;
860
- cmark_node *node;
861
- Data_Get_Struct(self, cmark_node, node);
784
+ static VALUE rb_node_get_list_tight(VALUE self) {
785
+ int flag;
786
+ cmark_node *node;
787
+ Data_Get_Struct(self, cmark_node, node);
862
788
 
863
- if (cmark_node_get_type(node) != CMARK_NODE_LIST) {
864
- rb_raise(rb_mNodeError,
865
- "can't get list_tight for non-list");
866
- }
789
+ if (cmark_node_get_type(node) != CMARK_NODE_LIST) {
790
+ rb_raise(rb_mNodeError, "can't get list_tight for non-list");
791
+ }
867
792
 
868
- flag = cmark_node_get_list_tight(node);
793
+ flag = cmark_node_get_list_tight(node);
869
794
 
870
- return flag ? Qtrue : Qfalse;
795
+ return flag ? Qtrue : Qfalse;
871
796
  }
872
797
 
873
798
  /*
@@ -877,19 +802,17 @@ rb_node_get_list_tight(VALUE self)
877
802
  *
878
803
  * Raises a NodeError if the tightness can't be set.
879
804
  */
880
- static VALUE
881
- rb_node_set_list_tight(VALUE self, VALUE tight)
882
- {
883
- int t;
884
- cmark_node *node;
885
- Data_Get_Struct(self, cmark_node, node);
886
- t = RTEST(tight);
887
-
888
- if (!cmark_node_set_list_tight(node, t)) {
889
- rb_raise(rb_mNodeError, "could not set list_tight");
890
- }
891
-
892
- return Qnil;
805
+ static VALUE rb_node_set_list_tight(VALUE self, VALUE tight) {
806
+ int t;
807
+ cmark_node *node;
808
+ Data_Get_Struct(self, cmark_node, node);
809
+ t = RTEST(tight);
810
+
811
+ if (!cmark_node_set_list_tight(node, t)) {
812
+ rb_raise(rb_mNodeError, "could not set list_tight");
813
+ }
814
+
815
+ return Qnil;
893
816
  }
894
817
 
895
818
  /*
@@ -898,20 +821,18 @@ rb_node_set_list_tight(VALUE self, VALUE tight)
898
821
  * Returns a {String} representing the fence info.
899
822
  * Raises a NodeError if the fence info can't be retrieved.
900
823
  */
901
- static VALUE
902
- rb_node_get_fence_info(VALUE self)
903
- {
904
- const char *fence_info;
905
- cmark_node *node;
906
- Data_Get_Struct(self, cmark_node, node);
824
+ static VALUE rb_node_get_fence_info(VALUE self) {
825
+ const char *fence_info;
826
+ cmark_node *node;
827
+ Data_Get_Struct(self, cmark_node, node);
907
828
 
908
- fence_info = cmark_node_get_fence_info(node);
829
+ fence_info = cmark_node_get_fence_info(node);
909
830
 
910
- if (fence_info == NULL) {
911
- rb_raise(rb_mNodeError, "could not get fence_info");
912
- }
831
+ if (fence_info == NULL) {
832
+ rb_raise(rb_mNodeError, "could not get fence_info");
833
+ }
913
834
 
914
- return rb_str_new2(fence_info);
835
+ return rb_str_new2(fence_info);
915
836
  }
916
837
 
917
838
  /*
@@ -921,121 +842,117 @@ rb_node_get_fence_info(VALUE self)
921
842
  *
922
843
  * Raises a NodeError if the fence info can't be set.
923
844
  */
924
- static VALUE
925
- rb_node_set_fence_info(VALUE self, VALUE info)
926
- {
927
- char *text;
928
- cmark_node *node;
929
- Check_Type(info, T_STRING);
845
+ static VALUE rb_node_set_fence_info(VALUE self, VALUE info) {
846
+ char *text;
847
+ cmark_node *node;
848
+ Check_Type(info, T_STRING);
930
849
 
931
- Data_Get_Struct(self, cmark_node, node);
932
- text = StringValueCStr(info);
850
+ Data_Get_Struct(self, cmark_node, node);
851
+ text = StringValueCStr(info);
933
852
 
934
- if (!cmark_node_set_fence_info(node, text)) {
935
- rb_raise(rb_mNodeError, "could not set fence_info");
936
- }
853
+ if (!cmark_node_set_fence_info(node, text)) {
854
+ rb_raise(rb_mNodeError, "could not set fence_info");
855
+ }
937
856
 
938
- return Qnil;
857
+ return Qnil;
939
858
  }
940
859
 
941
860
  /* Internal: Escapes href URLs safely. */
942
- static VALUE
943
- rb_html_escape_href(VALUE self, VALUE rb_text)
944
- {
945
- char *result;
946
- cmark_strbuf buf = GH_BUF_INIT;
861
+ static VALUE rb_html_escape_href(VALUE self, VALUE rb_text) {
862
+ char *result;
863
+ cmark_strbuf buf = GH_BUF_INIT;
947
864
 
948
- Check_Type(rb_text, T_STRING);
865
+ Check_Type(rb_text, T_STRING);
949
866
 
950
- if (houdini_escape_href(&buf, (const uint8_t *)RSTRING_PTR(rb_text), RSTRING_LEN(rb_text))) {
951
- result = (char *)cmark_strbuf_detach(&buf);
952
- return rb_str_new2(result);
953
- }
954
-
955
- return rb_text;
867
+ if (houdini_escape_href(&buf, (const uint8_t *)RSTRING_PTR(rb_text),
868
+ RSTRING_LEN(rb_text))) {
869
+ result = (char *)cmark_strbuf_detach(&buf);
870
+ return rb_str_new2(result);
871
+ }
956
872
 
873
+ return rb_text;
957
874
  }
958
875
 
959
876
  /* Internal: Escapes HTML content safely. */
960
- static VALUE
961
- rb_html_escape_html(VALUE self, VALUE rb_text)
962
- {
963
- char *result;
964
- cmark_strbuf buf = GH_BUF_INIT;
965
-
966
- Check_Type(rb_text, T_STRING);
967
-
968
- if (houdini_escape_html0(&buf, (const uint8_t *)RSTRING_PTR(rb_text), RSTRING_LEN(rb_text), 0)) {
969
- result = (char *)cmark_strbuf_detach(&buf);
970
- return rb_str_new2(result);
971
- }
972
-
973
- return rb_text;
974
- }
975
-
976
- __attribute__((visibility("default")))
977
- void Init_commonmarker()
978
- {
979
- VALUE module;
980
- sym_document = ID2SYM(rb_intern("document"));
981
- sym_blockquote = ID2SYM(rb_intern("blockquote"));
982
- sym_list = ID2SYM(rb_intern("list"));
983
- sym_list_item = ID2SYM(rb_intern("list_item"));
984
- sym_code_block = ID2SYM(rb_intern("code_block"));
985
- sym_html = ID2SYM(rb_intern("html"));
986
- sym_paragraph = ID2SYM(rb_intern("paragraph"));
987
- sym_header = ID2SYM(rb_intern("header"));
988
- sym_hrule = ID2SYM(rb_intern("hrule"));
989
- sym_text = ID2SYM(rb_intern("text"));
990
- sym_softbreak = ID2SYM(rb_intern("softbreak"));
991
- sym_linebreak = ID2SYM(rb_intern("linebreak"));
992
- sym_code = ID2SYM(rb_intern("code"));
993
- sym_inline_html = ID2SYM(rb_intern("inline_html"));
994
- sym_emph = ID2SYM(rb_intern("emph"));
995
- sym_strong = ID2SYM(rb_intern("strong"));
996
- sym_link = ID2SYM(rb_intern("link"));
997
- sym_image = ID2SYM(rb_intern("image"));
998
-
999
- sym_bullet_list = ID2SYM(rb_intern("bullet_list"));
1000
- sym_ordered_list = ID2SYM(rb_intern("ordered_list"));
1001
-
1002
- module = rb_define_module("CommonMarker");
1003
- rb_mNodeError = rb_define_class_under(module, "NodeError", rb_eStandardError);
1004
- rb_mNode = rb_define_class_under(module, "Node", rb_cObject);
1005
- rb_define_singleton_method(rb_mNode, "markdown_to_html", rb_markdown_to_html, 2);
1006
- rb_define_singleton_method(rb_mNode, "new", rb_node_new, 1);
1007
- rb_define_singleton_method(rb_mNode, "parse_document", rb_parse_document, 3);
1008
- rb_define_method(rb_mNode, "string_content", rb_node_get_string_content, 0);
1009
- rb_define_method(rb_mNode, "string_content=", rb_node_set_string_content, 1);
1010
- rb_define_method(rb_mNode, "type", rb_node_get_type, 0);
1011
- rb_define_method(rb_mNode, "type_string", rb_node_get_type_string, 0);
1012
- rb_define_method(rb_mNode, "sourcepos", rb_node_get_sourcepos, 0);
1013
- rb_define_method(rb_mNode, "delete", rb_node_unlink, 0);
1014
- rb_define_method(rb_mNode, "first_child", rb_node_first_child, 0);
1015
- rb_define_method(rb_mNode, "next", rb_node_next, 0);
1016
- rb_define_method(rb_mNode, "insert_before", rb_node_insert_before, 1);
1017
- rb_define_method(rb_mNode, "_render_html", rb_render_html, 1);
1018
- rb_define_method(rb_mNode, "insert_after", rb_node_insert_after, 1);
1019
- rb_define_method(rb_mNode, "prepend_child", rb_node_prepend_child, 1);
1020
- rb_define_method(rb_mNode, "append_child", rb_node_append_child, 1);
1021
- rb_define_method(rb_mNode, "last_child", rb_node_last_child, 0);
1022
- rb_define_method(rb_mNode, "parent", rb_node_parent, 0);
1023
- rb_define_method(rb_mNode, "previous", rb_node_previous, 0);
1024
- rb_define_method(rb_mNode, "url", rb_node_get_url, 0);
1025
- rb_define_method(rb_mNode, "url=", rb_node_set_url, 1);
1026
- rb_define_method(rb_mNode, "title", rb_node_get_title, 0);
1027
- rb_define_method(rb_mNode, "title=", rb_node_set_title, 1);
1028
- rb_define_method(rb_mNode, "header_level", rb_node_get_header_level, 0);
1029
- rb_define_method(rb_mNode, "header_level=", rb_node_set_header_level, 1);
1030
- rb_define_method(rb_mNode, "list_type", rb_node_get_list_type, 0);
1031
- rb_define_method(rb_mNode, "list_type=", rb_node_set_list_type, 1);
1032
- rb_define_method(rb_mNode, "list_start", rb_node_get_list_start, 0);
1033
- rb_define_method(rb_mNode, "list_start=", rb_node_set_list_start, 1);
1034
- rb_define_method(rb_mNode, "list_tight", rb_node_get_list_tight, 0);
1035
- rb_define_method(rb_mNode, "list_tight=", rb_node_set_list_tight, 1);
1036
- rb_define_method(rb_mNode, "fence_info", rb_node_get_fence_info, 0);
1037
- rb_define_method(rb_mNode, "fence_info=", rb_node_set_fence_info, 1);
1038
-
1039
- rb_define_singleton_method(rb_mNode, "html_escape_href", rb_html_escape_href, 1);
1040
- rb_define_singleton_method(rb_mNode, "html_escape_html", rb_html_escape_html, 1);
877
+ static VALUE rb_html_escape_html(VALUE self, VALUE rb_text) {
878
+ char *result;
879
+ cmark_strbuf buf = GH_BUF_INIT;
880
+
881
+ Check_Type(rb_text, T_STRING);
882
+
883
+ if (houdini_escape_html0(&buf, (const uint8_t *)RSTRING_PTR(rb_text),
884
+ RSTRING_LEN(rb_text), 0)) {
885
+ result = (char *)cmark_strbuf_detach(&buf);
886
+ return rb_str_new2(result);
887
+ }
888
+
889
+ return rb_text;
890
+ }
891
+
892
+ __attribute__((visibility("default"))) void Init_commonmarker() {
893
+ VALUE module;
894
+ sym_document = ID2SYM(rb_intern("document"));
895
+ sym_blockquote = ID2SYM(rb_intern("blockquote"));
896
+ sym_list = ID2SYM(rb_intern("list"));
897
+ sym_list_item = ID2SYM(rb_intern("list_item"));
898
+ sym_code_block = ID2SYM(rb_intern("code_block"));
899
+ sym_html = ID2SYM(rb_intern("html"));
900
+ sym_paragraph = ID2SYM(rb_intern("paragraph"));
901
+ sym_header = ID2SYM(rb_intern("header"));
902
+ sym_hrule = ID2SYM(rb_intern("hrule"));
903
+ sym_text = ID2SYM(rb_intern("text"));
904
+ sym_softbreak = ID2SYM(rb_intern("softbreak"));
905
+ sym_linebreak = ID2SYM(rb_intern("linebreak"));
906
+ sym_code = ID2SYM(rb_intern("code"));
907
+ sym_inline_html = ID2SYM(rb_intern("inline_html"));
908
+ sym_emph = ID2SYM(rb_intern("emph"));
909
+ sym_strong = ID2SYM(rb_intern("strong"));
910
+ sym_link = ID2SYM(rb_intern("link"));
911
+ sym_image = ID2SYM(rb_intern("image"));
912
+
913
+ sym_bullet_list = ID2SYM(rb_intern("bullet_list"));
914
+ sym_ordered_list = ID2SYM(rb_intern("ordered_list"));
915
+
916
+ module = rb_define_module("CommonMarker");
917
+ rb_mNodeError = rb_define_class_under(module, "NodeError", rb_eStandardError);
918
+ rb_mNode = rb_define_class_under(module, "Node", rb_cObject);
919
+ rb_define_singleton_method(rb_mNode, "markdown_to_html", rb_markdown_to_html,
920
+ 2);
921
+ rb_define_singleton_method(rb_mNode, "new", rb_node_new, 1);
922
+ rb_define_singleton_method(rb_mNode, "parse_document", rb_parse_document, 3);
923
+ rb_define_method(rb_mNode, "string_content", rb_node_get_string_content, 0);
924
+ rb_define_method(rb_mNode, "string_content=", rb_node_set_string_content, 1);
925
+ rb_define_method(rb_mNode, "type", rb_node_get_type, 0);
926
+ rb_define_method(rb_mNode, "type_string", rb_node_get_type_string, 0);
927
+ rb_define_method(rb_mNode, "sourcepos", rb_node_get_sourcepos, 0);
928
+ rb_define_method(rb_mNode, "delete", rb_node_unlink, 0);
929
+ rb_define_method(rb_mNode, "first_child", rb_node_first_child, 0);
930
+ rb_define_method(rb_mNode, "next", rb_node_next, 0);
931
+ rb_define_method(rb_mNode, "insert_before", rb_node_insert_before, 1);
932
+ rb_define_method(rb_mNode, "_render_html", rb_render_html, 1);
933
+ rb_define_method(rb_mNode, "insert_after", rb_node_insert_after, 1);
934
+ rb_define_method(rb_mNode, "prepend_child", rb_node_prepend_child, 1);
935
+ rb_define_method(rb_mNode, "append_child", rb_node_append_child, 1);
936
+ rb_define_method(rb_mNode, "last_child", rb_node_last_child, 0);
937
+ rb_define_method(rb_mNode, "parent", rb_node_parent, 0);
938
+ rb_define_method(rb_mNode, "previous", rb_node_previous, 0);
939
+ rb_define_method(rb_mNode, "url", rb_node_get_url, 0);
940
+ rb_define_method(rb_mNode, "url=", rb_node_set_url, 1);
941
+ rb_define_method(rb_mNode, "title", rb_node_get_title, 0);
942
+ rb_define_method(rb_mNode, "title=", rb_node_set_title, 1);
943
+ rb_define_method(rb_mNode, "header_level", rb_node_get_header_level, 0);
944
+ rb_define_method(rb_mNode, "header_level=", rb_node_set_header_level, 1);
945
+ rb_define_method(rb_mNode, "list_type", rb_node_get_list_type, 0);
946
+ rb_define_method(rb_mNode, "list_type=", rb_node_set_list_type, 1);
947
+ rb_define_method(rb_mNode, "list_start", rb_node_get_list_start, 0);
948
+ rb_define_method(rb_mNode, "list_start=", rb_node_set_list_start, 1);
949
+ rb_define_method(rb_mNode, "list_tight", rb_node_get_list_tight, 0);
950
+ rb_define_method(rb_mNode, "list_tight=", rb_node_set_list_tight, 1);
951
+ rb_define_method(rb_mNode, "fence_info", rb_node_get_fence_info, 0);
952
+ rb_define_method(rb_mNode, "fence_info=", rb_node_set_fence_info, 1);
953
+
954
+ rb_define_singleton_method(rb_mNode, "html_escape_href", rb_html_escape_href,
955
+ 1);
956
+ rb_define_singleton_method(rb_mNode, "html_escape_html", rb_html_escape_html,
957
+ 1);
1041
958
  }