bluecloth 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -2,22 +2,32 @@
2
2
 
3
3
  BlueCloth is a Ruby implementation of John Gruber's
4
4
  Markdown[http://daringfireball.net/projects/markdown/], a text-to-HTML
5
- conversion tool for web writers. To quote from the project page: Markdown
6
- allows you to write using an easy-to-read, easy-to-write plain text format,
7
- then convert it to structurally valid XHTML (or HTML).
5
+ conversion tool for web writers. To quote from the project page:
6
+ Markdown allows you to write using an easy-to-read, easy-to-write plain
7
+ text format, then convert it to structurally valid XHTML (or HTML).
8
8
 
9
9
  It borrows a naming convention and several helpings of interface from
10
- Redcloth[http://www.whytheluckystiff.net/ruby/redcloth/],
11
- {Why the Lucky Stiff}[http://www.whytheluckystiff.net/] 's processor for a
12
- similar text-to-HTML conversion syntax called
10
+ Redcloth[http://www.whytheluckystiff.net/ruby/redcloth/], {Why the Lucky
11
+ Stiff}[http://www.whytheluckystiff.net/] 's processor for a similar
12
+ text-to-HTML conversion syntax called
13
13
  Textile[http://www.textism.com/tools/textile/].
14
14
 
15
- BlueCloth 2 is a complete rewrite using David Parsons' Discount library, a C
16
- implementation of Markdown. I rewrote it using the extension for speed and
17
- accuracy; the original BlueCloth was a straight port from the Perl version
18
- that I wrote in a few days for my own use just to avoid having to shell out
19
- to Markdown.pl, and it was quite buggy and slow. I apologize to all the good
20
- people that sent me patches for it that were never released.
15
+ BlueCloth 2 is a complete rewrite using David Parsons' Discount library,
16
+ a C implementation of Markdown. I rewrote it using the extension for
17
+ speed and accuracy; the original BlueCloth was a straight port from the
18
+ Perl version that I wrote in a few days for my own use just to avoid
19
+ having to shell out to Markdown.pl, and it was quite buggy and slow. I
20
+ apologize to all the good people that sent me patches for it that were
21
+ never released.
22
+
23
+ Note that the new gem is called 'bluecloth' and the old one 'BlueCloth'. If you have both installed, you can ensure you're loading the new one with the 'gem' directive:
24
+
25
+ # Load the 2.0 version
26
+ gem 'bluecloth', '>= 2.0.0'
27
+
28
+ # Load the 1.0 version
29
+ gem 'BlueCloth'
30
+ require 'bluecloth'
21
31
 
22
32
 
23
33
  == Authors
@@ -50,22 +60,22 @@ You can also install as a site library via the Rakefile:
50
60
 
51
61
  == Source
52
62
 
53
- You can check out the current development source with Subversion from the
54
- following URL:
63
+ You can check out the current development source with Subversion from
64
+ the following URL:
55
65
 
56
66
  svn://deveiate.org/BlueCloth/trunk
57
67
 
58
- You can report bugs, suggest improvements, or check on development activity at
59
- the project page:
68
+ You can report bugs, suggest improvements, or check on development
69
+ activity at the project page:
60
70
 
61
71
  http://deveiate.org/projects/BlueCloth/
62
72
 
63
73
 
64
74
  == License
65
75
 
66
- See the LICENSE file included with the distribution for licensing and
76
+ See the LICENSE file included with the distribution for licensing and
67
77
  copyright details.
68
78
 
69
- The licensing terms of Discount are described in the LICENSE.discount file,
70
- also included with the distribution.
79
+ The licensing terms of Discount are described in the LICENSE.discount
80
+ file, also included with the distribution.
71
81
 
data/Rakefile CHANGED
@@ -44,6 +44,10 @@ PROJECT_NAME = 'BlueCloth'
44
44
  PKG_NAME = PROJECT_NAME.downcase
45
45
  PKG_SUMMARY = 'BlueCloth is a Ruby implementation of Markdown'
46
46
 
47
+ # Cruisecontrol stuff
48
+ CC_BUILD_LABEL = ENV['CC_BUILD_LABEL']
49
+ CC_BUILD_ARTIFACTS = ENV['CC_BUILD_ARTIFACTS'] || 'artifacts'
50
+
47
51
  VERSION_FILE = LIBDIR + 'bluecloth.rb'
48
52
  if VERSION_FILE.exist? && buildrev = ENV['CC_BUILD_LABEL']
49
53
  PKG_VERSION = VERSION_FILE.read[ /VERSION\s*=\s*['"](\d+\.\d+\.\d+)['"]/, 1 ] + '.' + buildrev
@@ -58,7 +62,7 @@ GEM_FILE_NAME = "#{PKG_FILE_NAME}.gem"
58
62
 
59
63
  EXTCONF = EXTDIR + 'extconf.rb'
60
64
 
61
- ARTIFACTS_DIR = Pathname.new( ENV['CC_BUILD_ARTIFACTS'] || 'artifacts' )
65
+ ARTIFACTS_DIR = Pathname.new( CC_BUILD_ARTIFACTS )
62
66
 
63
67
  TEXT_FILES = %w( Rakefile ChangeLog README LICENSE ).collect {|filename| BASEDIR + filename }
64
68
  BIN_FILES = Pathname.glob( "#{BINDIR}/*" ).delete_if {|item| item.to_s =~ /\.svn/ }
@@ -291,7 +295,7 @@ end
291
295
  desc "Cruisecontrol build"
292
296
  task :cruise => [:clean, 'spec:quiet', :package] do |task|
293
297
  raise "Artifacts dir not set." if ARTIFACTS_DIR.to_s.empty?
294
- artifact_dir = ARTIFACTS_DIR.cleanpath + ENV['CC_BUILD_LABEL']
298
+ artifact_dir = ARTIFACTS_DIR.cleanpath + (CC_BUILD_LABEL || Time.now.strftime('%Y%m%d-%T'))
295
299
  artifact_dir.mkpath
296
300
 
297
301
  coverage = BASEDIR + 'coverage'
data/ext/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.6
1
+ 1.4.0
data/ext/bluecloth.c CHANGED
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * BlueCloth -- a Ruby implementation of Markdown
3
- * $Id: bluecloth.c 107 2009-03-13 22:56:29Z deveiant $
3
+ * $Id: bluecloth.c 117 2009-05-14 15:21:03Z deveiant $
4
4
  *
5
5
  * = Authors
6
6
  *
@@ -327,7 +327,6 @@ void Init_bluecloth_ext( void ) {
327
327
  rb_define_attr( bluecloth_cBlueCloth, "options", 1, 0 );
328
328
 
329
329
  /* --- Constants ----- */
330
- /* special flags for markdown() and mkd_text() */
331
330
 
332
331
  /* Do not process `[]' and remove A tags from the output. */
333
332
  rb_define_const( bluecloth_cBlueCloth, "MKD_NOLINKS", INT2FIX(MKD_NOLINKS) );
@@ -344,7 +343,7 @@ void Init_bluecloth_ext( void ) {
344
343
  /* disable SUPERSCRIPT, RELAXED_EMPHASIS */
345
344
  rb_define_const( bluecloth_cBlueCloth, "MKD_STRICT", INT2FIX(MKD_STRICT) );
346
345
 
347
- /* don't expand `_` and `*` */
346
+ /* process text inside an html tag; no <em>, no <bold>, no html or [] expansion */
348
347
  rb_define_const( bluecloth_cBlueCloth, "MKD_TAGTEXT", INT2FIX(MKD_TAGTEXT) );
349
348
 
350
349
  /* don't allow pseudo-protocols */
@@ -359,7 +358,6 @@ void Init_bluecloth_ext( void ) {
359
358
  /* MKD_NOLINKS|MKD_NOIMAGE|MKD_TAGTEXT */
360
359
  rb_define_const( bluecloth_cBlueCloth, "MKD_EMBED", INT2FIX(MKD_EMBED) );
361
360
 
362
- /* -- special flags for mkd_in() and mkd_string() */
363
361
 
364
362
  /* don't process header blocks */
365
363
  rb_define_const( bluecloth_cBlueCloth, "MKD_NOHEADER", INT2FIX(MKD_NOHEADER) );
data/ext/cstring.h CHANGED
@@ -68,6 +68,7 @@ typedef STRING(char) Cstring;
68
68
 
69
69
  extern void Csputc(int, Cstring *);
70
70
  extern int Csprintf(Cstring *, char *, ...);
71
+ extern int Cswrite(Cstring *, char *, int);
71
72
  extern void Csreparse(Cstring *, char *, int, int);
72
73
 
73
74
  #endif/*_CSTRING_D*/
data/ext/generate.c CHANGED
@@ -410,6 +410,11 @@ linkyurl(MMIOT *f, int *sizep)
410
410
 
411
411
  ptr = cursor(f);
412
412
 
413
+ /* if I do (title:blah blah blah) embedded links, I need to subvert
414
+ * linkyurl to do a lookahead for the pseudo-protocol, then snarf
415
+ * up everything up to the terminating ')'
416
+ */
417
+
413
418
  if ( c == '<' ) {
414
419
  pull(f);
415
420
  ptr++;
@@ -1311,29 +1316,6 @@ display(Paragraph *p, MMIOT *f)
1311
1316
  }
1312
1317
 
1313
1318
 
1314
- /*
1315
- * dump out stylesheet sections.
1316
- */
1317
- static int
1318
- stylesheets(Paragraph *p, FILE *f)
1319
- {
1320
- Line* q;
1321
-
1322
- for ( ; p ; p = p->next ) {
1323
- if ( p->typ == STYLE ) {
1324
- for ( q = p->text; q ; q = q->next )
1325
- if ( fwrite(T(q->text), S(q->text), 1, f) == 1 )
1326
- putc('\n', f);
1327
- else
1328
- return EOF;
1329
- }
1330
- if ( p->down && (stylesheets(p->down, f) == EOF) )
1331
- return EOF;
1332
- }
1333
- return 0;
1334
- }
1335
-
1336
-
1337
1319
  /* return a pointer to the compiled markdown
1338
1320
  * document.
1339
1321
  */
@@ -1352,36 +1334,3 @@ mkd_document(Document *p, char **res)
1352
1334
  return EOF;
1353
1335
  }
1354
1336
 
1355
-
1356
- /* public interface for ___mkd_reparse()
1357
- */
1358
- int
1359
- mkd_text(char *bfr, int size, FILE *output, int flags)
1360
- {
1361
- MMIOT f;
1362
-
1363
- ___mkd_initmmiot(&f, 0);
1364
- f.flags = flags & USER_FLAGS;
1365
-
1366
- ___mkd_reparse(bfr, size, 0, &f);
1367
- ___mkd_emblock(&f);
1368
- if ( flags & CDATA_OUTPUT )
1369
- ___mkd_xml(T(f.out), S(f.out), output);
1370
- else
1371
- fwrite(T(f.out), S(f.out), 1, output);
1372
-
1373
- ___mkd_freemmiot(&f, 0);
1374
- return 0;
1375
- }
1376
-
1377
-
1378
- /* dump any embedded styles
1379
- */
1380
- int
1381
- mkd_style(Document *d, FILE *f)
1382
- {
1383
- if ( d && d->compiled )
1384
- return stylesheets(d->code, f);
1385
- return EOF;
1386
- }
1387
-
data/ext/markdown.h CHANGED
@@ -104,9 +104,15 @@ extern int mkd_firstnonblank(Line *);
104
104
  extern int mkd_compile(Document *, int);
105
105
  extern int mkd_document(Document *, char **);
106
106
  extern int mkd_generatehtml(Document *, FILE *);
107
- extern int mkd_style(Document *, FILE *);
107
+ extern int mkd_css(Document *, char **);
108
+ extern int mkd_generatecss(Document *, FILE *);
109
+ #define mkd_style mkd_generatecss
110
+ extern int mkd_xml(char *, int , char **);
111
+ extern int mkd_generatexml(char *, int, FILE *);
108
112
  extern void mkd_cleanup(Document *);
109
- extern int mkd_text(char *, int, FILE*, int);
113
+ extern int mkd_line(char *, int, char **, int);
114
+ extern int mkd_generateline(char *, int, FILE*, int);
115
+ #define mkd_text mkd_generateline
110
116
  extern void mkd_basename(Document*, char *);
111
117
  extern void mkd_string_to_anchor(char*,int, void(*)(int,void*), void*);
112
118
 
data/ext/mkdio.c CHANGED
@@ -193,7 +193,7 @@ mkd_generatehtml(Document *p, FILE *output)
193
193
 
194
194
  if ( (szdoc = mkd_document(p, &doc)) != EOF ) {
195
195
  if ( p->ctx->flags & CDATA_OUTPUT )
196
- ___mkd_xml(doc, szdoc, output);
196
+ mkd_generatexml(doc, szdoc, output);
197
197
  else
198
198
  fwrite(doc, szdoc, 1, output);
199
199
  putc('\n', output);
@@ -230,12 +230,74 @@ mkd_basename(Document *document, char *base)
230
230
  void
231
231
  mkd_string_to_anchor(char *s, int len, void(*outchar)(int,void*), void *out)
232
232
  {
233
- for ( ; len-- > 0; ++s ) {
234
- if ( *s == ' ' || *s == '&' || *s == '<' || *s == '"' )
233
+ unsigned char c;
234
+
235
+ for ( ; len-- > 0; ) {
236
+ c = *s++;
237
+ if ( c == ' ' || c == '&' || c == '<' || c == '"' )
235
238
  (*outchar)('+', out);
236
- else if ( isalnum(*s) || ispunct(*s) )
237
- (*outchar)(*s, out);
239
+ else if ( isalnum(c) || ispunct(c) || (c & 0x80) )
240
+ (*outchar)(c, out);
238
241
  else
239
242
  (*outchar)('~',out);
240
243
  }
241
244
  }
245
+
246
+
247
+ /* ___mkd_reparse() a line
248
+ */
249
+ static void
250
+ mkd_parse_line(char *bfr, int size, MMIOT *f, int flags)
251
+ {
252
+ ___mkd_initmmiot(f, 0);
253
+ f->flags = flags & USER_FLAGS;
254
+ ___mkd_reparse(bfr, size, 0, f);
255
+ ___mkd_emblock(f);
256
+ }
257
+
258
+
259
+ /* ___mkd_reparse() a line, returning it in malloc()ed memory
260
+ */
261
+ int
262
+ mkd_line(char *bfr, int size, char **res, int flags)
263
+ {
264
+ MMIOT f;
265
+ int len;
266
+
267
+ mkd_parse_line(bfr, size, &f, flags);
268
+
269
+ if ( len = S(f.out) ) {
270
+ /* kludge alert; we know that T(f.out) is malloced memory,
271
+ * so we can just steal it away. This is awful -- there
272
+ * should be an opaque method that transparently moves
273
+ * the pointer out of the embedded Cstring.
274
+ */
275
+ *res = T(f.out);
276
+ T(f.out) = 0;
277
+ S(f.out) = 0;
278
+ }
279
+ else {
280
+ *res = 0;
281
+ len = EOF;
282
+ }
283
+ ___mkd_freemmiot(&f, 0);
284
+ return len;
285
+ }
286
+
287
+
288
+ /* ___mkd_reparse() a line, writing it to a FILE
289
+ */
290
+ int
291
+ mkd_generateline(char *bfr, int size, FILE *output, int flags)
292
+ {
293
+ MMIOT f;
294
+
295
+ mkd_parse_line(bfr, size, &f, flags);
296
+ if ( flags & CDATA_OUTPUT )
297
+ mkd_generatexml(T(f.out), S(f.out), output);
298
+ else
299
+ fwrite(T(f.out), S(f.out), 1, output);
300
+
301
+ ___mkd_freemmiot(&f, 0);
302
+ return 0;
303
+ }
data/ext/mkdio.h CHANGED
@@ -15,19 +15,15 @@ void mkd_basename(MMIOT*,char*);
15
15
  /* compilation, debugging, cleanup
16
16
  */
17
17
  int mkd_compile(MMIOT*, int);
18
- int mkd_generatehtml(MMIOT*,FILE*);
19
- int mkd_generatetoc(MMIOT*,FILE*);
20
- int mkd_xhtmlpage(MMIOT*,int,FILE*);
21
18
  int mkd_cleanup(MMIOT*);
22
19
 
23
20
  /* markup functions
24
21
  */
25
- int mkd_text(char *, int, FILE*, int);
26
- int mkd_style(MMIOT*, FILE*);
27
22
  int mkd_dump(MMIOT*, FILE*, int, char*);
28
23
  int markdown(MMIOT*, FILE*, int);
29
- void mkd_basename(MMIOT*,char*);
24
+ int mkd_line(char *, int, char **, int);
30
25
  void mkd_string_to_anchor(char *, int, int (*)(int,void*), void*);
26
+ int mkd_xhtmlpage(MMIOT*,int,FILE*);
31
27
 
32
28
  /* header block access
33
29
  */
@@ -38,6 +34,19 @@ char* mkd_doc_date(MMIOT*);
38
34
  /* compiled data access
39
35
  */
40
36
  int mkd_document(MMIOT*, char**);
37
+ int mkd_toc(MMIOT*, char**);
38
+ int mkd_css(MMIOT*, char **);
39
+ int mkd_xml(char *, int, char **);
40
+
41
+ /* write-to-file functions
42
+ */
43
+ int mkd_generatehtml(MMIOT*,FILE*);
44
+ int mkd_generatetoc(MMIOT*,FILE*);
45
+ int mkd_generatexml(char *, int,FILE*);
46
+ int mkd_generatecss(MMIOT*,FILE*);
47
+ #define mkd_style mkd_generatecss
48
+ int mkd_generateline(char *, int, FILE*, int);
49
+ #define mkd_text mkd_generateline
41
50
 
42
51
  /* version#.
43
52
  */
@@ -50,7 +59,8 @@ extern char markdown_version[];
50
59
  #define MKD_NOPANTS 0x0004 /* don't run smartypants() */
51
60
  #define MKD_NOHTML 0x0008 /* don't allow raw html through AT ALL */
52
61
  #define MKD_STRICT 0x0010 /* disable SUPERSCRIPT, RELAXED_EMPHASIS */
53
- #define MKD_TAGTEXT 0x0020 /* don't expand `_` and `*` */
62
+ #define MKD_TAGTEXT 0x0020 /* process text inside an html tag; no
63
+ * <em>, no <bold>, no html or [] expansion */
54
64
  #define MKD_NO_EXT 0x0040 /* don't allow pseudo-protocols */
55
65
  #define MKD_CDATA 0x0080 /* generate code for xml ![CDATA[...]] */
56
66
  #define MKD_TOC 0x1000 /* do table-of-contents processing */
data/ext/resource.c CHANGED
@@ -145,25 +145,3 @@ mkd_cleanup(Document *doc)
145
145
  free(doc);
146
146
  }
147
147
  }
148
-
149
-
150
- /* write output in XML format
151
- */
152
- void
153
- ___mkd_xml(char *p, int size, FILE *out)
154
- {
155
- char c;
156
-
157
- while ( size-- > 0 ) {
158
- if ( !isascii(c = *p++) )
159
- continue;
160
- switch (c) {
161
- case '<': fputs("&lt;", out); break;
162
- case '>': fputs("&gt;", out); break;
163
- case '&': fputs("&amp;", out); break;
164
- case '"': fputs("&quot;", out); break;
165
- case '\'':fputs("&apos;", out); break;
166
- default: putc(c,out); break;
167
- }
168
- }
169
- }
data/lib/bluecloth.rb CHANGED
@@ -18,7 +18,7 @@
18
18
  #
19
19
  # == Version
20
20
  #
21
- # $Id: bluecloth.rb 115 2009-04-29 13:12:34Z deveiant $
21
+ # $Id: bluecloth.rb 118 2009-05-14 15:26:02Z deveiant $
22
22
  #
23
23
  # == License
24
24
  #
@@ -29,13 +29,13 @@
29
29
  class BlueCloth
30
30
 
31
31
  # Release Version
32
- VERSION = '2.0.1'
32
+ VERSION = '2.0.2'
33
33
 
34
34
  # SVN Revision
35
- SVNREV = %q$Rev: 115 $
35
+ SVNREV = %q$Rev: 118 $
36
36
 
37
37
  # SVN Id tag
38
- SVNID = %q$Id: bluecloth.rb 115 2009-04-29 13:12:34Z deveiant $
38
+ SVNID = %q$Id: bluecloth.rb 118 2009-05-14 15:26:02Z deveiant $
39
39
 
40
40
  # The defaults for all supported options.
41
41
  DEFAULT_OPTIONS = {
@@ -52,7 +52,7 @@ class BlueCloth
52
52
  # The number of characters of the original markdown source to include in the
53
53
  # output of #inspect
54
54
  INSPECT_TEXT_LENGTH = 50
55
-
55
+
56
56
 
57
57
  #################################################################
58
58
  ### C L A S S M E T H O D S
@@ -84,6 +84,7 @@ class BlueCloth
84
84
  if opthash[:mdtest_1_compat] then flags |= MKD_1_COMPAT; end
85
85
  if opthash[:escape_html] then flags |= MKD_NOHTML; end
86
86
  if opthash[:strict_mode] then flags |= MKD_STRICT; end
87
+ if opthash[:tagtext_mode] then flags |= MKD_TAGTEXT; end
87
88
 
88
89
  return flags
89
90
  end
@@ -92,7 +93,7 @@ class BlueCloth
92
93
  ### Returns a Hash that reflects the settings from the specified +flags+ Integer.
93
94
  def self::opthash_from_flags( flags=0 )
94
95
  flags = flags.to_i
95
-
96
+
96
97
  opthash = {}
97
98
  if ( flags & MKD_NOLINKS ).nonzero? then opthash[:remove_links] = true; end
98
99
  if ( flags & MKD_NOIMAGE ).nonzero? then opthash[:remove_images] = true; end
@@ -103,6 +104,7 @@ class BlueCloth
103
104
  if ( flags & MKD_1_COMPAT ).nonzero? then opthash[:mdtest_1_compat] = true; end
104
105
  if ( flags & MKD_NOHTML ).nonzero? then opthash[:escape_html] = true; end
105
106
  if ( flags & MKD_STRICT ).nonzero? then opthash[:strict_mode] = true; end
107
+ if ( flags & MKD_TAGTEXT ).nonzero? then opthash[:tagtext_mode] = true; end
106
108
 
107
109
  return opthash
108
110
  end
@@ -130,8 +132,8 @@ class BlueCloth
130
132
  def filter_html
131
133
  return self.options[:escape_html]
132
134
  end
133
-
134
-
135
+
136
+
135
137
  ### Backward-compatible method: raises an appropriate error notifying the user that
136
138
  ### BlueCloth2 doesn't support this option.
137
139
  def filter_html=( arg )
@@ -140,8 +142,8 @@ class BlueCloth
140
142
  "via #filter_html=. You now must create the BlueCloth object with the :escape_html" +
141
143
  "option set to true instead."
142
144
  end
143
-
144
-
145
+
146
+
145
147
 
146
148
  end # class BlueCloth
147
149