rdiscount 2.1.7 → 2.2.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,6 +16,7 @@
16
16
 
17
17
  typedef ANCHOR(Line) LineAnchor;
18
18
 
19
+
19
20
  /* create a new blank Document
20
21
  */
21
22
  Document*
@@ -183,15 +184,13 @@ mkd_generatehtml(Document *p, FILE *output)
183
184
  char *doc;
184
185
  int szdoc;
185
186
 
186
- if ( (szdoc = mkd_document(p, &doc)) != EOF ) {
187
- if ( p->ctx->flags & MKD_CDATA )
188
- mkd_generatexml(doc, szdoc, output);
189
- else
190
- fwrite(doc, szdoc, 1, output);
191
- putc('\n', output);
192
- return 0;
193
- }
194
- return -1;
187
+ DO_OR_DIE( szdoc = mkd_document(p,&doc) );
188
+ if ( p->ctx->flags & MKD_CDATA )
189
+ DO_OR_DIE( mkd_generatexml(doc, szdoc, output) );
190
+ else if ( fwrite(doc, szdoc, 1, output) != 1 )
191
+ return EOF;
192
+ DO_OR_DIE( putc('\n', output) );
193
+ return 0;
195
194
  }
196
195
 
197
196
 
@@ -213,22 +212,31 @@ markdown(Document *document, FILE *out, int flags)
213
212
  */
214
213
  void
