redcarpet 1.5.0 → 2.0.0
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.
- data/README.markdown +312 -20
- data/Rakefile +31 -36
- data/bin/redcarpet +1 -1
- data/ext/redcarpet/autolink.c +260 -0
- data/ext/{xhtml.h → redcarpet/autolink.h} +17 -24
- data/ext/redcarpet/buffer.c +229 -0
- data/ext/redcarpet/buffer.h +88 -0
- data/ext/redcarpet/houdini.h +29 -0
- data/ext/redcarpet/houdini_href_e.c +108 -0
- data/ext/redcarpet/houdini_html_e.c +84 -0
- data/ext/redcarpet/html.c +603 -0
- data/ext/redcarpet/html.h +67 -0
- data/ext/redcarpet/html_blocks.h +206 -0
- data/ext/redcarpet/html_smartypants.c +385 -0
- data/ext/redcarpet/markdown.c +2454 -0
- data/ext/redcarpet/markdown.h +130 -0
- data/ext/redcarpet/rc_markdown.c +137 -0
- data/ext/redcarpet/rc_render.c +434 -0
- data/ext/redcarpet/redcarpet.h +33 -0
- data/ext/redcarpet/stack.c +81 -0
- data/ext/redcarpet/stack.h +21 -0
- data/lib/redcarpet/render_man.rb +65 -0
- data/lib/redcarpet.rb +65 -72
- data/redcarpet.gemspec +29 -20
- data/test/redcarpet_test.rb +232 -88
- metadata +45 -29
- data/ext/array.c +0 -300
- data/ext/array.h +0 -148
- data/ext/buffer.c +0 -319
- data/ext/buffer.h +0 -145
- data/ext/markdown.c +0 -2076
- data/ext/markdown.h +0 -107
- data/ext/redcarpet.c +0 -140
- data/ext/xhtml.c +0 -779
- data/lib/markdown.rb +0 -1
- data/test/benchmark.rb +0 -56
- data/test/benchmark.txt +0 -306
- data/test/markdown_test.rb +0 -186
- /data/ext/{extconf.rb → redcarpet/extconf.rb} +0 -0
data/ext/markdown.h
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/* markdown.h - generic markdown parser */
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* Copyright (c) 2009, Natacha Porté
|
|
5
|
-
*
|
|
6
|
-
* Permission to use, copy, modify, and distribute this software for any
|
|
7
|
-
* purpose with or without fee is hereby granted, provided that the above
|
|
8
|
-
* copyright notice and this permission notice appear in all copies.
|
|
9
|
-
*
|
|
10
|
-
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
11
|
-
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
12
|
-
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
13
|
-
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
14
|
-
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
15
|
-
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
16
|
-
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
#ifndef UPSKIRT_MARKDOWN_H
|
|
20
|
-
#define UPSKIRT_MARKDOWN_H
|
|
21
|
-
|
|
22
|
-
#include "buffer.h"
|
|
23
|
-
|
|
24
|
-
/* Require a blank newline after HTML tags */
|
|
25
|
-
#define UPSKIRT_NEWLINE_AFTER_TAGS
|
|
26
|
-
|
|
27
|
-
/********************
|
|
28
|
-
* TYPE DEFINITIONS *
|
|
29
|
-
********************/
|
|
30
|
-
|
|
31
|
-
/* mkd_autolink • type of autolink */
|
|
32
|
-
enum mkd_autolink {
|
|
33
|
-
MKDA_NOT_AUTOLINK, /* used internally when it is not an autolink*/
|
|
34
|
-
MKDA_NORMAL, /* normal http/http/ftp/etc link */
|
|
35
|
-
MKDA_EXPLICIT_EMAIL, /* e-mail link with explit mailto: */
|
|
36
|
-
MKDA_IMPLICIT_EMAIL /* e-mail link without mailto: */
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
enum mkd_extensions {
|
|
40
|
-
MKDEXT_LAX_EMPHASIS = (1 << 0),
|
|
41
|
-
MKDEXT_TABLES = (1 << 1),
|
|
42
|
-
MKDEXT_FENCED_CODE = (1 << 2),
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/* mkd_renderer • functions for rendering parsed data */
|
|
46
|
-
struct mkd_renderer {
|
|
47
|
-
/* block level callbacks - NULL skips the block */
|
|
48
|
-
void (*blockcode)(struct buf *ob, struct buf *text, void *opaque);
|
|
49
|
-
void (*blockquote)(struct buf *ob, struct buf *text, void *opaque);
|
|
50
|
-
void (*blockhtml)(struct buf *ob, struct buf *text, void *opaque);
|
|
51
|
-
void (*header)(struct buf *ob, struct buf *text, int level, void *opaque);
|
|
52
|
-
void (*hrule)(struct buf *ob, void *opaque);
|
|
53
|
-
void (*list)(struct buf *ob, struct buf *text, int flags, void *opaque);
|
|
54
|
-
void (*listitem)(struct buf *ob, struct buf *text, int flags, void *opaque);
|
|
55
|
-
void (*paragraph)(struct buf *ob, struct buf *text, void *opaque);
|
|
56
|
-
void (*table)(struct buf *ob, struct buf *header, struct buf *body, void *opaque);
|
|
57
|
-
void (*table_row)(struct buf *ob, struct buf *text, void *opaque);
|
|
58
|
-
void (*table_cell)(struct buf *ob, struct buf *text, int flags, void *opaque);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
/* span level callbacks - NULL or return 0 prints the span verbatim */
|
|
62
|
-
int (*autolink)(struct buf *ob, struct buf *link, enum mkd_autolink type, void *opaque);
|
|
63
|
-
int (*codespan)(struct buf *ob, struct buf *text, void *opaque);
|
|
64
|
-
int (*double_emphasis)(struct buf *ob, struct buf *text, char c, void *opaque);
|
|
65
|
-
int (*emphasis)(struct buf *ob, struct buf *text, char c,void *opaque);
|
|
66
|
-
int (*image)(struct buf *ob, struct buf *link, struct buf *title, struct buf *alt, void *opaque);
|
|
67
|
-
int (*linebreak)(struct buf *ob, void *opaque);
|
|
68
|
-
int (*link)(struct buf *ob, struct buf *link, struct buf *title, struct buf *content, void *opaque);
|
|
69
|
-
int (*raw_html_tag)(struct buf *ob, struct buf *tag, void *opaque);
|
|
70
|
-
int (*triple_emphasis)(struct buf *ob, struct buf *text, char c, void *opaque);
|
|
71
|
-
|
|
72
|
-
/* low level callbacks - NULL copies input directly into the output */
|
|
73
|
-
void (*entity)(struct buf *ob, struct buf *entity, void *opaque);
|
|
74
|
-
void (*normal_text)(struct buf *ob, struct buf *text, void *opaque);
|
|
75
|
-
|
|
76
|
-
/* header and footer */
|
|
77
|
-
void (*doc_header)(struct buf *ob, void *opaque);
|
|
78
|
-
void (*doc_footer)(struct buf *ob, void *opaque);
|
|
79
|
-
|
|
80
|
-
/* renderer data */
|
|
81
|
-
const char *emph_chars; /* chars that trigger emphasis rendering */
|
|
82
|
-
void *opaque;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
/*********
|
|
86
|
-
* FLAGS *
|
|
87
|
-
*********/
|
|
88
|
-
|
|
89
|
-
/* list/listitem flags */
|
|
90
|
-
#define MKD_LIST_ORDERED 1
|
|
91
|
-
#define MKD_LI_BLOCK 2 /* <li> containing block data */
|
|
92
|
-
|
|
93
|
-
#define MKD_TABLE_ALIGN_L (1 << 0)
|
|
94
|
-
#define MKD_TABLE_ALIGN_R (1 << 1)
|
|
95
|
-
#define MKD_TABLE_ALIGN_CENTER (MKD_TABLE_ALIGN_L | MKD_TABLE_ALIGN_R)
|
|
96
|
-
|
|
97
|
-
/**********************
|
|
98
|
-
* EXPORTED FUNCTIONS *
|
|
99
|
-
**********************/
|
|
100
|
-
|
|
101
|
-
/* markdown • parses the input buffer and renders it into the output buffer */
|
|
102
|
-
void
|
|
103
|
-
markdown(struct buf *ob, struct buf *ib, const struct mkd_renderer *rndr, unsigned int extensions);
|
|
104
|
-
|
|
105
|
-
#endif
|
|
106
|
-
|
|
107
|
-
/* vim: set filetype=c: */
|
data/ext/redcarpet.c
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
#include <stdio.h>
|
|
2
|
-
#include "ruby.h"
|
|
3
|
-
|
|
4
|
-
#include "markdown.h"
|
|
5
|
-
#include "xhtml.h"
|
|
6
|
-
|
|
7
|
-
typedef enum
|
|
8
|
-
{
|
|
9
|
-
REDCARPET_RENDER_XHTML,
|
|
10
|
-
REDCARPET_RENDER_TOC
|
|
11
|
-
} RendererType;
|
|
12
|
-
|
|
13
|
-
static VALUE rb_cRedcarpet;
|
|
14
|
-
|
|
15
|
-
static void rb_redcarpet__get_flags(VALUE ruby_obj,
|
|
16
|
-
unsigned int *enabled_extensions_p,
|
|
17
|
-
unsigned int *render_flags_p)
|
|
18
|
-
{
|
|
19
|
-
unsigned int render_flags = XHTML_EXPAND_TABS;
|
|
20
|
-
unsigned int extensions = 0;
|
|
21
|
-
|
|
22
|
-
/* smart */
|
|
23
|
-
if (rb_funcall(ruby_obj, rb_intern("smart"), 0) == Qtrue)
|
|
24
|
-
render_flags |= XHTML_SMARTYPANTS;
|
|
25
|
-
|
|
26
|
-
/* filter_html */
|
|
27
|
-
if (rb_funcall(ruby_obj, rb_intern("filter_html"), 0) == Qtrue)
|
|
28
|
-
render_flags |= XHTML_SKIP_HTML;
|
|
29
|
-
|
|
30
|
-
/* no_image */
|
|
31
|
-
if (rb_funcall(ruby_obj, rb_intern("no_image"), 0) == Qtrue)
|
|
32
|
-
render_flags |= XHTML_SKIP_IMAGES;
|
|
33
|
-
|
|
34
|
-
/* no_links */
|
|
35
|
-
if (rb_funcall(ruby_obj, rb_intern("no_links"), 0) == Qtrue)
|
|
36
|
-
render_flags |= XHTML_SKIP_LINKS;
|
|
37
|
-
|
|
38
|
-
/* filter_style */
|
|
39
|
-
if (rb_funcall(ruby_obj, rb_intern("filter_styles"), 0) == Qtrue)
|
|
40
|
-
render_flags |= XHTML_SKIP_STYLE;
|
|
41
|
-
|
|
42
|
-
/* autolink */
|
|
43
|
-
if (rb_funcall(ruby_obj, rb_intern("autolink"), 0) == Qtrue)
|
|
44
|
-
render_flags |= XHTML_AUTOLINK;
|
|
45
|
-
|
|
46
|
-
/* safelink */
|
|
47
|
-
if (rb_funcall(ruby_obj, rb_intern("safelink"), 0) == Qtrue)
|
|
48
|
-
render_flags |= XHTML_SAFELINK;
|
|
49
|
-
|
|
50
|
-
if (rb_funcall(ruby_obj, rb_intern("generate_toc"), 0) == Qtrue)
|
|
51
|
-
render_flags |= XHTML_TOC;
|
|
52
|
-
|
|
53
|
-
if (rb_funcall(ruby_obj, rb_intern("no_strikethrough"), 0) == Qtrue)
|
|
54
|
-
render_flags |= XHTML_SKIP_STRIKETHROUGH;
|
|
55
|
-
|
|
56
|
-
/* parser - strict
|
|
57
|
-
* This is fucking stupid; what the 'strict' flag actually
|
|
58
|
-
* enforces is laxer emphasis parsing. So we use a properly
|
|
59
|
-
* named flag internally, even if outside we have retarded
|
|
60
|
-
* naming because of compat. issues .*/
|
|
61
|
-
if (rb_funcall(ruby_obj, rb_intern("strict"), 0) == Qtrue)
|
|
62
|
-
extensions |= MKDEXT_LAX_EMPHASIS;
|
|
63
|
-
|
|
64
|
-
if (rb_funcall(ruby_obj, rb_intern("no_tables"), 0) != Qtrue)
|
|
65
|
-
extensions |= MKDEXT_TABLES;
|
|
66
|
-
|
|
67
|
-
if (rb_funcall(ruby_obj, rb_intern("no_fencedcode"), 0) != Qtrue)
|
|
68
|
-
extensions |= MKDEXT_FENCED_CODE;
|
|
69
|
-
|
|
70
|
-
*enabled_extensions_p = extensions;
|
|
71
|
-
*render_flags_p = render_flags;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
static VALUE rb_redcarpet__render(VALUE self, RendererType render_type)
|
|
75
|
-
{
|
|
76
|
-
VALUE text = rb_funcall(self, rb_intern("text"), 0);
|
|
77
|
-
VALUE result;
|
|
78
|
-
|
|
79
|
-
struct buf input_buf, *output_buf;
|
|
80
|
-
struct mkd_renderer renderer;
|
|
81
|
-
unsigned int enabled_extensions, render_flags;
|
|
82
|
-
|
|
83
|
-
Check_Type(text, T_STRING);
|
|
84
|
-
|
|
85
|
-
memset(&input_buf, 0x0, sizeof(struct buf));
|
|
86
|
-
input_buf.data = RSTRING_PTR(text);
|
|
87
|
-
input_buf.size = RSTRING_LEN(text);
|
|
88
|
-
|
|
89
|
-
output_buf = bufnew(128);
|
|
90
|
-
bufgrow(output_buf, RSTRING_LEN(text) * 1.2f);
|
|
91
|
-
|
|
92
|
-
rb_redcarpet__get_flags(self, &enabled_extensions, &render_flags);
|
|
93
|
-
|
|
94
|
-
switch (render_type) {
|
|
95
|
-
case REDCARPET_RENDER_XHTML:
|
|
96
|
-
init_xhtml_renderer(&renderer, render_flags);
|
|
97
|
-
break;
|
|
98
|
-
|
|
99
|
-
case REDCARPET_RENDER_TOC:
|
|
100
|
-
init_toc_renderer(&renderer);
|
|
101
|
-
break;
|
|
102
|
-
|
|
103
|
-
default:
|
|
104
|
-
return Qnil;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
markdown(output_buf, &input_buf, &renderer, enabled_extensions);
|
|
108
|
-
|
|
109
|
-
result = rb_str_new(output_buf->data, output_buf->size);
|
|
110
|
-
bufrelease(output_buf);
|
|
111
|
-
free_renderer(&renderer);
|
|
112
|
-
|
|
113
|
-
/* force the input encoding */
|
|
114
|
-
if (rb_respond_to(text, rb_intern("encoding"))) {
|
|
115
|
-
VALUE encoding = rb_funcall(text, rb_intern("encoding"), 0);
|
|
116
|
-
rb_funcall(result, rb_intern("force_encoding"), 1, encoding);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return result;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
static VALUE
|
|
123
|
-
rb_redcarpet_toc(int argc, VALUE *argv, VALUE self)
|
|
124
|
-
{
|
|
125
|
-
return rb_redcarpet__render(self, REDCARPET_RENDER_TOC);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
static VALUE
|
|
129
|
-
rb_redcarpet_to_html(int argc, VALUE *argv, VALUE self)
|
|
130
|
-
{
|
|
131
|
-
return rb_redcarpet__render(self, REDCARPET_RENDER_XHTML);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
void Init_redcarpet()
|
|
135
|
-
{
|
|
136
|
-
rb_cRedcarpet = rb_define_class("Redcarpet", rb_cObject);
|
|
137
|
-
rb_define_method(rb_cRedcarpet, "to_html", rb_redcarpet_to_html, -1);
|
|
138
|
-
rb_define_method(rb_cRedcarpet, "toc_content", rb_redcarpet_toc, -1);
|
|
139
|
-
}
|
|
140
|
-
|