rdiscount 2.0.7.3 → 2.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/ext/pgm_options.h ADDED
@@ -0,0 +1,9 @@
1
+ #ifndef PGM_OPTIONS_D
2
+ #define PGM_OPTIONS_D
3
+
4
+ #include <mkdio.h>
5
+
6
+ int set_flag(mkd_flag_t *flags, char *optionstring);
7
+ void show_flags(int byname);
8
+
9
+ #endif/*PGM_OPTIONS_D*/
data/ext/rdiscount.c CHANGED
@@ -3,6 +3,37 @@
3
3
  #include "ruby.h"
4
4
  #include "mkdio.h"
5
5
 
6
+ typedef struct {
7
+ char *accessor_name;
8
+ int flag;
9
+ } AccessorFlagPair;
10
+
11
+ /*
12
+ * Maps accessor names on the RDiscount object to Discount flags.
13
+ *
14
+ * The following flags are handled specially:
15
+ * - MKD_TABSTOP: Always set.
16
+ * - MKD_NOHEADER: Always set.
17
+ * - MKD_NOPANTS: Set unless the "smart" accessor returns true.
18
+ *
19
+ * See rb_rdiscount__get_flags() for the detailed implementation.
20
+ */
21
+ static AccessorFlagPair ACCESSOR_2_FLAG[] = {
22
+ { "filter_html", MKD_NOHTML },
23
+ { "footnotes", MKD_EXTRA_FOOTNOTE },
24
+ { "generate_toc", MKD_TOC },
25
+ { "no_image", MKD_NOIMAGE },
26
+ { "no_links", MKD_NOLINKS },
27
+ { "no_tables", MKD_NOTABLES },
28
+ { "strict", MKD_STRICT },
29
+ { "autolink", MKD_AUTOLINK },
30
+ { "safelink", MKD_SAFELINK },
31
+ { "no_pseudo_protocols", MKD_NO_EXT },
32
+ { "no_superscript", MKD_NOSUPERSCRIPT },
33
+ { "no_strikethrough", MKD_NOSTRIKETHROUGH },
34
+ { NULL, 0 } /* sentinel */
35
+ };
36
+
6
37
  static VALUE rb_cRDiscount;
7
38
 
8
39
  static VALUE
@@ -27,7 +58,7 @@ rb_rdiscount_to_html(int argc, VALUE *argv, VALUE self)
27
58
  * of at least 21 bits).
28
59
  */
29
60
  char *old_locale = strdup(setlocale(LC_CTYPE, NULL));
30
- setlocale(LC_CTYPE, "C"); // ASCII (and passthru characters > 127)
61
+ setlocale(LC_CTYPE, "C"); /* ASCII (and passthru characters > 127) */
31
62
 
32
63
  MMIOT *doc = mkd_string(RSTRING_PTR(text), RSTRING_LEN(text), flags);
33
64
 
@@ -46,8 +77,8 @@ rb_rdiscount_to_html(int argc, VALUE *argv, VALUE self)
46
77
 
47
78
  /* force the input encoding */
48
79
  if ( rb_respond_to(text, rb_intern("encoding")) ) {
49
- encoding = rb_funcall(text, rb_intern("encoding"), 0);
50
- rb_funcall(buf, rb_intern("force_encoding"), 1, encoding);
80
+ encoding = rb_funcall(text, rb_intern("encoding"), 0);
81
+ rb_funcall(buf, rb_intern("force_encoding"), 1, encoding);
51
82
  }
52
83
 
53
84
  return buf;
@@ -85,55 +116,24 @@ rb_rdiscount_toc_content(int argc, VALUE *argv, VALUE self)
85
116
 
86
117
  int rb_rdiscount__get_flags(VALUE ruby_obj)