215
214
  mkd_string_to_anchor(char *s, int len, mkd_sta_function_t outchar,
216
- void *out, int labelformat)
215
+ void *out, int labelformat,
216
+ DWORD flags)
217
217
  {
218
+ static const unsigned char hexchars[] = "0123456789abcdef";
218
219
  unsigned char c;
219
220
 
220
221
  int i, size;
221
222
  char *line;
222
223
 
223
224
  size = mkd_line(s, len, &line, IS_LABEL);
224
-
225
- if ( labelformat && (size>0) && !isalpha(line[0]) )
225
+
226
+ if ( !(flags & MKD_URLENCODEDANCHOR)
227
+ && labelformat
228
+ && (size>0) && !isalpha(line[0]) )
226
229
  (*outchar)('L',out);
227
230
  for ( i=0; i < size ; i++ ) {
228
231
  c = line[i];
229
232
  if ( labelformat ) {
230
233
  if ( isalnum(c) || (c == '_') || (c == ':') || (c == '-') || (c == '.' ) )
231
234
  (*outchar)(c, out);
235
+ else if ( flags & MKD_URLENCODEDANCHOR ) {
236
+ (*outchar)('%', out);
237
+ (*outchar)(hexchars[c >> 4 & 0xf], out);
238
+ (*outchar)(hexchars[c & 0xf], out);
239
+ }
232
240
  else
233
241
  (*outchar)('.', out);
234
242
  }
@@ -289,15 +297,16 @@ int
289
297
  mkd_generateline(char *bfr, int size, FILE *output, DWORD flags)
290
298
  {
291
299
  MMIOT f;
300
+ int status;
292
301
 
293
302
  mkd_parse_line(bfr, size, &f, flags);
294
303
  if ( flags & MKD_CDATA )
295
- mkd_generatexml(T(f.out), S(f.out), output);
304
+ status = mkd_generatexml(T(f.out), S(f.out), output) != EOF;
296
305
  else
297
- fwrite(T(f.out), S(f.out), 1, output);
306
+ status = fwrite(T(f.out), S(f.out), 1, output) == S(f.out);
298
307
 
299
308
  ___mkd_freemmiot(&f, 0);
300
- return 0;
309
+ return status ? 0 : EOF;
301
310
  }
302
311
 
303
312
 
@@ -106,6 +106,13 @@ void mkd_ref_prefix(MMIOT*, char*);
106
106
  #define MKD_NODLIST 0x00100000 /* forbid definition lists */
107
107
  #define MKD_EXTRA_FOOTNOTE 0x00200000 /* enable markdown extra-style footnotes */
108
108
  #define MKD_NOSTYLE 0x00400000 /* don't extract <style> blocks */
109
+ #define MKD_NODLDISCOUNT 0x00800000 /* disable discount-style definition lists */
110
+ #define MKD_DLEXTRA 0x01000000 /* enable extra-style definition lists */
111
+ #define MKD_FENCEDCODE 0x02000000 /* enabled fenced code blocks */
112
+ #define MKD_IDANCHOR 0x04000000 /* use id= anchors for TOC links */
113
+ #define MKD_GITHUBTAGS 0x08000000 /* allow dash and underscore in element names */
114
+ #define MKD_URLENCODEDANCHOR 0x10000000 /* urlencode non-identifier chars instead of replacing with dots */
115
+
109
116
  #define MKD_EMBED MKD_NOLINKS|MKD_NOIMAGE|MKD_TAGTEXT
110
117
 
111
118
  /* special flags for mkd_in() and mkd_string()
@@ -8,7 +8,9 @@
8
8
  #include <stdio.h>
9
9
  #include <stdlib.h>
10
10
  #include <limits.h>
11
+ #ifndef _MSC_VER
11
12
  #include <unistd.h>
13
+ #endif
12
14
  #include <mkdio.h>
13
15
  #include <errno.h>
14
16
  #include <string.h>
@@ -25,7 +27,7 @@ static struct _opt {
25
27
  char *name;
26
28
  char *desc;
27
29
  int off;
28
- int skip;
30
+ int skip; /* this opt is a synonym */
29
31
  int sayenable;
30
32
  mkd_flag_t flag;
31
33
  } opts[] = {
@@ -55,6 +57,12 @@ static struct _opt {
55
57
  { "footnotes", "markdown extra footnotes", 0, 0, 1, MKD_EXTRA_FOOTNOTE },
56
58
  { "footnote", "markdown extra footnotes", 0, 1, 1, MKD_EXTRA_FOOTNOTE },
57
59
  { "style", "extract style blocks", 1, 0, 1, MKD_NOSTYLE },
60
+ { "dldiscount", "discount-style definition lists", 1, 0, 1, MKD_NODLDISCOUNT },
61
+ { "dlextra", "extra-style definition lists", 0, 0, 1, MKD_DLEXTRA },
62
+ { "fencedcode", "fenced code blocks", 0, 0, 1, MKD_FENCEDCODE },
63
+ { "idanchor", "id= anchors in TOC", 0, 0, 1, MKD_IDANCHOR },
64
+ { "githubtags", "permit - and _ in element names", 0, 0, 0, MKD_GITHUBTAGS },
65
+ { "urlencodedanchor", "urlencode special chars in TOC links", 0, 0, 0, MKD_URLENCODEDANCHOR },
58
66
  } ;
59
67
 
60
68
  #define NR(x) (sizeof x / sizeof x[0])
@@ -14,6 +14,9 @@ typedef struct {
14
14
  * The following flags are handled specially:
15
15
  * - MKD_TABSTOP: Always set.
16
16
  * - MKD_NOHEADER: Always set.
17
+ * - MKD_DLEXTRA: Always set. (For compatibility with RDiscount 2.1.8 and earlier.)
18
+ * - MKD_FENCEDCODE: Always set. (For compatibility with RDiscount 2.1.8 and earlier.)
19
+ * - MKD_GITHUBTAGS: Always set. (For compatibility with RDiscount 2.1.8 and earlier.)
17
20
  * - MKD_NOPANTS: Set unless the "smart" accessor returns true.
18
21
  *
19
22
  * See rb_rdiscount__get_flags() for the detailed implementation.
@@ -36,6 +39,28 @@ static AccessorFlagPair ACCESSOR_2_FLAG[] = {
36
39
 
37
40
  static VALUE rb_cRDiscount;
38
41
 
42
+ int rb_rdiscount__get_flags(VALUE ruby_obj)
43
+ {
44
+ AccessorFlagPair *entry;
45
+
46
+ /* compile flags */
47
+ int flags = MKD_TABSTOP | MKD_NOHEADER | MKD_DLEXTRA | MKD_FENCEDCODE | MKD_GITHUBTAGS;
48
+
49
+ /* The "smart" accessor turns OFF the MKD_NOPANTS flag. */
50
+ if ( rb_funcall(ruby_obj, rb_intern("smart"), 0) != Qtrue ) {
51
+ flags = flags | MKD_NOPANTS;
52
+ }
53
+
54
+ /* Handle standard flags declared in ACCESSOR_2_FLAG */
55
+ for ( entry = ACCESSOR_2_FLAG; entry->accessor_name; entry++ ) {
56
+ if ( rb_funcall(ruby_obj, rb_intern(entry->accessor_name), 0) == Qtrue ) {
57
+ flags = flags | entry->flag;
58
+ }
59
+ }
60
+
61
+ return flags;
62
+ }
63
+
39
64
  static VALUE
40
65
  rb_rdiscount_to_html(int argc, VALUE *argv, VALUE self)
41
66
  {
@@ -114,28 +139,6 @@ rb_rdiscount_toc_content(int argc, VALUE *argv, VALUE self)
114
139
  return buf;
115
140
  }
116
141
 
117
- int rb_rdiscount__get_flags(VALUE ruby_obj)
118
- {
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
- }
138
-
139
142
 
140
143
  void Init_rdiscount()
141
144
  {
@@ -76,9 +76,9 @@ ___mkd_freefootnotes(MMIOT *f)
76
76
  int i;
77
77
 
78
78
  if ( f->footnotes ) {
79
- for (i=0; i < S(*f->footnotes); i++)
80
- ___mkd_freefootnote( &T(*f->footnotes)[i] );
81
- DELETE(*f->footnotes);
79
+ for (i=0; i < S(f->footnotes->note); i++)
80
+ ___mkd_freefootnote( &T(f->footnotes->note)[i] );
81
+ DELETE(f->footnotes->note);
82
82
  free(f->footnotes);
83
83
  }
84
84
  }
@@ -98,7 +98,7 @@ ___mkd_initmmiot(MMIOT *f, void *footnotes)
98
98
  f->footnotes = footnotes;
99
99
  else {
100
100
  f->footnotes = malloc(sizeof f->footnotes[0]);
101
- CREATE(*f->footnotes);
101
+ CREATE(f->footnotes->note);
102
102
  }
103
103
  }
104
104
  }
data/ext/toc.c CHANGED
@@ -62,11 +62,11 @@ mkd_toc(Document *p, char **doc)
62
62
  Csprintf(&res, "%*s<li><a href=\"#", srcp->hnumber, "");
63
63
  mkd_string_to_anchor(T(srcp->text->text),
64
64
  S(srcp->text->text),
65
- (mkd_sta_function_t)Csputc, &res,1);
65
+ (mkd_sta_function_t)Csputc, &res,1,p->ctx->flags);
66
66
  Csprintf(&res, "\">");
67
67
  mkd_string_to_anchor(T(srcp->text->text),
68
68
  S(srcp->text->text),
69
- (mkd_sta_function_t)Csputc, &res,0);
69
+ (mkd_sta_function_t)Csputc, &res,0,p->ctx->flags);
70
70
  Csprintf(&res, "</a>");
