piko-fast-lib 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +7 -0
  2. data/piko-fast-lib.gemspec +11 -0
  3. data/redcarpet-3.6.1/CHANGELOG.md +487 -0
  4. data/redcarpet-3.6.1/CONTRIBUTING.md +33 -0
  5. data/redcarpet-3.6.1/COPYING +20 -0
  6. data/redcarpet-3.6.1/Gemfile +9 -0
  7. data/redcarpet-3.6.1/README.markdown +405 -0
  8. data/redcarpet-3.6.1/Rakefile +60 -0
  9. data/redcarpet-3.6.1/bin/redcarpet +7 -0
  10. data/redcarpet-3.6.1/ext/redcarpet/autolink.c +308 -0
  11. data/redcarpet-3.6.1/ext/redcarpet/autolink.h +55 -0
  12. data/redcarpet-3.6.1/ext/redcarpet/buffer.c +203 -0
  13. data/redcarpet-3.6.1/ext/redcarpet/buffer.h +88 -0
  14. data/redcarpet-3.6.1/ext/redcarpet/extconf.rb +6 -0
  15. data/redcarpet-3.6.1/ext/redcarpet/houdini.h +51 -0
  16. data/redcarpet-3.6.1/ext/redcarpet/houdini_href_e.c +124 -0
  17. data/redcarpet-3.6.1/ext/redcarpet/houdini_html_e.c +104 -0
  18. data/redcarpet-3.6.1/ext/redcarpet/html.c +869 -0
  19. data/redcarpet-3.6.1/ext/redcarpet/html.h +83 -0
  20. data/redcarpet-3.6.1/ext/redcarpet/html_block_names.txt +44 -0
  21. data/redcarpet-3.6.1/ext/redcarpet/html_blocks.h +222 -0
  22. data/redcarpet-3.6.1/ext/redcarpet/html_smartypants.c +472 -0
  23. data/redcarpet-3.6.1/ext/redcarpet/markdown.c +2946 -0
  24. data/redcarpet-3.6.1/ext/redcarpet/markdown.h +143 -0
  25. data/redcarpet-3.6.1/ext/redcarpet/rc_markdown.c +194 -0
  26. data/redcarpet-3.6.1/ext/redcarpet/rc_render.c +601 -0
  27. data/redcarpet-3.6.1/ext/redcarpet/redcarpet.h +54 -0
  28. data/redcarpet-3.6.1/ext/redcarpet/stack.c +84 -0
  29. data/redcarpet-3.6.1/ext/redcarpet/stack.h +48 -0
  30. data/redcarpet-3.6.1/lib/redcarpet/cli.rb +86 -0
  31. data/redcarpet-3.6.1/lib/redcarpet/compat.rb +71 -0
  32. data/redcarpet-3.6.1/lib/redcarpet/render_man.rb +65 -0
  33. data/redcarpet-3.6.1/lib/redcarpet/render_strip.rb +60 -0
  34. data/redcarpet-3.6.1/lib/redcarpet.rb +92 -0
  35. data/redcarpet-3.6.1/redcarpet.gemspec +59 -0
  36. metadata +74 -0