87
118
  {
88
- /* compile flags */
89
- int flags = MKD_TABSTOP | MKD_NOHEADER;
90
-
91
- /* smart */
92
- if ( rb_funcall(ruby_obj, rb_intern("smart"), 0) != Qtrue )
93
- flags = flags | MKD_NOPANTS;
94
-
95
- /* filter_html */
96
- if ( rb_funcall(ruby_obj, rb_intern("filter_html"), 0) == Qtrue )
97
- flags = flags | MKD_NOHTML;
98
-
99
- /* footnotes */
100
- if ( rb_funcall(ruby_obj, rb_intern("footnotes"), 0) == Qtrue )
101
- flags = flags | MKD_EXTRA_FOOTNOTE;
102
-
103
- /* generate_toc */
104
- if ( rb_funcall(ruby_obj, rb_intern("generate_toc"), 0) == Qtrue)
105
- flags = flags | MKD_TOC;
106
-
107
- /* no_image */
108
- if ( rb_funcall(ruby_obj, rb_intern("no_image"), 0) == Qtrue)
109
- flags = flags | MKD_NOIMAGE;
110
-
111
- /* no_links */
112
- if ( rb_funcall(ruby_obj, rb_intern("no_links"), 0) == Qtrue)
113
- flags = flags | MKD_NOLINKS;
114
-
115
- /* no_tables */
116
- if ( rb_funcall(ruby_obj, rb_intern("no_tables"), 0) == Qtrue)
117
- flags = flags | MKD_NOTABLES;
118
-
119
- /* strict */
120
- if ( rb_funcall(ruby_obj, rb_intern("strict"), 0) == Qtrue)
121
- flags = flags | MKD_STRICT;
122
-
123
- /* autolink */
124
- if ( rb_funcall(ruby_obj, rb_intern("autolink"), 0) == Qtrue)
125
- flags = flags | MKD_AUTOLINK;
126
-
127
- /* safelink */
128
- if ( rb_funcall(ruby_obj, rb_intern("safelink"), 0) == Qtrue)
129
- flags = flags | MKD_SAFELINK;
130
-
131
- /* no_pseudo_protocols */
132
- if ( rb_funcall(ruby_obj, rb_intern("no_pseudo_protocols"), 0) == Qtrue)
133
- flags = flags | MKD_NO_EXT;
134
-
135
-
136
- return flags;
119
+ AccessorFlagPair *entry;
120
+
121
+ /* compile flags */
122
+ int flags = MKD_TABSTOP | MKD_NOHEADER;
123
+
124
+ /* The "smart" accessor turns OFF the MKD_NOPANTS flag. */
125
+ if ( rb_funcall(ruby_obj, rb_intern("smart"), 0) != Qtrue ) {
126
+ flags = flags | MKD_NOPANTS;
127
+ }
128
+
129
+ /* Handle standard flags declared in ACCESSOR_2_FLAG */
130
+ for ( entry = ACCESSOR_2_FLAG; entry->accessor_name; entry++ ) {
131
+ if ( rb_funcall(ruby_obj, rb_intern(entry->accessor_name), 0) == Qtrue ) {
132
+ flags = flags | entry->flag;
133
+ }
134
+ }
135
+
136
+ return flags;
137
137
  }
138
138
 
139
139
 
data/ext/setup.c CHANGED
@@ -18,7 +18,6 @@
18
18
  #include "amalloc.h"
19
19
  #include "tags.h"
20
20
 
21
- static int need_to_setup = 1;
22
21
  static int need_to_initrng = 1;
23
22
 
24
23
  void
@@ -29,19 +28,12 @@ mkd_initialize()
29
28
  need_to_initrng = 0;
30
29
  INITRNG(time(0));
31
30
  }
32
- if ( need_to_setup ) {
33
- need_to_setup = 0;
34
- mkd_prepare_tags();
35
- }
36
31
  }
37
32
 
38
33
 
39
34
  void
40
35
  mkd_shlib_destructor()
41
36
  {
42
- if ( !need_to_setup ) {
43
- need_to_setup = 1;
44
- mkd_deallocate_tags();
45
- }
37
+ mkd_deallocate_tags();
46
38
  }
47
39
 
data/ext/tags.c CHANGED
@@ -4,19 +4,33 @@
4
4
  #include "cstring.h"
5
5
  #include "tags.h"
6
6
 
7
- STRING(struct kw) blocktags;
7
+ STRING(struct kw) extratags;
8
+
9
+ /* the standard collection of tags are built and sorted when
10
+ * discount is configured, so all we need to do is pull them
11
+ * in and use them.
12
+ *
13
+ * Additional tags still need to be allocated, sorted, and deallocated.
14
+ */
15
+ #include "blocktags"
8
16
 
9
17
 
10
- /* define a html block tag
18
+ /* define an additional html block tag
11
19
  */
12
20
  void
13
21
  mkd_define_tag(char *id, int selfclose)
14
22
  {
15
- struct kw *p = &EXPAND(blocktags);
16
-
17
- p->id = id;
18
- p->size = strlen(id);
19
- p->selfclose = selfclose;
23
+ struct kw *p;
24
+
25
+ /* only add the new tag if it doesn't exist in
26
+ * either the standard or extra tag tables.
27
+ */
28
+ if ( !(p = mkd_search_tags(id, strlen(id))) ) {
29
+ p = &EXPAND(extratags);
30
+ p->id = id;
31
+ p->size = strlen(id);
32
+ p->selfclose = selfclose;
33
+ }
20
34
  }
21
35
 
22
36
 
@@ -37,87 +51,41 @@ casort(struct kw *a, struct kw *b)
37
51
  typedef int (*stfu)(const void*,const void*);
38
52
 
39
53
 
40
- /* sort the list of html block tags for later searching
54
+ /* sort the list of extra html block tags for later searching
41
55
  */