71
71
 
72
72
  first = 0;
@@ -7,24 +7,7 @@ char markdown_version[] = VERSION
7
7
  #if USE_AMALLOC
8
8
  " DEBUG"
9
9
  #endif
10
- #if USE_DISCOUNT_DL
11
- # if USE_EXTRA_DL
12
- " DL=BOTH"
13
- # else
14
- " DL=DISCOUNT"
15
- # endif
16
- #elif USE_EXTRA_DL
17
- " DL=EXTRA"
18
- #else
19
- " DL=NONE"
20
- #endif
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"
10
+ #if WITH_LATEX
11
+ " LATEX"
29
12
  #endif
30
13
  ;
data/ext/xml.c CHANGED
@@ -47,9 +47,9 @@ mkd_generatexml(char *p, int size, FILE *out)
47
47
  c = *p++;
48
48
 
49
49
  if ( entity = mkd_xmlchar(c) )
50
- fputs(entity, out);
50
+ DO_OR_DIE( fputs(entity, out) );
51
51
  else
52
- fputc(c, out);
52
+ DO_OR_DIE( fputc(c, out) );
53
53
  }
54
54
  return 0;
55
55
  }
@@ -22,27 +22,25 @@ mkd_xhtmlpage(Document *p, int flags, FILE *out)
22
22
  extern char *mkd_doc_title(Document *);