@@ -0,0 +1,601 @@
1
+ /*
2
+ * Copyright (c) 2015, Vicent Marti
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ * THE SOFTWARE.
21
+ */
22
+
23
+ #include "redcarpet.h"
24
+
25
+ #define SPAN_CALLBACK(method_name, ...) {\
26
+ struct redcarpet_renderopt *opt = opaque;\
27
+ VALUE ret = rb_funcall(opt->self, rb_intern(method_name), __VA_ARGS__);\
28
+ if (NIL_P(ret)) return 0;\
29
+ Check_Type(ret, T_STRING);\
30
+ bufput(ob, RSTRING_PTR(ret), RSTRING_LEN(ret));\
31
+ return 1;\
32
+ }
33
+
34
+ #define BLOCK_CALLBACK(method_name, ...) {\
35
+ struct redcarpet_renderopt *opt = opaque;\
36
+ VALUE ret = rb_funcall(opt->self, rb_intern(method_name), __VA_ARGS__);\
37
+ if (NIL_P(ret)) return;\
38
+ Check_Type(ret, T_STRING);\
39
+ bufput(ob, RSTRING_PTR(ret), RSTRING_LEN(ret));\
40
+ }
41
+
42
+ extern VALUE rb_mRedcarpet;
43
+ extern VALUE rb_cRenderHTML_TOC;
44
+ VALUE rb_mRender;
45
+ VALUE rb_cRenderBase;
46
+ VALUE rb_cRenderHTML;
47
+ VALUE rb_mSmartyPants;
48
+
49
+ #define buf2str(t) ((t) ? rb_enc_str_new((const char*)(t)->data, (t)->size, opt->active_enc) : Qnil)
50
+
51
+ static void
52
+ rndr_blockcode(struct buf *ob, const struct buf *text, const struct buf *lang, void *opaque)
53
+ {
54
+ BLOCK_CALLBACK("block_code", 2, buf2str(text), buf2str(lang));
55
+ }
56
+
57
+ static void
58
+ rndr_blockquote(struct buf *ob, const struct buf *text, void *opaque)
59
+ {
60
+ BLOCK_CALLBACK("block_quote", 1, buf2str(text));
61
+ }
62
+
63
+ static void
64
+ rndr_raw_block(struct buf *ob, const struct buf *text, void *opaque)
65
+ {
66
+ BLOCK_CALLBACK("block_html", 1, buf2str(text));
67
+ }
68
+
69
+ static void
70
+ rndr_header(struct buf *ob, const struct buf *text, int level, void *opaque)
71
+ {
72
+ BLOCK_CALLBACK("header", 2, buf2str(text), INT2FIX(level));
73
+ }
74
+
75
+ static void
76
+ rndr_hrule(struct buf *ob, void *opaque)
77
+ {
78
+ BLOCK_CALLBACK("hrule", 0);
79
+ }
80
+
81
+ static void
82
+ rndr_list(struct buf *ob, const struct buf *text, int flags, void *opaque)
83
+ {
84
+ BLOCK_CALLBACK("list", 2, buf2str(text),
85
+ (flags & MKD_LIST_ORDERED) ? CSTR2SYM("ordered") : CSTR2SYM("unordered"));
86
+ }
87
+
88
+ static void
89
+ rndr_listitem(struct buf *ob, const struct buf *text, int flags, void *opaque)
90
+ {
91
+ BLOCK_CALLBACK("list_item", 2, buf2str(text),
92
+ (flags & MKD_LIST_ORDERED) ? CSTR2SYM("ordered") : CSTR2SYM("unordered"));
93
+ }
94
+
95
+ static void
96
+ rndr_paragraph(struct buf *ob, const struct buf *text, void *opaque)
97
+ {
98
+ BLOCK_CALLBACK("paragraph", 1, buf2str(text));
99
+ }
100
+
101
+ static void
102
+ rndr_table(struct buf *ob, const struct buf *header, const struct buf *body, void *opaque)
103
+ {
104
+ BLOCK_CALLBACK("table", 2, buf2str(header), buf2str(body));
105
+ }
106
+
107
+ static void
108
+ rndr_tablerow(struct buf *ob, const struct buf *text, void *opaque)
109
+ {
110
+ BLOCK_CALLBACK("table_row", 1, buf2str(text));
111
+ }
112
+
113
+ static void
114
+ rndr_tablecell(struct buf *ob, const struct buf *text, int align, void *opaque)
115
+ {
116
+ VALUE rb_align, rb_header;
117
+ VALUE rb_callback, rb_callback_arity;
118
+
119
+ switch (align & MKD_TABLE_ALIGNMASK) {
120
+ case MKD_TABLE_ALIGN_L:
121
+ rb_align = CSTR2SYM("left");
122
+ break;
123
+
124
+ case MKD_TABLE_ALIGN_R:
125
+ rb_align = CSTR2SYM("right");
126
+ break;
127
+
128
+ case MKD_TABLE_ALIGN_CENTER:
129
+ rb_align = CSTR2SYM("center");
130
+ break;
131
+
132
+ default:
133
+ rb_align = Qnil;
134
+ break;
135
+ }
136
+
137
+ if (align & MKD_TABLE_HEADER) {
138
+ rb_header = Qtrue;
139
+ } else {
140
+ rb_header = Qfalse;
141
+ }
142
+
143
+ struct redcarpet_renderopt *opt = opaque;
144
+
145
+ rb_callback = rb_funcall(opt->self, rb_intern("method"), 1, CSTR2SYM("table_cell"));
146
+
147
+ rb_callback_arity = rb_funcall(rb_callback, rb_intern("arity"), 0);
148
+
149
+ /* For backward compatibility, let's ensure that the erasure with
150
+ only two parameters is still supported. */
151
+ if (FIX2INT(rb_callback_arity) == 3) {
152
+ BLOCK_CALLBACK("table_cell", 3, buf2str(text), rb_align, rb_header);
153
+ } else {
154
+ BLOCK_CALLBACK("table_cell", 2, buf2str(text), rb_align);
155
+ }
156
+ }
157
+
158
+ static void
159
+ rndr_footnotes(struct buf *ob, const struct buf *text, void *opaque)
160
+ {
161
+ BLOCK_CALLBACK("footnotes", 1, buf2str(text));
162
+ }
163
+
164
+ static void
165
+ rndr_footnote_def(struct buf *ob, const struct buf *text, unsigned int num, void *opaque)
166
+ {
167
+ BLOCK_CALLBACK("footnote_def", 2, buf2str(text), INT2FIX(num));
168
+ }
169
+
170
+
171
+ /***
172
+ * SPAN LEVEL
173
+ */
174
+ static int
175
+ rndr_autolink(struct buf *ob, const struct buf *link, enum mkd_autolink type, void *opaque)
176
+ {
177
+ SPAN_CALLBACK("autolink", 2, buf2str(link),
178
+ type == MKDA_NORMAL ? CSTR2SYM("url") : CSTR2SYM("email"));
179
+ }
180
+
181
+ static int
182
+ rndr_codespan(struct buf *ob, const struct buf *text, void *opaque)
183
+ {
184
+ SPAN_CALLBACK("codespan", 1, buf2str(text));
185
+ }
186
+
187
+ static int
188
+ rndr_double_emphasis(struct buf *ob, const struct buf *text, void *opaque)
189
+ {
190
+ SPAN_CALLBACK("double_emphasis", 1, buf2str(text));
191
+ }
192
+
193
+ static int
194
+ rndr_emphasis(struct buf *ob, const struct buf *text, void *opaque)
195
+ {
196
+ SPAN_CALLBACK("emphasis", 1, buf2str(text));
197
+ }
198
+
199
+ static int
200
+ rndr_underline(struct buf *ob, const struct buf *text, void *opaque)
201
+ {
202
+ SPAN_CALLBACK("underline", 1, buf2str(text));
203
+ }
204
+
205
+ static int
206
+ rndr_highlight(struct buf *ob, const struct buf *text, void *opaque)
207
+ {
208
+ SPAN_CALLBACK("highlight", 1, buf2str(text));
209
+ }
210
+
211
+ static int
212
+ rndr_quote(struct buf *ob, const struct buf *text, void *opaque)
213
+ {
214
+ SPAN_CALLBACK("quote", 1, buf2str(text));
215
+ }
216
+
217
+ static int
218
+ rndr_image(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *alt, void *opaque)
219
+ {
220
+ SPAN_CALLBACK("image", 3, buf2str(link), buf2str(title), buf2str(alt));
221
+ }
222
+
223
+ static int
224
+ rndr_linebreak(struct buf *ob, void *opaque)
225
+ {
226
+ SPAN_CALLBACK("linebreak", 0);
227
+ }
228
+
229
+ static int
230
+ rndr_link(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *content, void *opaque)
231
+ {
232
+ SPAN_CALLBACK("link", 3, buf2str(link), buf2str(title), buf2str(content));
233
+ }
234
+
235
+ static int
236
+ rndr_raw_html(struct buf *ob, const struct buf *text, void *opaque)
237
+ {
238
+ SPAN_CALLBACK("raw_html", 1, buf2str(text));
239
+ }
240
+
241
+ static int
242
+ rndr_triple_emphasis(struct buf *ob, const struct buf *text, void *opaque)
243
+ {
244
+ SPAN_CALLBACK("triple_emphasis", 1, buf2str(text));
245
+ }
246
+
247
+ static int
248
+ rndr_strikethrough(struct buf *ob, const struct buf *text, void *opaque)
249
+ {
250
+ SPAN_CALLBACK("strikethrough", 1, buf2str(text));
251
+ }
252
+
253
+ static int
254
+ rndr_superscript(struct buf *ob, const struct buf *text, void *opaque)
255
+ {
256
+ SPAN_CALLBACK("superscript", 1, buf2str(text));
257
+ }
258
+
259
+ static int
260
+ rndr_footnote_ref(struct buf *ob, unsigned int num, void *opaque)
261
+ {
262
+ SPAN_CALLBACK("footnote_ref", 1, INT2FIX(num));
263
+ }
264
+
265
+ /**
266
+ * direct writes
267
+ */
268
+ static void
269
+ rndr_entity(struct buf *ob, const struct buf *text, void *opaque)
270
+ {
271
+ BLOCK_CALLBACK("entity", 1, buf2str(text));
272
+ }
273
+
274
+ static void
275
+ rndr_normal_text(struct buf *ob, const struct buf *text, void *opaque)
276
+ {
277
+ BLOCK_CALLBACK("normal_text", 1, buf2str(text));
278
+ }
279
+
280
+ static void
281
+ rndr_doc_header(struct buf *ob, void *opaque)
282
+ {
283
+ BLOCK_CALLBACK("doc_header", 0);
284
+ }
285
+
286
+ static void
287
+ rndr_doc_footer(struct buf *ob, void *opaque)
288
+ {
289
+ BLOCK_CALLBACK("doc_footer", 0);
290
+ }
291
+
292
+ static int
293
+ cb_link_attribute(VALUE key, VALUE val, VALUE payload)
294
+ {
295
+ struct buf *ob = (struct buf *)payload;
296
+ key = rb_obj_as_string(key);
297
+ val = rb_obj_as_string(val);
298
+ bufprintf(ob, " %s=\"%s\"", StringValueCStr(key), StringValueCStr(val));
299
+ return 0;
300
+ }
301
+
302
+ static struct sd_callbacks rb_redcarpet_callbacks = {
303
+ rndr_blockcode,
304
+ rndr_blockquote,
305
+ rndr_raw_block,
306
+ rndr_header,
307
+ rndr_hrule,
308
+ rndr_list,
309
+ rndr_listitem,
310
+ rndr_paragraph,
311
+ rndr_table,
312
+ rndr_tablerow,
313
+ rndr_tablecell,
314
+ rndr_footnotes,
315
+ rndr_footnote_def,
316
+
317
+ rndr_autolink,
318
+ rndr_codespan,
319
+ rndr_double_emphasis,
320
+ rndr_emphasis,
321
+ rndr_underline,
322
+ rndr_highlight,
323
+ rndr_quote,
324
+ rndr_image,
325
+ rndr_linebreak,
326
+ rndr_link,
327
+ rndr_raw_html,
328
+ rndr_triple_emphasis,
329
+ rndr_strikethrough,
330
+ rndr_superscript,
331
+ rndr_footnote_ref,
332
+
333
+ rndr_entity,
334
+ rndr_normal_text,
335
+
336
+ rndr_doc_header,
337
+ rndr_doc_footer,
338
+ };
339
+
340
+ static const char *rb_redcarpet_method_names[] = {
341
+ "block_code",
342
+ "block_quote",
343
+ "block_html",
344
+ "header",
345
+ "hrule",
346
+ "list",
347
+ "list_item",
348
+ "paragraph",
349
+ "table",
350
+ "table_row",
351
+ "table_cell",
352
+ "footnotes",
353
+ "footnote_def",
354
+
355
+ "autolink",
356
+ "codespan",
357
+ "double_emphasis",
358
+ "emphasis",
359
+ "underline",
360
+ "highlight",
361
+ "quote",
362
+ "image",
363
+ "linebreak",
364
+ "link",
365
+ "raw_html",
366
+ "triple_emphasis",
367
+ "strikethrough",
368
+ "superscript",
369
+ "footnote_ref",
370
+
371
+ "entity",
372
+ "normal_text",
373
+
374
+ "doc_header",
375
+ "doc_footer"
376
+ };
377
+
378
+ static const size_t rb_redcarpet_method_count = sizeof(rb_redcarpet_method_names)/sizeof(char *);
379
+
380
+ static void rb_redcarpet_rbase_mark(void *data)
381
+ {
382
+ struct rb_redcarpet_rndr *rndr = (struct rb_redcarpet_rndr *)data;
383
+ if (rndr->options.link_attributes)
384
+ rb_gc_mark(rndr->options.link_attributes);
385
+ }
386
+
387
+ static const rb_data_type_t rb_redcarpet_rndr_type = {
388
+ "Redcarpet/rndr",
389
+ {
390
+ rb_redcarpet_rbase_mark,
391
+ RUBY_TYPED_DEFAULT_FREE,
392
+ },
393
+ 0,
394
+ 0,
395
+ RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
396
+ };
397
+
398
+ struct rb_redcarpet_rndr * rb_redcarpet_rndr_unwrap(VALUE self)
399
+ {
400
+ struct rb_redcarpet_rndr *rndr;
401
+ TypedData_Get_Struct(self, struct rb_redcarpet_rndr, &rb_redcarpet_rndr_type, rndr);
402
+ return rndr;
403
+ }
404
+
405
+ static VALUE rb_redcarpet_rbase_alloc(VALUE klass)
406
+ {
407
+ struct rb_redcarpet_rndr *rndr = ALLOC(struct rb_redcarpet_rndr);
408
+ memset(rndr, 0x0, sizeof(struct rb_redcarpet_rndr));
409
+ return TypedData_Wrap_Struct(klass, &rb_redcarpet_rndr_type, rndr);
410
+ }
411
+
412
+ static void
413
+ rndr_link_attributes(struct buf *ob, const struct buf *url, void *opaque)
414
+ {
415
+ struct redcarpet_renderopt *opt = opaque;
416
+ struct rb_redcarpet_rndr *rndr;
417
+
418
+ TypedData_Get_Struct(opt->self, struct rb_redcarpet_rndr, &rb_redcarpet_rndr_type, rndr);
419
+ Check_Type(opt->link_attributes, T_HASH);
420
+ rb_hash_foreach(opt->link_attributes, &cb_link_attribute, (VALUE)ob);
421
+ }
422
+
423
+ static void rb_redcarpet__overload(VALUE self, VALUE base_class)
424
+ {
425
+ struct rb_redcarpet_rndr *rndr;
426
+ VALUE options_ivar;
427
+
428
+ TypedData_Get_Struct(self, struct rb_redcarpet_rndr, &rb_redcarpet_rndr_type, rndr);
429
+ rndr->options.self = self;
430
+ rndr->options.base_class = base_class;
431
+
432
+ if (rb_obj_class(self) == rb_cRenderBase)
433
+ rb_raise(rb_eRuntimeError,
434
+ "The Redcarpet::Render::Base class cannot be instantiated. "
435
+ "Create an inheriting class instead to implement a custom renderer.");
436
+
437
+ if (rb_obj_class(self) != base_class) {
438
+ void **source = (void **)&rb_redcarpet_callbacks;
439
+ void **dest = (void **)&rndr->callbacks;
440
+ size_t i;
441
+
442
+ for (i = 0; i < rb_redcarpet_method_count; ++i) {
443
+ if (rb_respond_to(self, rb_intern(rb_redcarpet_method_names[i])))
444
+ dest[i] = source[i];
445
+ }
446
+ }
447
+
448
+ options_ivar = rb_attr_get(self, rb_intern("@options"));
449
+ if (options_ivar == Qundef || options_ivar == Qnil)
450
+ rb_iv_set(self, "@options", rb_hash_new());
451
+ }
452
+
453
+ static VALUE rb_redcarpet_rbase_init(VALUE self)
454
+ {
455
+ rb_redcarpet__overload(self, rb_cRenderBase);
456
+ return Qnil;
457
+ }
458
+
459
+ static VALUE rb_redcarpet_html_init(int argc, VALUE *argv, VALUE self)
460
+ {
461
+ struct rb_redcarpet_rndr *rndr;
462
+ unsigned int render_flags = 0;
463
+ VALUE hash, link_attr = Qnil;
464
+
465
+ TypedData_Get_Struct(self, struct rb_redcarpet_rndr, &rb_redcarpet_rndr_type, rndr);
466
+
467
+ if (rb_scan_args(argc, argv, "01", &hash) == 1) {
468
+ Check_Type(hash, T_HASH);
469
+
470
+ /* Give access to the passed options through `@options` */
471
+ rb_iv_set(self, "@options", hash);
472
+
473
+ /* escape_html */
474
+ if (rb_hash_aref(hash, CSTR2SYM("escape_html")) == Qtrue)
475
+ render_flags |= HTML_ESCAPE;
476
+
477
+ /* filter_html */
478
+ if (rb_hash_aref(hash, CSTR2SYM("filter_html")) == Qtrue)
479
+ render_flags |= HTML_SKIP_HTML;
480
+
481
+ /* no_image */
482
+ if (rb_hash_aref(hash, CSTR2SYM("no_images")) == Qtrue)
483
+ render_flags |= HTML_SKIP_IMAGES;
484
+
485
+ /* no_links */
486
+ if (rb_hash_aref(hash, CSTR2SYM("no_links")) == Qtrue)
487
+ render_flags |= HTML_SKIP_LINKS;
488
+
489
+ /* prettify */
490
+ if (rb_hash_aref(hash, CSTR2SYM("prettify")) == Qtrue)
491
+ render_flags |= HTML_PRETTIFY;
492
+
493
+ /* filter_style */
494
+ if (rb_hash_aref(hash, CSTR2SYM("no_styles")) == Qtrue)
495
+ render_flags |= HTML_SKIP_STYLE;
496
+
497
+ /* safelink */
498
+ if (rb_hash_aref(hash, CSTR2SYM("safe_links_only")) == Qtrue)
499
+ render_flags |= HTML_SAFELINK;
500
+
501
+ if (rb_hash_aref(hash, CSTR2SYM("with_toc_data")) == Qtrue)
502
+ render_flags |= HTML_TOC;
503
+
504
+ if (rb_hash_aref(hash, CSTR2SYM("hard_wrap")) == Qtrue)
505
+ render_flags |= HTML_HARD_WRAP;
506
+
507
+ if (rb_hash_aref(hash, CSTR2SYM("xhtml")) == Qtrue)
508
+ render_flags |= HTML_USE_XHTML;
509
+
510
+ link_attr = rb_hash_aref(hash, CSTR2SYM("link_attributes"));
511
+ }
512
+
513
+ sdhtml_renderer(&rndr->callbacks, (struct html_renderopt *)&rndr->options.html, render_flags);
514
+ rb_redcarpet__overload(self, rb_cRenderHTML);
515
+
516
+ if (!NIL_P(link_attr)) {
517
+ RB_OBJ_WRITE(self, &rndr->options.link_attributes, link_attr);
518
+ rndr->options.html.link_attributes = &rndr_link_attributes;
519
+ }
520
+
521
+ return Qnil;
522
+ }
523
+
524
+ static VALUE rb_redcarpet_htmltoc_init(int argc, VALUE *argv, VALUE self)
525
+ {
526
+ struct rb_redcarpet_rndr *rndr;
527
+ unsigned int render_flags = HTML_TOC;
528
+ VALUE hash, nesting_level = Qnil;
529
+
530
+ TypedData_Get_Struct(self, struct rb_redcarpet_rndr, &rb_redcarpet_rndr_type, rndr);
531
+
532
+ if (rb_scan_args(argc, argv, "01", &hash) == 1) {
533
+ Check_Type(hash, T_HASH);
534
+
535
+ /* Give access to the passed options through `@options` */
536
+ rb_iv_set(self, "@options", hash);
537
+
538
+ /* escape_html */
539
+ if (rb_hash_aref(hash, CSTR2SYM("escape_html")) == Qtrue)
540
+ render_flags |= HTML_ESCAPE;
541
+
542
+ /* Nesting level */
543
+ nesting_level = rb_hash_aref(hash, CSTR2SYM("nesting_level"));
544
+ }
545
+
546
+ sdhtml_toc_renderer(&rndr->callbacks, (struct html_renderopt *)&rndr->options.html, render_flags);
547
+ rb_redcarpet__overload(self, rb_cRenderHTML_TOC);
548
+
549
+ /* Check whether we are dealing with a Range object by
550
+ checking whether the object responds to min and max */
551
+ if (rb_respond_to(nesting_level, rb_intern("min")) &&
552
+ rb_respond_to(nesting_level, rb_intern("max"))) {
553
+ int min = NUM2INT(rb_funcall(nesting_level, rb_intern("min"), 0));
554
+ int max = NUM2INT(rb_funcall(nesting_level, rb_intern("max"), 0));
555
+
556
+ rndr->options.html.toc_data.nesting_bounds[0] = min;
557
+ rndr->options.html.toc_data.nesting_bounds[1] = max;
558
+ } else if (FIXNUM_P(nesting_level)) {
559
+ rndr->options.html.toc_data.nesting_bounds[0] = 1;
560
+ rndr->options.html.toc_data.nesting_bounds[1] = NUM2INT(nesting_level);
561
+ } else {
562
+ rndr->options.html.toc_data.nesting_bounds[0] = 1;
563
+ rndr->options.html.toc_data.nesting_bounds[1] = 6;
564
+ }
565
+
566
+ return Qnil;
567
+ }
568
+
569
+ static VALUE rb_redcarpet_smartypants_render(VALUE self, VALUE text)
570
+ {
571
+ VALUE result;
572
+ struct buf *output_buf;
573
+
574
+ Check_Type(text, T_STRING);
575
+
576
+ output_buf = bufnew(128);
577
+
578
+ sdhtml_smartypants(output_buf, (const uint8_t*)RSTRING_PTR(text), RSTRING_LEN(text));
579
+ result = rb_enc_str_new((const char*)output_buf->data, output_buf->size, rb_enc_get(text));
580
+
581
+ bufrelease(output_buf);
582
+ return result;
583
+ }
584
+
585
+ void Init_redcarpet_rndr()
586
+ {
587
+ rb_mRender = rb_define_module_under(rb_mRedcarpet, "Render");
588
+
589
+ rb_cRenderBase = rb_define_class_under(rb_mRender, "Base", rb_cObject);
590
+ rb_define_alloc_func(rb_cRenderBase, rb_redcarpet_rbase_alloc);
591
+ rb_define_method(rb_cRenderBase, "initialize", rb_redcarpet_rbase_init, 0);
592
+
593
+ rb_cRenderHTML = rb_define_class_under(rb_mRender, "HTML", rb_cRenderBase);
594
+ rb_define_method(rb_cRenderHTML, "initialize", rb_redcarpet_html_init, -1);
595
+
596
+ rb_cRenderHTML_TOC = rb_define_class_under(rb_mRender, "HTML_TOC", rb_cRenderBase);
597
+ rb_define_method(rb_cRenderHTML_TOC, "initialize", rb_redcarpet_htmltoc_init, -1);
598
+
599
+ rb_mSmartyPants = rb_define_module_under(rb_mRender, "SmartyPants");
600
+ rb_define_method(rb_mSmartyPants, "postprocess", rb_redcarpet_smartypants_render, 1);
601
+ }
@@ -0,0 +1,54 @@
1
+ /*
2
+ * Copyright (c) 2015, Vicent Marti
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ * THE SOFTWARE.
21
+ */
22
+
23
+ #ifndef REDCARPET_H__
24
+ #define REDCARPET_H__
25
+
26
+ #define RSTRING_NOT_MODIFIED
27
+ #include "ruby.h"
28
+ #include <stdio.h>
29
+
30
+ #include <ruby/encoding.h>
31
+
32
+ #include "markdown.h"
33
+ #include "html.h"
34
+
35
+ #define CSTR2SYM(s) (ID2SYM(rb_intern((s))))
36
+
37
+ void Init_redcarpet_rndr();
38
+
39
+ struct redcarpet_renderopt {
40
+ struct html_renderopt html;
41
+ VALUE link_attributes;
42
+ VALUE self;
43
+ VALUE base_class;
44
+ rb_encoding *active_enc;
45
+ };
46
+
47
+ struct rb_redcarpet_rndr {
48
+ struct sd_callbacks callbacks;
49
+ struct redcarpet_renderopt options;
50
+ };
51
+
52
+ struct rb_redcarpet_rndr * rb_redcarpet_rndr_unwrap(VALUE);
53
+
54
+ #endif