42
56
  void
43
57
  mkd_sort_tags()
44
58
  {
45
- qsort(T(blocktags), S(blocktags), sizeof(struct kw), (stfu)casort);
59
+ qsort(T(extratags), S(extratags), sizeof(struct kw), (stfu)casort);
46
60
  }
47
61
 
48
62
 
49
-
50
63
  /* look for a token in the html block tag list
51
64
  */
52
65
  struct kw*
53
66
  mkd_search_tags(char *pat, int len)
54
67
  {
55
68
  struct kw key;
69
+ struct kw *ret;
56
70
 
57
71
  key.id = pat;
58
72
  key.size = len;
59
73
 
60
- return bsearch(&key, T(blocktags), S(blocktags), sizeof key, (stfu)casort);
61
- }
62
-
63
-
64
- static int populated = 0;
74
+ if ( (ret=bsearch(&key,blocktags,NR_blocktags,sizeof key,(stfu)casort)) )
75
+ return ret;
65
76
 
77
+ if ( S(extratags) )
78
+ return bsearch(&key,T(extratags),S(extratags),sizeof key,(stfu)casort);
79
+
80
+ return 0;
81
+ }
66
82
 
67
- /* load in the standard collection of html tags that markdown supports
68
- */
69
- void
70
- mkd_prepare_tags()
71
- {
72
-
73
- #define KW(x) mkd_define_tag(x, 0)
74
- #define SC(x) mkd_define_tag(x, 1)
75
83
 
76
- if ( populated ) return;
77
- populated = 1;
78
-
79
- KW("STYLE");
80
- KW("SCRIPT");
81
- KW("ADDRESS");
82
- KW("BDO");
83
- KW("BLOCKQUOTE");
84
- KW("CENTER");
85
- KW("DFN");
86
- KW("DIV");
87
- KW("OBJECT");
88
- KW("H1");
89
- KW("H2");
90
- KW("H3");
91
- KW("H4");
92
- KW("H5");
93
- KW("H6");
94
- KW("LISTING");
95
- KW("NOBR");
96
- KW("UL");
97
- KW("P");
98
- KW("OL");
99
- KW("DL");
100
- KW("PLAINTEXT");
101
- KW("PRE");
102
- KW("TABLE");
103
- KW("WBR");
104
- KW("XMP");
105
- SC("HR");
106
- SC("BR");
107
- KW("IFRAME");
108
- KW("MAP");
109
-
110
- mkd_sort_tags();
111
- } /* mkd_prepare_tags */
112
-
113
-
114
- /* destroy the blocktags list (for shared libraries)
84
+ /* destroy the extratags list (for shared libraries)
115
85
  */
116
86
  void
117
87
  mkd_deallocate_tags()
118
88
  {
119
- if ( S(blocktags) > 0 ) {
120
- populated = 0;
121
- DELETE(blocktags);
122
- }
89
+ if ( S(extratags) > 0 )
90
+ DELETE(extratags);
123
91
  } /* mkd_deallocate_tags */
data/ext/toc.c CHANGED
@@ -1,7 +1,8 @@
1
1
  /*
2
2
  * toc -- spit out a table of contents based on header blocks
3
3
  *
4
- * Copyright (C) 2008 Jjgod Jiang, David L Parsons.
4
+ * Copyright (C) 2008 Jjgod Jiang, David L Parsons
5
+ * portions Copyright (C) 2011 Stefano D'Angelo
5
6
  * The redistribution terms are provided in the COPYRIGHT file that must
6
7
  * be distributed with this source code.
7
8
  */
@@ -23,6 +24,7 @@ mkd_toc(Document *p, char **doc)
23
24
  int last_hnumber = 0;
24
25
  Cstring res;
25
26
  int size;
27
+ int first = 1;
26
28
 
27
29
  if ( !(doc && p && p->ctx) ) return -1;
28
30
 