23
23
 
24
24
  if ( mkd_compile(p, flags) ) {
25
- fprintf(out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
26
- fprintf(out, "<!DOCTYPE html "
27
- " PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\""
28
- " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n");
25
+ DO_OR_DIE( fprintf(out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
26
+ "<!DOCTYPE html "
27
+ " PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\""
28
+ " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
29
+ "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n") );
29
30
 
30
- fprintf(out, "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n");
31
-
32
- fprintf(out, "<head>\n");
33
- if ( title = mkd_doc_title(p) )
34
- fprintf(out, "<title>%s</title>\n", title);
35
- mkd_generatecss(p, out);
36
- fprintf(out, "</head>\n");
37
-
38
- fprintf(out, "<body>\n");
39
- mkd_generatehtml(p, out);
40
- fprintf(out, "</body>\n");
41
- fprintf(out, "</html>\n");
31
+ DO_OR_DIE( fprintf(out, "<head>\n") );
32
+ if ( title = mkd_doc_title(p) ) {
33
+ DO_OR_DIE( fprintf(out, "<title>%s</title>\n", title) );
34
+ }
35
+ DO_OR_DIE( mkd_generatecss(p, out) );
36
+ DO_OR_DIE( fprintf(out, "</head>\n"
37
+ "<body>\n") );
42
38
 
43
- mkd_cleanup(p);
39
+ DO_OR_DIE( mkd_generatehtml(p, out) );
40
+ DO_OR_DIE( fprintf(out, "</body>\n"
41
+ "</html>\n") );
44
42
 
45
43
  return 0;
46
44
  }
47
- return -1;
45
+ return EOF;
48
46
  }
@@ -24,7 +24,7 @@
24
24
  # end
25
25
  #
26
26
  class RDiscount
27
- VERSION = '2.1.7'
27
+ VERSION = '2.2.0.2'
28
28
 
29
29
  # Original Markdown formatted text.
30
30
  attr_reader :text
@@ -1,11 +1,12 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rdiscount'
3
- s.version = '2.1.7'
3
+ s.version = '2.2.0.2'
4
4
  s.summary = "Fast Implementation of Gruber's Markdown in C"
5
- s.date = '2013-10-13'
6
- s.email = 'davidfstr@gmail.com'
5
+ s.date = '2020-08-09'
6
+ s.email = 'david@dafoster.net'
7
7
  s.homepage = 'http://dafoster.net/projects/rdiscount/'
8
8
  s.authors = ["Ryan Tomayko", "David Loren Parsons", "Andrew White", "David Foster"]
9
+ s.license = "BSD-3-Clause"
9
10
  # = MANIFEST =
