bluecloth 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/ChangeLog +629 -0
- data/LICENSE +27 -0
- data/LICENSE.discount +47 -0
- data/README +71 -0
- data/Rakefile +319 -0
- data/Rakefile.local +63 -0
- data/bin/bluecloth +84 -0
- data/ext/VERSION +1 -0
- data/ext/amalloc.h +29 -0
- data/ext/bluecloth.c +373 -0
- data/ext/config.h +47 -0
- data/ext/cstring.h +73 -0
- data/ext/docheader.c +43 -0
- data/ext/extconf.rb +45 -0
- data/ext/generate.c +1387 -0
- data/ext/markdown.c +939 -0
- data/ext/markdown.h +135 -0
- data/ext/mkdio.c +241 -0
- data/ext/mkdio.h +66 -0
- data/ext/resource.c +169 -0
- data/ext/version.c +28 -0
- data/lib/bluecloth.rb +148 -0
- data/rake/191_compat.rb +26 -0
- data/rake/dependencies.rb +76 -0
- data/rake/helpers.rb +412 -0
- data/rake/manual.rb +782 -0
- data/rake/packaging.rb +116 -0
- data/rake/publishing.rb +321 -0
- data/rake/rdoc.rb +40 -0
- data/rake/style.rb +62 -0
- data/rake/svn.rb +639 -0
- data/rake/testing.rb +204 -0
- data/rake/verifytask.rb +64 -0
- data/rake/win32.rb +186 -0
- data/spec/bluecloth/101_changes_spec.rb +141 -0
- data/spec/bluecloth/autolinks_spec.rb +49 -0
- data/spec/bluecloth/blockquotes_spec.rb +143 -0
- data/spec/bluecloth/code_spans_spec.rb +164 -0
- data/spec/bluecloth/emphasis_spec.rb +164 -0
- data/spec/bluecloth/entities_spec.rb +65 -0
- data/spec/bluecloth/hrules_spec.rb +90 -0
- data/spec/bluecloth/images_spec.rb +92 -0
- data/spec/bluecloth/inline_html_spec.rb +238 -0
- data/spec/bluecloth/links_spec.rb +171 -0
- data/spec/bluecloth/lists_spec.rb +294 -0
- data/spec/bluecloth/paragraphs_spec.rb +75 -0
- data/spec/bluecloth/titles_spec.rb +305 -0
- data/spec/bluecloth_spec.rb +209 -0
- data/spec/bugfix_spec.rb +123 -0
- data/spec/contributions_spec.rb +85 -0
- data/spec/data/antsugar.txt +34 -0
- data/spec/data/markdowntest/Amps and angle encoding.html +17 -0
- data/spec/data/markdowntest/Amps and angle encoding.text +21 -0
- data/spec/data/markdowntest/Auto links.html +18 -0
- data/spec/data/markdowntest/Auto links.text +13 -0
- data/spec/data/markdowntest/Backslash escapes.html +118 -0
- data/spec/data/markdowntest/Backslash escapes.text +120 -0
- data/spec/data/markdowntest/Blockquotes with code blocks.html +15 -0
- data/spec/data/markdowntest/Blockquotes with code blocks.text +11 -0
- data/spec/data/markdowntest/Code Blocks.html +18 -0
- data/spec/data/markdowntest/Code Blocks.text +14 -0
- data/spec/data/markdowntest/Code Spans.html +5 -0
- data/spec/data/markdowntest/Code Spans.text +5 -0
- data/spec/data/markdowntest/Hard-wrapped paragraphs with list-like lines.html +8 -0
- data/spec/data/markdowntest/Hard-wrapped paragraphs with list-like lines.text +8 -0
- data/spec/data/markdowntest/Horizontal rules.html +71 -0
- data/spec/data/markdowntest/Horizontal rules.text +67 -0
- data/spec/data/markdowntest/Inline HTML (Advanced).html +15 -0
- data/spec/data/markdowntest/Inline HTML (Advanced).text +15 -0
- data/spec/data/markdowntest/Inline HTML (Simple).html +72 -0
- data/spec/data/markdowntest/Inline HTML (Simple).text +69 -0
- data/spec/data/markdowntest/Inline HTML comments.html +13 -0
- data/spec/data/markdowntest/Inline HTML comments.text +13 -0
- data/spec/data/markdowntest/Links, inline style.html +11 -0
- data/spec/data/markdowntest/Links, inline style.text +12 -0
- data/spec/data/markdowntest/Links, reference style.html +52 -0
- data/spec/data/markdowntest/Links, reference style.text +71 -0
- data/spec/data/markdowntest/Links, shortcut references.html +9 -0
- data/spec/data/markdowntest/Links, shortcut references.text +20 -0
- data/spec/data/markdowntest/Literal quotes in titles.html +3 -0
- data/spec/data/markdowntest/Literal quotes in titles.text +7 -0
- data/spec/data/markdowntest/Markdown Documentation - Basics.html +314 -0
- data/spec/data/markdowntest/Markdown Documentation - Basics.text +306 -0
- data/spec/data/markdowntest/Markdown Documentation - Syntax.html +942 -0
- data/spec/data/markdowntest/Markdown Documentation - Syntax.text +888 -0
- data/spec/data/markdowntest/Nested blockquotes.html +9 -0
- data/spec/data/markdowntest/Nested blockquotes.text +5 -0
- data/spec/data/markdowntest/Ordered and unordered lists.html +148 -0
- data/spec/data/markdowntest/Ordered and unordered lists.text +131 -0
- data/spec/data/markdowntest/Strong and em together.html +7 -0
- data/spec/data/markdowntest/Strong and em together.text +7 -0
- data/spec/data/markdowntest/Tabs.html +25 -0
- data/spec/data/markdowntest/Tabs.text +21 -0
- data/spec/data/markdowntest/Tidyness.html +8 -0
- data/spec/data/markdowntest/Tidyness.text +5 -0
- data/spec/data/ml-announce.txt +17 -0
- data/spec/data/re-overflow.txt +67 -0
- data/spec/data/re-overflow2.txt +281 -0
- data/spec/lib/constants.rb +5 -0
- data/spec/lib/helpers.rb +137 -0
- data/spec/lib/matchers.rb +235 -0
- data/spec/markdowntest_spec.rb +76 -0
- metadata +305 -0
data/Rakefile.local
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
#!rake
|
2
|
+
|
3
|
+
# C extension constants
|
4
|
+
EXT_MAKEFILE = EXTDIR + 'Makefile'
|
5
|
+
EXT_SOURCES = FileList[ EXTDIR + '*.c' ]
|
6
|
+
EXT_SO = EXTDIR + "bluecloth_ext.#{CONFIG['DLEXT']}"
|
7
|
+
|
8
|
+
GEMSPEC.extra_rdoc_files << 'LICENSE.discount'
|
9
|
+
DOCFILES << 'LICENSE.discount'
|
10
|
+
|
11
|
+
|
12
|
+
#####################################################################
|
13
|
+
### T A S K S
|
14
|
+
#####################################################################
|
15
|
+
|
16
|
+
# Make both the default task and the spec task depend on building the extension
|
17
|
+
task :local => :build
|
18
|
+
task :spec => :build
|
19
|
+
namespace :spec do
|
20
|
+
task :doc => [ :build ]
|
21
|
+
task :quiet => [ :build ]
|
22
|
+
task :html => [ :build ]
|
23
|
+
task :text => [ :build ]
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "Make the Makefile for the C extension"
|
27
|
+
file EXT_MAKEFILE.to_s => EXT_SOURCES do
|
28
|
+
log "Configuring BlueCloth C extension"
|
29
|
+
in_subdirectory( EXTDIR ) do
|
30
|
+
ruby 'extconf.rb'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
CLOBBER.include( EXTDIR + 'mkmf.log', EXTDIR + 'conftest.dSYM', EXT_SO )
|
34
|
+
|
35
|
+
desc "Build the C extension"
|
36
|
+
task :build => EXT_SO
|
37
|
+
file EXT_SO => [ EXT_MAKEFILE.to_s, *EXT_SOURCES ] do
|
38
|
+
in_subdirectory( EXTDIR ) do
|
39
|
+
sh 'make'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "Rebuild the C extension"
|
44
|
+
task :rebuild => [ :clobber, :build ]
|
45
|
+
|
46
|
+
|
47
|
+
task :clean do
|
48
|
+
if EXT_MAKEFILE.exist?
|
49
|
+
in_subdirectory( EXTDIR ) do
|
50
|
+
sh 'make clean'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
task :clobber do
|
56
|
+
if EXT_MAKEFILE.exist?
|
57
|
+
in_subdirectory( EXTDIR ) do
|
58
|
+
sh 'make distclean'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
CLOBBER.include( EXT_MAKEFILE )
|
63
|
+
|
data/bin/bluecloth
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# = bluecloth
|
4
|
+
#
|
5
|
+
# Format one or more text files with the markdown formatter.
|
6
|
+
#
|
7
|
+
# = Synopsis
|
8
|
+
#
|
9
|
+
# bluecloth [OPTIONS] [FILES]
|
10
|
+
#
|
11
|
+
#
|
12
|
+
#
|
13
|
+
|
14
|
+
BEGIN {
|
15
|
+
require 'bluecloth'
|
16
|
+
require 'optparse'
|
17
|
+
}
|
18
|
+
|
19
|
+
DocumentWrapper = %{
|
20
|
+
<html>
|
21
|
+
<head><title>%s</title></head>
|
22
|
+
<body>
|
23
|
+
%s
|
24
|
+
</body>
|
25
|
+
</html>
|
26
|
+
}
|
27
|
+
|
28
|
+
def main
|
29
|
+
fragment = false
|
30
|
+
destination = '.'
|
31
|
+
|
32
|
+
ARGV.options do |oparser|
|
33
|
+
|
34
|
+
oparser.banner = "Usage: #$0 [OPTIONS] FILES"
|
35
|
+
|
36
|
+
# Debug mode
|
37
|
+
oparser.on( "--debug", "-d", TrueClass, "Turn debugging output on" ) {
|
38
|
+
$DEBUG = true
|
39
|
+
}
|
40
|
+
|
41
|
+
# 'Fragment' mode
|
42
|
+
oparser.on( "--fragment", "-f", TrueClass,
|
43
|
+
"Output HTML fragments instead of whole documents" ) {
|
44
|
+
fragment = true
|
45
|
+
}
|
46
|
+
|
47
|
+
# Output destination
|
48
|
+
#oparser.on( "--output=DESTINATION", "-o DESTINATION", String,
|
49
|
+
# "Write output to DESTINATION instead of the current directory" ) {|arg|
|
50
|
+
# destination = arg
|
51
|
+
#}
|
52
|
+
|
53
|
+
oparser.parse!
|
54
|
+
end
|
55
|
+
|
56
|
+
# Filter mode if no arguments
|
57
|
+
ARGV.push( "-" ) if ARGV.empty?
|
58
|
+
|
59
|
+
ARGV.each {|file|
|
60
|
+
if file == '-'
|
61
|
+
contents = $stdin.read
|
62
|
+
else
|
63
|
+
contents = File::read( file )
|
64
|
+
end
|
65
|
+
|
66
|
+
bc = BlueCloth::new( contents )
|
67
|
+
$stderr.puts "Using BlueCloth version #{BlueCloth::VERSION}"
|
68
|
+
|
69
|
+
if fragment
|
70
|
+
$stdout.puts bc.to_html
|
71
|
+
else
|
72
|
+
$stdout.puts DocumentWrapper % [ file, bc.to_html ]
|
73
|
+
end
|
74
|
+
}
|
75
|
+
|
76
|
+
rescue => err
|
77
|
+
$stderr.puts "Aborting: Fatal error: %s" % err.message
|
78
|
+
exit 255
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
main
|
84
|
+
|
data/ext/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.3.4
|
data/ext/amalloc.h
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
/*
|
2
|
+
* debugging malloc()/realloc()/calloc()/free() that attempts
|
3
|
+
* to keep track of just what's been allocated today.
|
4
|
+
*/
|
5
|
+
#ifndef AMALLOC_D
|
6
|
+
#define AMALLOC_D
|
7
|
+
|
8
|
+
#include "config.h"
|
9
|
+
|
10
|
+
#ifdef USE_AMALLOC
|
11
|
+
|
12
|
+
extern void *amalloc(int);
|
13
|
+
extern void *acalloc(int,int);
|
14
|
+
extern void *arealloc(void*,int);
|
15
|
+
extern void afree(void*);
|
16
|
+
extern void adump();
|
17
|
+
|
18
|
+
#define malloc amalloc
|
19
|
+
#define calloc acalloc
|
20
|
+
#define realloc arealloc
|
21
|
+
#define free afree
|
22
|
+
|
23
|
+
#else
|
24
|
+
|
25
|
+
#define adump() (void)1
|
26
|
+
|
27
|
+
#endif
|
28
|
+
|
29
|
+
#endif/*AMALLOC_D*/
|
data/ext/bluecloth.c
ADDED
@@ -0,0 +1,373 @@
|
|
1
|
+
/*
|
2
|
+
* BlueCloth -- a Ruby implementation of Markdown
|
3
|
+
* $Id: bluecloth.c 107 2009-03-13 22:56:29Z deveiant $
|
4
|
+
*
|
5
|
+
* = Authors
|
6
|
+
*
|
7
|
+
* - Michael Granger <ged@FaerieMUD.org>
|
8
|
+
*
|
9
|
+
* BlueCloth 2 is mostly just a wrapper around the Discount library
|
10
|
+
* written by David Loren Parsons <http://www.pell.portland.or.us/~orc>.
|
11
|
+
*
|
12
|
+
* = License
|
13
|
+
*
|
14
|
+
* Discount:
|
15
|
+
* Copyright (C) 2007 David Loren Parsons. All rights reserved.
|
16
|
+
*
|
17
|
+
* The Discount library is used under the licensing terms outlined in the
|
18
|
+
* COPYRIGHT.discount file included in the distribution.
|
19
|
+
*
|
20
|
+
* Ruby bits:
|
21
|
+
* See the LICENSE file included in the distribution.
|
22
|
+
*
|
23
|
+
*/
|
24
|
+
|
25
|
+
#include "mkdio.h"
|
26
|
+
#include "ruby.h"
|
27
|
+
|
28
|
+
VALUE bluecloth_cBlueCloth;
|
29
|
+
VALUE bluecloth_default_opthash;
|
30
|
+
|
31
|
+
|
32
|
+
/* Get a Discount document for the specified text */
|
33
|
+
static MMIOT *
|
34
|
+
bluecloth_alloc( VALUE text, int flags ) {
|
35
|
+
MMIOT *document;
|
36
|
+
|
37
|
+
document = mkd_string( RSTRING_PTR(text), RSTRING_LEN(text), flags );
|
38
|
+
if ( !document )
|
39
|
+
rb_raise( rb_eRuntimeError, "Failed to create a BlueCloth object for: %s", RSTRING_PTR(text) );
|
40
|
+
|
41
|
+
return document;
|
42
|
+
}
|
43
|
+
|
44
|
+
|
45
|
+
/*
|
46
|
+
* GC Free function
|
47
|
+
*/
|
48
|
+
static void
|
49
|
+
bluecloth_gc_free( MMIOT *document ) {
|
50
|
+
if ( document ) {
|
51
|
+
mkd_cleanup( document );
|
52
|
+
document = NULL;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
|
57
|
+
/* --------------------------------------------------------------
|
58
|
+
* Utility functions
|
59
|
+
* -------------------------------------------------------------- */
|
60
|
+
|
61
|
+
#ifdef HAVE_STDARG_PROTOTYPES
|
62
|
+
#include <stdarg.h>
|
63
|
+
void
|
64
|
+
bluecloth_debug(const char *fmt, ...)
|
65
|
+
#else
|
66
|
+
#include <varargs.h>
|
67
|
+
void
|
68
|
+
bluecloth_debug( fmt, va_alist )
|
69
|
+
const char *fmt;
|
70
|
+
va_dcl
|
71
|
+
#endif
|
72
|
+
{
|
73
|
+
char buf[BUFSIZ], buf2[BUFSIZ];
|
74
|
+
va_list args;
|
75
|
+
|
76
|
+
if (!RTEST(ruby_debug)) return;
|
77
|
+
|
78
|
+
snprintf( buf, BUFSIZ, "Debug>>> %s", fmt );
|
79
|
+
|
80
|
+
#ifdef HAVE_STDARG_PROTOTYPES
|
81
|
+
va_start( args, fmt );
|
82
|
+
#else
|
83
|
+
va_start( args );
|
84
|
+
#endif
|
85
|
+
vsnprintf( buf2, BUFSIZ, buf, args );
|
86
|
+
fputs( buf2, stderr );
|
87
|
+
fputs( "\n", stderr );
|
88
|
+
fflush( stderr );
|
89
|
+
va_end( args );
|
90
|
+
}
|
91
|
+
|
92
|
+
|
93
|
+
/*
|
94
|
+
* Object validity checker. Returns the data pointer.
|
95
|
+
*/
|
96
|
+
static MMIOT *
|
97
|
+
bluecloth_check_ptr( VALUE self ) {
|
98
|
+
Check_Type( self, T_DATA );
|
99
|
+
|
100
|
+
if ( !rb_obj_is_kind_of(self, bluecloth_cBlueCloth) ) {
|
101
|
+
rb_raise( rb_eTypeError, "wrong argument type %s (expected BlueCloth object)",
|
102
|
+
rb_class2name(CLASS_OF( self )) );
|
103
|
+
}
|
104
|
+
|
105
|
+
return DATA_PTR( self );
|
106
|
+
}
|
107
|
+
|
108
|
+
|
109
|
+
/*
|
110
|
+
* Fetch the data pointer and check it for sanity.
|
111
|
+
*/
|
112
|
+
static MMIOT *
|
113
|
+
bluecloth_get_ptr( VALUE self ) {
|
114
|
+
MMIOT *ptr = bluecloth_check_ptr( self );
|
115
|
+
|
116
|
+
if ( !ptr )
|
117
|
+
rb_fatal( "Use of uninitialized BlueCloth object" );
|
118
|
+
|
119
|
+
return ptr;
|
120
|
+
}
|
121
|
+
|
122
|
+
|
123
|
+
/* --------------------------------------------------------------
|
124
|
+
* Class methods
|
125
|
+
* -------------------------------------------------------------- */
|
126
|
+
|
127
|
+
/*
|
128
|
+
* call-seq:
|
129
|
+
* BlueCloth.allocate -> object
|
130
|
+
*
|
131
|
+
* Allocate a new BlueCloth object.
|
132
|
+
*
|
133
|
+
*/
|
134
|
+
static VALUE
|
135
|
+
bluecloth_s_allocate( VALUE klass ) {
|
136
|
+
return Data_Wrap_Struct( klass, NULL, bluecloth_gc_free, 0 );
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
/*
|
141
|
+
* call-seq:
|
142
|
+
* BlueCloth.discount_version -> string
|
143
|
+
*
|
144
|
+
* Return the version string of the Discount library BlueCloth was built on.
|
145
|
+
*
|
146
|
+
*/
|
147
|
+
static VALUE
|
148
|
+
bluecloth_s_discount_version( VALUE klass ) {
|
149
|
+
return rb_str_new2( markdown_version );
|
150
|
+
}
|
151
|
+
|
152
|
+
/* --------------------------------------------------------------
|
153
|
+
* Instance methods
|
154
|
+
* -------------------------------------------------------------- */
|
155
|
+
|
156
|
+
/*
|
157
|
+
* call-seq:
|
158
|
+
* BlueCloth.new( string='', options=DEFAULT_OPTIONS ) -> object
|
159
|
+
*
|
160
|
+
* Create a new BlueCloth object that will process the given +string+. The +options+
|
161
|
+
* argument is a Hash that can be used to control the generated markup, and to
|
162
|
+
* enable/disable extensions. The supported options are:
|
163
|
+
*
|
164
|
+
* [:remove_links]
|
165
|
+
* Ignore links in Markdown, and escape A tags in the output. Defaults to +false+.
|
166
|
+
* [:remove_images]
|
167
|
+
* Ignore images in Markdown, and escape IMG tags in the output. Defaults to +false+.
|
168
|
+
* [:smartypants]
|
169
|
+
* Do Smartypants-style mangling of quotes, dashes, or ellipses. Defaults to +true+.
|
170
|
+
* [:pseudoprotocols]
|
171
|
+
* Support Discount's pseudo-protocol links. Defaults to +false+.
|
172
|
+
* [:pandoc_headers]
|
173
|
+
* Support the extraction of
|
174
|
+
* {Pandoc headers}[http://johnmacfarlane.net/pandoc/README.html#title-blocks], which
|
175
|
+
* can be fetched as a Hash via the #header method. Defaults to +false+.
|
176
|
+
* [:header_labels]
|
177
|
+
* Generate ID attributes for all headers. Defaults to +false+.
|
178
|
+
* [:escape_html]
|
179
|
+
* Escape all HTML in the input string. Defaults to +false+.
|
180
|
+
* [:strict_mode]
|
181
|
+
* Disables Discount's relaxed emphasis (ignores underscores in the middle of words) and
|
182
|
+
* superscript notation. Defaults to +true+.
|
183
|
+
*
|
184
|
+
*/
|
185
|
+
static VALUE
|
186
|
+
bluecloth_initialize( int argc, VALUE *argv, VALUE self ) {
|
187
|
+
if ( !bluecloth_check_ptr(self) ) {
|
188
|
+
MMIOT *document;
|
189
|
+
VALUE text, textcopy, optflags, fullhash, opthash = Qnil;
|
190
|
+
int flags = 0;
|
191
|
+
|
192
|
+
rb_scan_args( argc, argv, "02", &text, &opthash );
|
193
|
+
|
194
|
+
/* Default empty string and options */
|
195
|
+
if ( argc == 0 ) {
|
196
|
+
text = rb_str_new( "", 0 );
|
197
|
+
}
|
198
|
+
|
199
|
+
/* One arg could be either the text or the opthash, so shift the args if appropriate */
|
200
|
+
else if ( argc == 1 && (TYPE(text) == T_HASH || TYPE(text) == T_FIXNUM) ) {
|
201
|
+
opthash = text;
|
202
|
+
text = rb_str_new( "", 0 );
|
203
|
+
}
|
204
|
+
|
205
|
+
/* Merge the options hash with the defaults and turn it into a flags int */
|
206
|
+
if ( NIL_P(opthash) ) opthash = rb_hash_new();
|
207
|
+
optflags = rb_funcall( bluecloth_cBlueCloth, rb_intern("flags_from_opthash"), 1, opthash );
|
208
|
+
fullhash = rb_funcall( bluecloth_cBlueCloth, rb_intern("opthash_from_flags"), 1, optflags );
|
209
|
+
|
210
|
+
flags = NUM2INT( optflags );
|
211
|
+
DATA_PTR( self ) = document = bluecloth_alloc( text, flags );
|
212
|
+
if ( !mkd_compile(document, flags) )
|
213
|
+
rb_raise( rb_eRuntimeError, "Failed to compile markdown" );
|
214
|
+
|
215
|
+
textcopy = rb_str_dup( text );
|
216
|
+
OBJ_FREEZE( textcopy );
|
217
|
+
rb_iv_set( self, "@text", textcopy );
|
218
|
+
OBJ_FREEZE( fullhash );
|
219
|
+
rb_iv_set( self, "@options", fullhash );
|
220
|
+
|
221
|
+
OBJ_INFECT( self, text );
|
222
|
+
}
|
223
|
+
|
224
|
+
return self;
|
225
|
+
}
|
226
|
+
|
227
|
+
|
228
|
+
/*
|
229
|
+
* call-seq:
|
230
|
+
* bluecloth.to_html -> string
|
231
|
+
*
|
232
|
+
* Transform the document into HTML.
|
233
|
+
*
|
234
|
+
*/
|
235
|
+
static VALUE
|
236
|
+
bluecloth_to_html( VALUE self ) {
|
237
|
+
MMIOT *document = bluecloth_get_ptr( self );
|
238
|
+
char *output;
|
239
|
+
int length;
|
240
|
+
VALUE result = Qnil;
|
241
|
+
|
242
|
+
bluecloth_debug( "Compiling document %p", document );
|
243
|
+
|
244
|
+
if ( (length = mkd_document( document, &output )) != EOF ) {
|
245
|
+
bluecloth_debug( "Pointer to results: %p, length = %d", output, length );
|
246
|
+
result = rb_str_new( output, length );
|
247
|
+
|
248
|
+
OBJ_INFECT( result, self );
|
249
|
+
return result;
|
250
|
+
} else {
|
251
|
+
return Qnil;
|
252
|
+
}
|
253
|
+
}
|
254
|
+
|
255
|
+
|
256
|
+
char * (*header_functions[3])(MMIOT *) = {
|
257
|
+
mkd_doc_title,
|
258
|
+
mkd_doc_author,
|
259
|
+
mkd_doc_date
|
260
|
+
};
|
261
|
+
|
262
|
+
/*
|
263
|
+
* call-seq:
|
264
|
+
* bluecloth.header -> hash
|
265
|
+
*
|
266
|
+
* Return the hash of
|
267
|
+
* {Pandoc-style headers}[http://johnmacfarlane.net/pandoc/README.html#title-blocks]
|
268
|
+
* from the parsed document. If there were no headers, or the BlueCloth object was not
|
269
|
+
* constructed with the :pandoc_headers option enabled, an empty Hash is returned.
|
270
|
+
*
|
271
|
+
* markdown = "%title My Essay\n%author Me\n%date Today\n\nSome stuff..."
|
272
|
+
* bc = BlueCloth.new( markdown, :pandoc_headers => true )
|
273
|
+
* # =>
|
274
|
+
* bc.header
|
275
|
+
* # =>
|
276
|
+
*/
|
277
|
+
static VALUE
|
278
|
+
bluecloth_header( VALUE self ) {
|
279
|
+
MMIOT *document = bluecloth_get_ptr( self );
|
280
|
+
char *field;
|
281
|
+
VALUE fieldstring, headers = rb_hash_new();
|
282
|
+
|
283
|
+
bluecloth_debug( "Fetching pandoc headers for document %p", document );
|
284
|
+
|
285
|
+
if ( (field = mkd_doc_title(document)) ) {
|
286
|
+
fieldstring = rb_str_new2( field );
|
287
|
+
OBJ_INFECT( fieldstring, self );
|
288
|
+
rb_hash_aset( headers, ID2SYM(rb_intern("title")), fieldstring );
|
289
|
+
}
|
290
|
+
if ( (field = mkd_doc_author(document)) ) {
|
291
|
+
fieldstring = rb_str_new2( field );
|
292
|
+
OBJ_INFECT( fieldstring, self );
|
293
|
+
rb_hash_aset( headers, ID2SYM(rb_intern("author")), fieldstring );
|
294
|
+
}
|
295
|
+
if ( (field = mkd_doc_date(document)) ) {
|
296
|
+
fieldstring = rb_str_new2( field );
|
297
|
+
OBJ_INFECT( fieldstring, self );
|
298
|
+
rb_hash_aset( headers, ID2SYM(rb_intern("date")), fieldstring );
|
299
|
+
}
|
300
|
+
|
301
|
+
return headers;
|
302
|
+
}
|
303
|
+
|
304
|
+
|
305
|
+
|
306
|
+
/* --------------------------------------------------------------
|
307
|
+
* Initializer
|
308
|
+
* -------------------------------------------------------------- */
|
309
|
+
|
310
|
+
void Init_bluecloth_ext( void ) {
|
311
|
+
bluecloth_cBlueCloth = rb_define_class( "BlueCloth", rb_cObject );
|
312
|
+
|
313
|
+
rb_define_alloc_func( bluecloth_cBlueCloth, bluecloth_s_allocate );
|
314
|
+
rb_define_singleton_method( bluecloth_cBlueCloth, "discount_version",
|
315
|
+
bluecloth_s_discount_version, 0 );
|
316
|
+
|
317
|
+
rb_define_method( bluecloth_cBlueCloth, "initialize", bluecloth_initialize, -1 );
|
318
|
+
|
319
|
+
rb_define_method( bluecloth_cBlueCloth, "to_html", bluecloth_to_html, 0 );
|
320
|
+
rb_define_method( bluecloth_cBlueCloth, "header", bluecloth_header, 0 );
|
321
|
+
rb_define_alias( bluecloth_cBlueCloth, "pandoc_header", "header" );
|
322
|
+
|
323
|
+
/* The original Markdown text the object was constructed with */
|
324
|
+
rb_define_attr( bluecloth_cBlueCloth, "text", 1, 0 );
|
325
|
+
|
326
|
+
/* The options hash that describes the options in effect when the object was created */
|
327
|
+
rb_define_attr( bluecloth_cBlueCloth, "options", 1, 0 );
|
328
|
+
|
329
|
+
/* --- Constants ----- */
|
330
|
+
/* special flags for markdown() and mkd_text() */
|
331
|
+
|
332
|
+
/* Do not process `[]' and remove A tags from the output. */
|
333
|
+
rb_define_const( bluecloth_cBlueCloth, "MKD_NOLINKS", INT2FIX(MKD_NOLINKS) );
|
334
|
+
|
335
|
+
/* Do not process `![]' and remove IMG tags from the output. */
|
336
|
+
rb_define_const( bluecloth_cBlueCloth, "MKD_NOIMAGE", INT2FIX(MKD_NOIMAGE) );
|
337
|
+
|
338
|
+
/* Do not do Smartypants-style mangling of quotes, dashes, or ellipses. */
|
339
|
+
rb_define_const( bluecloth_cBlueCloth, "MKD_NOPANTS", INT2FIX(MKD_NOPANTS) );
|
340
|
+
|
341
|
+
/* Escape all opening angle brackets in the input text instead of allowing block-level HTML */
|
342
|
+
rb_define_const( bluecloth_cBlueCloth, "MKD_NOHTML", INT2FIX(MKD_NOHTML) );
|
343
|
+
|
344
|
+
/* disable SUPERSCRIPT, RELAXED_EMPHASIS */
|
345
|
+
rb_define_const( bluecloth_cBlueCloth, "MKD_STRICT", INT2FIX(MKD_STRICT) );
|
346
|
+
|
347
|
+
/* don't expand `_` and `*` */
|
348
|
+
rb_define_const( bluecloth_cBlueCloth, "MKD_TAGTEXT", INT2FIX(MKD_TAGTEXT) );
|
349
|
+
|
350
|
+
/* don't allow pseudo-protocols */
|
351
|
+
rb_define_const( bluecloth_cBlueCloth, "MKD_NO_EXT", INT2FIX(MKD_NO_EXT) );
|
352
|
+
|
353
|
+
/* do table-of-contents processing */
|
354
|
+
rb_define_const( bluecloth_cBlueCloth, "MKD_TOC", INT2FIX(MKD_TOC) );
|
355
|
+
|
356
|
+
/* MarkdownTest 1.0 Compatibility Mode */
|
357
|
+
rb_define_const( bluecloth_cBlueCloth, "MKD_1_COMPAT", INT2FIX(MKD_1_COMPAT) );
|
358
|
+
|
359
|
+
/* MKD_NOLINKS|MKD_NOIMAGE|MKD_TAGTEXT */
|
360
|
+
rb_define_const( bluecloth_cBlueCloth, "MKD_EMBED", INT2FIX(MKD_EMBED) );
|
361
|
+
|
362
|
+
/* -- special flags for mkd_in() and mkd_string() */
|
363
|
+
|
364
|
+
/* don't process header blocks */
|
365
|
+
rb_define_const( bluecloth_cBlueCloth, "MKD_NOHEADER", INT2FIX(MKD_NOHEADER) );
|
366
|
+
|
367
|
+
|
368
|
+
/* Make sure the Ruby side is loaded */
|
369
|
+
rb_require( "bluecloth" );
|
370
|
+
|
371
|
+
bluecloth_default_opthash = rb_const_get( bluecloth_cBlueCloth, rb_intern("DEFAULT_OPTIONS") );
|
372
|
+
}
|
373
|
+
|