@@ -38,16 +40,23 @@ mkd_toc(Document *p, char **doc)
38
40
  for ( srcp = tp->down; srcp; srcp = srcp->next ) {
39
41
  if ( srcp->typ == HDR && srcp->text ) {
40
42
 
41
- if ( last_hnumber >= srcp->hnumber ) {
42
- while ( last_hnumber > srcp->hnumber ) {
43
- Csprintf(&res, "%*s</ul></li>\n", last_hnumber-1,"");
44
- --last_hnumber;
45
- }
43
+ while ( last_hnumber > srcp->hnumber ) {
44
+ if ( (last_hnumber - srcp->hnumber) > 1 )
45
+ Csprintf(&res, "\n");
46
+ Csprintf(&res, "</li>\n%*s</ul>\n%*s",
47
+ last_hnumber-1, "", last_hnumber-1, "");
48
+ --last_hnumber;
46
49
  }
47
50
 
51
+ if ( last_hnumber == srcp->hnumber )
52
+ Csprintf(&res, "</li>\n");
53
+ else if ( (srcp->hnumber > last_hnumber) && !first )
54
+ Csprintf(&res, "\n");
55
+
48
56
  while ( srcp->hnumber > last_hnumber ) {
49
- Csprintf(&res, "%*s%s<ul>\n", last_hnumber, "",
50
- last_hnumber ? "<li>" : "");
57
+ Csprintf(&res, "%*s<ul>\n", last_hnumber, "");
58
+ if ( (srcp->hnumber - last_hnumber) > 1 )
59
+ Csprintf(&res, "%*s<li>\n", last_hnumber+1, "");
51
60
  ++last_hnumber;
52
61
  }
53
62
  Csprintf(&res, "%*s<li><a href=\"#", srcp->hnumber, "");
@@ -59,7 +68,8 @@ mkd_toc(Document *p, char **doc)
59
68
  S(srcp->text->text),
60
69
  (mkd_sta_function_t)Csputc, &res,0);
61
70
  Csprintf(&res, "</a>");
62
- Csprintf(&res, "</li>\n");
71
+
72
+ first = 0;
63
73
  }
64
74
  }
65
75
  }
@@ -67,7 +77,8 @@ mkd_toc(Document *p, char **doc)
67
77
 
68
78
  while ( last_hnumber > 0 ) {
69
79
  --last_hnumber;
70
- Csprintf(&res, last_hnumber ? "%*s</ul></li>\n" : "%*s</ul>\n", last_hnumber, "");
80
+ Csprintf(&res, "</li>\n%*s</ul>\n%*s",
81
+ last_hnumber, "", last_hnumber, "");
71
82
  }
72
83
 
73
84
  if ( (size = S(res)) > 0 ) {
data/ext/version.c CHANGED
@@ -18,5 +18,13 @@ char markdown_version[] = VERSION
18
18
  #else
19
19
  " DL=NONE"
20
20
  #endif
21
-
21
+ #if WITH_ID_ANCHOR
22
+ " ID-ANCHOR"
23
+ #endif
24
+ #if WITH_GITHUB_TAGS
25
+ " GITHUB-TAGS"
26
+ #endif
27
+ #if WITH_FENCED_CODE
28
+ " FENCED-CODE"
29
+ #endif
22
30
  ;
data/lib/rdiscount.rb CHANGED
@@ -24,7 +24,7 @@
24
24
  # end
25
25
  #
26
26
  class RDiscount
27
- VERSION = '2.0.7'
27
+ VERSION = '2.1.6'
28
28
 
29
29
  # Original Markdown formatted text.
30
30
  attr_reader :text
@@ -68,6 +68,12 @@ class RDiscount
68
68
 
69
69
  # Do not process pseudo-protocols like <tt>[](id:name)</tt>
70
70
  attr_accessor :no_pseudo_protocols
71
+
72
+ # Disable superscript processing.
73
+ attr_accessor :no_superscript
74
+
75
+ # Disable strikethrough processing.
76
+ attr_accessor :no_strikethrough
71
77
 
72
78
  # Create a RDiscount Markdown processor. The +text+ argument
73
79
  # should be a string containing Markdown text. Additional arguments may be
data/rdiscount.gemspec CHANGED
@@ -1,8 +1,8 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rdiscount'
3
- s.version = '2.0.7.3'
3
+ s.version = '2.1.6'
4
4
  s.summary = "Fast Implementation of Gruber's Markdown in C"
5
- s.date = '2013-05-07'
5
+ s.date = '2013-05-28'
6
6
  s.email = 'davidfstr@gmail.com'
7
7
  s.homepage = 'http://dafoster.net/projects/rdiscount/'
8
8
  s.authors = ["Ryan Tomayko", "David Loren Parsons", "Andrew White", "David Foster"]
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  ext/amalloc.c
20
20
  ext/amalloc.h
21
21
  ext/basename.c
22
+ ext/blocktags
22
23
  ext/config.h
23
24
  ext/css.c
24
25
  ext/cstring.h
@@ -28,11 +29,15 @@ Gem::Specification.new do |s|
28
29
  ext/extconf.rb
29
30
  ext/flags.c
30
31
  ext/generate.c
32
+ ext/github_flavoured.c
31
33
  ext/html5.c
32
34
  ext/markdown.c
33
35
  ext/markdown.h
34
36
  ext/mkdio.c
35
37
  ext/mkdio.h
38
+ ext/mktags.c
39
+ ext/pgm_options.c
40
+ ext/pgm_options.h
36
41
  ext/rdiscount.c
37
42
  ext/resource.c
38
43
  ext/setup.c