10
11
  s.files = %w[
11
12
  BUILDING
@@ -153,6 +153,15 @@ EOS
153
153
  rd = RDiscount.new(<<EOS, :footnotes)
154
154
  Obtuse text.[^1]
155
155
 
156
+ [^1]: Clarification
157
+ EOS
158
+ assert rd.to_html.include?('<a href="#fn:1" rel="footnote">1</a>')
159
+ end
160
+
161
+ def test_that_footnotes_in_span_works
162
+ rd = RDiscount.new(<<EOS, :footnotes)
163
+ [Obtuse text.[^1]](class:someclass)
164
+
156
165
  [^1]: Clarification
157
166
  EOS
158
167
  assert rd.to_html.include?('<a href="#fn:1" rel="footnote">1</a>')
@@ -204,6 +213,17 @@ EOS
204
213
  assert_equal "<pre><code>line 1\n\nline 2\n</code></pre>\n", rd.to_html
205
214
  end
206
215
 
216
+ def test_that_gfm_code_blocks_work_with_language
217
+ rd = RDiscount.new(<<EOS)
218
+ ```ruby
219
+ line 1
220
+
221
+ line 2
222
+ ```
223
+ EOS
224
+ assert_equal "<pre><code class=\"ruby\">line 1\n\nline 2\n</code></pre>\n", rd.to_html
225
+ end
226
+
207
227
  def test_that_pandoc_code_blocks_work
208
228
  rd = RDiscount.new(<<EOS)
209
229
  ~~~
@@ -230,7 +250,7 @@ EOS
230
250
  EOS
231
251
  end
232
252
 
233
- def test_that_php_definition_lists_work
253
+ def test_that_extra_definition_lists_work
234
254
  rd = RDiscount.new(<<EOS)
235
255
  tag1
236
256
  : data
@@ -242,4 +262,15 @@ EOS
242
262
  </dl>
243
263
  EOS
244
264
  end
265
+
266
+ def test_that_emphasis_beside_international_characters_detected
267
+ rd = RDiscount.new(%(*foo ä bar*))
268
+ assert_equal %(<p><em>foo ä bar</em></p>\n), rd.to_html
269
+
270
+ rd = RDiscount.new(%(*ä foobar*))
271
+ assert_equal %(<p><em>ä foobar</em></p>\n), rd.to_html
272
+
273
+ rd = RDiscount.new(%(*foobar ä*))
274
+ assert_equal %(<p><em>foobar ä</em></p>\n), rd.to_html
275
+ end
245
276
  end
metadata CHANGED
@@ -1,21 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdiscount
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.7
5
- prerelease:
4
+ version: 2.2.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ryan Tomayko
9
8
  - David Loren Parsons
10
9
  - Andrew White
11
10
  - David Foster
12
- autorequire:
11
+ autorequire:
13
12
  bindir: bin
14
13
  cert_chain: []
15
- date: 2013-10-13 00:00:00.000000000 Z
14
+ date: 2020-08-09 00:00:00.000000000 Z
16
15
  dependencies: []
17
- description:
18
- email: davidfstr@gmail.com
16
+ description:
17
+ email: david@dafoster.net
19
18
  executables:
20
19
  - rdiscount
21
20
  extensions:
@@ -72,30 +71,28 @@ files:
72
71
  - test/markdown_test.rb
73
72
  - test/rdiscount_test.rb
74
73
  homepage: http://dafoster.net/projects/rdiscount/
75
- licenses: []
76
- post_install_message:
74
+ licenses:
75
+ - BSD-3-Clause
76
+ metadata: {}
77
+ post_install_message:
77
78
  rdoc_options: []
78
79
  require_paths:
79
80
  - lib
80
81
  required_ruby_version: !ruby/object:Gem::Requirement
81
- none: false
82
82
  requirements:
83
- - - ! '!='
83
+ - - "!="
84
84
  - !ruby/object:Gem::Version
85
85
  version: 1.9.2
86
86
  required_rubygems_version: !ruby/object:Gem::Requirement
87
- none: false
88
87
  requirements:
89
- - - ! '>='
88
+ - - ">="
90
89
  - !ruby/object:Gem::Version
91
90
  version: '0'
92
91
  requirements: []
93
- rubyforge_project: wink
94
- rubygems_version: 1.8.24
95
- signing_key:
96
- specification_version: 3
92
+ rubygems_version: 3.0.8
93
+ signing_key:
94
+ specification_version: 4
97
95
  summary: Fast Implementation of Gruber's Markdown in C
98
96
  test_files:
99
97
  - test/markdown_test.rb
100
98
  - test/rdiscount_test.rb
101
- has_rdoc: