jeremy-RedCloth 4.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +135 -0
- data/COPYING +18 -0
- data/Manifest +56 -0
- data/README +171 -0
- data/Rakefile +205 -0
- data/bin/redcloth +28 -0
- data/ext/mingw-rbconfig.rb +176 -0
- data/ext/redcloth_scan/extconf.rb +9 -0
- data/ext/redcloth_scan/redcloth.h +178 -0
- data/ext/redcloth_scan/redcloth_attributes.c.rl +56 -0
- data/ext/redcloth_scan/redcloth_attributes.java.rl +96 -0
- data/ext/redcloth_scan/redcloth_attributes.rl +33 -0
- data/ext/redcloth_scan/redcloth_common.c.rl +18 -0
- data/ext/redcloth_scan/redcloth_common.java.rl +18 -0
- data/ext/redcloth_scan/redcloth_common.rl +111 -0
- data/ext/redcloth_scan/redcloth_inline.c.rl +159 -0
- data/ext/redcloth_scan/redcloth_inline.java.rl +108 -0
- data/ext/redcloth_scan/redcloth_inline.rl +159 -0
- data/ext/redcloth_scan/redcloth_scan.c.rl +237 -0
- data/ext/redcloth_scan/redcloth_scan.java.rl +573 -0
- data/ext/redcloth_scan/redcloth_scan.rl +325 -0
- data/extras/ragel_profiler.rb +73 -0
- data/lib/case_sensitive_require/RedCloth.rb +6 -0
- data/lib/redcloth.rb +37 -0
- data/lib/redcloth/erb_extension.rb +27 -0
- data/lib/redcloth/formatters/base.rb +57 -0
- data/lib/redcloth/formatters/html.rb +353 -0
- data/lib/redcloth/formatters/latex.rb +275 -0
- data/lib/redcloth/formatters/latex_entities.yml +2414 -0
- data/lib/redcloth/textile_doc.rb +103 -0
- data/lib/redcloth/version.rb +28 -0
- data/setup.rb +1585 -0
- data/test/basic.yml +922 -0
- data/test/code.yml +229 -0
- data/test/definitions.yml +82 -0
- data/test/extra_whitespace.yml +64 -0
- data/test/filter_html.yml +177 -0
- data/test/filter_pba.yml +20 -0
- data/test/helper.rb +108 -0
- data/test/html.yml +311 -0
- data/test/images.yml +254 -0
- data/test/instiki.yml +38 -0
- data/test/links.yml +275 -0
- data/test/lists.yml +283 -0
- data/test/poignant.yml +89 -0
- data/test/sanitize_html.yml +42 -0
- data/test/table.yml +336 -0
- data/test/test_custom_tags.rb +58 -0
- data/test/test_erb.rb +13 -0
- data/test/test_extensions.rb +31 -0
- data/test/test_formatters.rb +24 -0
- data/test/test_parser.rb +73 -0
- data/test/test_restrictions.rb +41 -0
- data/test/textism.yml +480 -0
- data/test/threshold.yml +772 -0
- data/test/validate_fixtures.rb +74 -0
- metadata +133 -0
data/bin/redcloth
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib/')
|
3
|
+
require 'optparse'
|
4
|
+
require 'redcloth'
|
5
|
+
|
6
|
+
if %w(--version -v).include? ARGV.first
|
7
|
+
puts "#{RedCloth::NAME} #{RedCloth::VERSION}"
|
8
|
+
exit(0)
|
9
|
+
end
|
10
|
+
|
11
|
+
output_as = "html"
|
12
|
+
opts = OptionParser.new do |opts|
|
13
|
+
opts.banner = "Usage: redcloth [options] [redcloth_formatted.txt]"
|
14
|
+
opts.separator "If no file specified, STDIN will be used. If you are typing input, you can send an EOF by pressing ^D (^Z on Windows)"
|
15
|
+
opts.separator ""
|
16
|
+
opts.on("-o", "--output STYLE", "Output format (defaults to #{output_as})") do |o|
|
17
|
+
output_as = o
|
18
|
+
end
|
19
|
+
end
|
20
|
+
opts.parse! ARGV
|
21
|
+
|
22
|
+
red = RedCloth.new( ARGF.read )
|
23
|
+
out_meth = "to_#{ output_as }"
|
24
|
+
if red.respond_to? out_meth
|
25
|
+
puts red.method( out_meth ).call
|
26
|
+
else
|
27
|
+
abort "** No to_#{ output_as } method found for the `#{ output_as }' format"
|
28
|
+
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
|
2
|
+
# This rbconfig.rb corresponds to a Ruby installation for win32 cross-compiled
|
3
|
+
# with mingw under i686-linux. It can be used to cross-compile extensions for
|
4
|
+
# win32 using said toolchain.
|
5
|
+
#
|
6
|
+
# This file assumes that a cross-compiled mingw32 build (compatible with the
|
7
|
+
# mswin32 builds) is installed under $HOME/ruby-mingw32.
|
8
|
+
|
9
|
+
module Config
|
10
|
+
#RUBY_VERSION == "1.8.5" or
|
11
|
+
# raise "ruby lib version (1.8.5) doesn't match executable version (#{RUBY_VERSION})"
|
12
|
+
|
13
|
+
mingw32 = ENV['MINGW32_RUBY'] || "#{ENV["HOME"]}/ruby-mingw32"
|
14
|
+
mingwpre = ENV['MINGW32_PREFIX']
|
15
|
+
TOPDIR = File.dirname(__FILE__).chomp!("/lib/ruby/1.8/i386-mingw32")
|
16
|
+
DESTDIR = '' unless defined? DESTDIR
|
17
|
+
CONFIG = {}
|
18
|
+
CONFIG["DESTDIR"] = DESTDIR
|
19
|
+
CONFIG["INSTALL"] = "/usr/bin/install -c"
|
20
|
+
CONFIG["prefix"] = (TOPDIR || DESTDIR + mingw32)
|
21
|
+
CONFIG["EXEEXT"] = ".exe"
|
22
|
+
CONFIG["ruby_install_name"] = "ruby"
|
23
|
+
CONFIG["RUBY_INSTALL_NAME"] = "ruby"
|
24
|
+
CONFIG["RUBY_SO_NAME"] = "msvcrt-ruby18"
|
25
|
+
CONFIG["SHELL"] = "/bin/sh"
|
26
|
+
CONFIG["PATH_SEPARATOR"] = ":"
|
27
|
+
CONFIG["PACKAGE_NAME"] = ""
|
28
|
+
CONFIG["PACKAGE_TARNAME"] = ""
|
29
|
+
CONFIG["PACKAGE_VERSION"] = ""
|
30
|
+
CONFIG["PACKAGE_STRING"] = ""
|
31
|
+
CONFIG["PACKAGE_BUGREPORT"] = ""
|
32
|
+
CONFIG["exec_prefix"] = "$(prefix)"
|
33
|
+
CONFIG["bindir"] = "$(exec_prefix)/bin"
|
34
|
+
CONFIG["sbindir"] = "$(exec_prefix)/sbin"
|
35
|
+
CONFIG["libexecdir"] = "$(exec_prefix)/libexec"
|
36
|
+
CONFIG["datadir"] = "$(prefix)/share"
|
37
|
+
CONFIG["sysconfdir"] = "$(prefix)/etc"
|
38
|
+
CONFIG["sharedstatedir"] = "$(prefix)/com"
|
39
|
+
CONFIG["localstatedir"] = "$(prefix)/var"
|
40
|
+
CONFIG["libdir"] = "$(exec_prefix)/lib"
|
41
|
+
CONFIG["includedir"] = "$(prefix)/include"
|
42
|
+
CONFIG["oldincludedir"] = "/usr/include"
|
43
|
+
CONFIG["infodir"] = "$(prefix)/info"
|
44
|
+
CONFIG["mandir"] = "$(prefix)/man"
|
45
|
+
CONFIG["build_alias"] = "i686-linux"
|
46
|
+
CONFIG["host_alias"] = "#{mingwpre}"
|
47
|
+
CONFIG["target_alias"] = "i386-mingw32"
|
48
|
+
CONFIG["ECHO_C"] = ""
|
49
|
+
CONFIG["ECHO_N"] = "-n"
|
50
|
+
CONFIG["ECHO_T"] = ""
|
51
|
+
CONFIG["LIBS"] = "-lwsock32 "
|
52
|
+
CONFIG["MAJOR"] = "1"
|
53
|
+
CONFIG["MINOR"] = "8"
|
54
|
+
CONFIG["TEENY"] = "4"
|
55
|
+
CONFIG["build"] = "i686-pc-linux"
|
56
|
+
CONFIG["build_cpu"] = "i686"
|
57
|
+
CONFIG["build_vendor"] = "pc"
|
58
|
+
CONFIG["build_os"] = "linux"
|
59
|
+
CONFIG["host"] = "i586-pc-mingw32msvc"
|
60
|
+
CONFIG["host_cpu"] = "i586"
|
61
|
+
CONFIG["host_vendor"] = "pc"
|
62
|
+
CONFIG["host_os"] = "mingw32msvc"
|
63
|
+
CONFIG["target"] = "i386-pc-mingw32"
|
64
|
+
CONFIG["target_cpu"] = "i386"
|
65
|
+
CONFIG["target_vendor"] = "pc"
|
66
|
+
CONFIG["target_os"] = "mingw32"
|
67
|
+
CONFIG["CC"] = "#{mingwpre}-gcc"
|
68
|
+
CONFIG["CFLAGS"] = "-g "
|
69
|
+
CONFIG["LDFLAGS"] = ""
|
70
|
+
CONFIG["CPPFLAGS"] = ""
|
71
|
+
CONFIG["OBJEXT"] = "o"
|
72
|
+
CONFIG["CPP"] = "#{mingwpre}-gcc -E"
|
73
|
+
CONFIG["EGREP"] = "grep -E"
|
74
|
+
CONFIG["GNU_LD"] = "yes"
|
75
|
+
CONFIG["CPPOUTFILE"] = "-o conftest.i"
|
76
|
+
CONFIG["OUTFLAG"] = "-o "
|
77
|
+
CONFIG["YACC"] = "bison -y"
|
78
|
+
CONFIG["RANLIB"] = "#{mingwpre}-ranlib"
|
79
|
+
CONFIG["AR"] = "#{mingwpre}-ar"
|
80
|
+
CONFIG["NM"] = "#{mingwpre}-nm"
|
81
|
+
CONFIG["WINDRES"] = "#{mingwpre}-windres"
|
82
|
+
CONFIG["DLLWRAP"] = "#{mingwpre}-dllwrap"
|
83
|
+
CONFIG["OBJDUMP"] = "#{mingwpre}-objdump"
|
84
|
+
CONFIG["LN_S"] = "ln -s"
|
85
|
+
CONFIG["SET_MAKE"] = ""
|
86
|
+
CONFIG["INSTALL_PROGRAM"] = "$(INSTALL)"
|
87
|
+
CONFIG["INSTALL_SCRIPT"] = "$(INSTALL)"
|
88
|
+
CONFIG["INSTALL_DATA"] = "$(INSTALL) -m 644"
|
89
|
+
CONFIG["RM"] = "rm -f"
|
90
|
+
CONFIG["CP"] = "cp"
|
91
|
+
CONFIG["MAKEDIRS"] = "mkdir -p"
|
92
|
+
CONFIG["LIBOBJS"] = " fileblocks$(U).o crypt$(U).o flock$(U).o acosh$(U).o win32$(U).o"
|
93
|
+
CONFIG["ALLOCA"] = ""
|
94
|
+
CONFIG["DLDFLAGS"] = " -Wl,--enable-auto-import,--export-all"
|
95
|
+
CONFIG["ARCH_FLAG"] = ""
|
96
|
+
CONFIG["STATIC"] = ""
|
97
|
+
CONFIG["CCDLFLAGS"] = ""
|
98
|
+
CONFIG["LDSHARED"] = "#{mingwpre}-gcc -shared -s"
|
99
|
+
CONFIG["DLEXT"] = "so"
|
100
|
+
CONFIG["DLEXT2"] = "dll"
|
101
|
+
CONFIG["LIBEXT"] = "a"
|
102
|
+
CONFIG["LINK_SO"] = ""
|
103
|
+
CONFIG["LIBPATHFLAG"] = " -L\"%s\""
|
104
|
+
CONFIG["RPATHFLAG"] = ""
|
105
|
+
CONFIG["LIBPATHENV"] = ""
|
106
|
+
CONFIG["TRY_LINK"] = ""
|
107
|
+
CONFIG["STRIP"] = "strip"
|
108
|
+
CONFIG["EXTSTATIC"] = ""
|
109
|
+
CONFIG["setup"] = "Setup"
|
110
|
+
CONFIG["MINIRUBY"] = "ruby -rfake"
|
111
|
+
CONFIG["PREP"] = "fake.rb"
|
112
|
+
CONFIG["RUNRUBY"] = "$(MINIRUBY) -I`cd $(srcdir)/lib; pwd`"
|
113
|
+
CONFIG["EXTOUT"] = ".ext"
|
114
|
+
CONFIG["ARCHFILE"] = ""
|
115
|
+
CONFIG["RDOCTARGET"] = ""
|
116
|
+
CONFIG["XCFLAGS"] = " -DRUBY_EXPORT"
|
117
|
+
CONFIG["XLDFLAGS"] = " -Wl,--stack,0x02000000 -L."
|
118
|
+
CONFIG["LIBRUBY_LDSHARED"] = "#{mingwpre}-gcc -shared -s"
|
119
|
+
CONFIG["LIBRUBY_DLDFLAGS"] = " -Wl,--enable-auto-import,--export-all -Wl,--out-implib=$(LIBRUBY)"
|
120
|
+
CONFIG["rubyw_install_name"] = "rubyw"
|
121
|
+
CONFIG["RUBYW_INSTALL_NAME"] = "rubyw"
|
122
|
+
CONFIG["LIBRUBY_A"] = "lib$(RUBY_SO_NAME)-static.a"
|
123
|
+
CONFIG["LIBRUBY_SO"] = "$(RUBY_SO_NAME).dll"
|
124
|
+
CONFIG["LIBRUBY_ALIASES"] = ""
|
125
|
+
CONFIG["LIBRUBY"] = "lib$(LIBRUBY_SO).a"
|
126
|
+
CONFIG["LIBRUBYARG"] = "$(LIBRUBYARG_SHARED)"
|
127
|
+
CONFIG["LIBRUBYARG_STATIC"] = "-l$(RUBY_SO_NAME)-static"
|
128
|
+
CONFIG["LIBRUBYARG_SHARED"] = "-l$(RUBY_SO_NAME)"
|
129
|
+
CONFIG["SOLIBS"] = "$(LIBS)"
|
130
|
+
CONFIG["DLDLIBS"] = ""
|
131
|
+
CONFIG["ENABLE_SHARED"] = "yes"
|
132
|
+
CONFIG["MAINLIBS"] = ""
|
133
|
+
CONFIG["COMMON_LIBS"] = "m"
|
134
|
+
CONFIG["COMMON_MACROS"] = ""
|
135
|
+
CONFIG["COMMON_HEADERS"] = "windows.h winsock.h"
|
136
|
+
CONFIG["EXPORT_PREFIX"] = ""
|
137
|
+
CONFIG["MINIOBJS"] = "dmydln.o"
|
138
|
+
CONFIG["MAKEFILES"] = "Makefile GNUmakefile"
|
139
|
+
CONFIG["arch"] = "i386-mingw32"
|
140
|
+
CONFIG["sitearch"] = "i386-msvcrt"
|
141
|
+
CONFIG["sitedir"] = "$(prefix)/lib/ruby/site_ruby"
|
142
|
+
CONFIG["configure_args"] = "'--host=#{mingwpre}' '--target=i386-mingw32' '--build=i686-linux' '--prefix=#{mingw32}' 'build_alias=i686-linux' 'host_alias=#{mingwpre}' 'target_alias=i386-mingw32'"
|
143
|
+
CONFIG["NROFF"] = "/usr/bin/nroff"
|
144
|
+
CONFIG["MANTYPE"] = "doc"
|
145
|
+
CONFIG["LTLIBOBJS"] = " fileblocks$(U).lo crypt$(U).lo flock$(U).lo acosh$(U).lo win32$(U).lo"
|
146
|
+
CONFIG["ruby_version"] = "$(MAJOR).$(MINOR)"
|
147
|
+
CONFIG["rubylibdir"] = "$(libdir)/ruby/$(ruby_version)"
|
148
|
+
CONFIG["archdir"] = "$(rubylibdir)/$(arch)"
|
149
|
+
CONFIG["sitelibdir"] = "$(sitedir)/$(ruby_version)"
|
150
|
+
CONFIG["sitearchdir"] = "$(sitelibdir)/$(sitearch)"
|
151
|
+
CONFIG["topdir"] = File.dirname(__FILE__)
|
152
|
+
MAKEFILE_CONFIG = {}
|
153
|
+
CONFIG.each{|k,v| MAKEFILE_CONFIG[k] = v.dup}
|
154
|
+
def Config::expand(val, config = CONFIG)
|
155
|
+
val.gsub!(/\$\$|\$\(([^()]+)\)|\$\{([^{}]+)\}/) do |var|
|
156
|
+
if !(v = $1 || $2)
|
157
|
+
'$'
|
158
|
+
elsif key = config[v = v[/\A[^:]+(?=(?::(.*?)=(.*))?\z)/]]
|
159
|
+
pat, sub = $1, $2
|
160
|
+
config[v] = false
|
161
|
+
Config::expand(key, config)
|
162
|
+
config[v] = key
|
163
|
+
key = key.gsub(/#{Regexp.quote(pat)}(?=\s|\z)/n) {sub} if pat
|
164
|
+
key
|
165
|
+
else
|
166
|
+
var
|
167
|
+
end
|
168
|
+
end
|
169
|
+
val
|
170
|
+
end
|
171
|
+
CONFIG.each_value do |val|
|
172
|
+
Config::expand(val)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
RbConfig = Config # compatibility for ruby-1.9
|
176
|
+
CROSS_COMPILING = nil unless defined? CROSS_COMPILING
|
@@ -0,0 +1,178 @@
|
|
1
|
+
#ifndef redcloth_h
|
2
|
+
#define redcloth_h
|
3
|
+
|
4
|
+
/* Backward compatibility with Ruby < 1.8.6 */
|
5
|
+
#ifndef RSTRING_LEN
|
6
|
+
#define RSTRING_LEN(x) (RSTRING(x)->len)
|
7
|
+
#endif
|
8
|
+
#ifndef RSTRING_PTR
|
9
|
+
#define RSTRING_PTR(x) (RSTRING(x)->ptr)
|
10
|
+
#endif
|
11
|
+
|
12
|
+
/* variable defs */
|
13
|
+
#ifndef redcloth_scan_c
|
14
|
+
extern VALUE super_ParseError, mRedCloth, super_RedCloth;
|
15
|
+
extern int SYM_escape_preformatted;
|
16
|
+
#endif
|
17
|
+
|
18
|
+
/* function defs */
|
19
|
+
void rb_str_cat_escaped(VALUE self, VALUE str, char *ts, char *te);
|
20
|
+
void rb_str_cat_escaped_for_preformatted(VALUE self, VALUE str, char *ts, char *te);
|
21
|
+
VALUE redcloth_inline(VALUE, char *, char *, VALUE);
|
22
|
+
VALUE redcloth_inline2(VALUE, VALUE, VALUE);
|
23
|
+
VALUE redcloth_attribute_parser(int, VALUE, char *, char *);
|
24
|
+
VALUE redcloth_attributes(VALUE, VALUE);
|
25
|
+
VALUE redcloth_link_attributes(VALUE, VALUE);
|
26
|
+
VALUE redcloth_transform(VALUE, char *, char *, VALUE);
|
27
|
+
VALUE redcloth_transform2(VALUE, VALUE);
|
28
|
+
void red_inc(VALUE, VALUE);
|
29
|
+
VALUE red_block(VALUE, VALUE, VALUE, VALUE);
|
30
|
+
VALUE red_blockcode(VALUE, VALUE, VALUE);
|
31
|
+
VALUE red_pass(VALUE, VALUE, VALUE, ID, VALUE);
|
32
|
+
VALUE red_pass_code(VALUE, VALUE, VALUE, ID);
|
33
|
+
|
34
|
+
/* parser macros */
|
35
|
+
#define CLEAR_REGS() regs = rb_hash_new();
|
36
|
+
#define RESET_REG() reg = NULL
|
37
|
+
#define CAT(H) rb_str_cat(H, ts, te-ts)
|
38
|
+
#define CLEAR(H) H = rb_str_new2("")
|
39
|
+
#define SET_PLAIN_BLOCK(T) plain_block = rb_str_new2(T)
|
40
|
+
#define RESET_TYPE(T) rb_hash_aset(regs, ID2SYM(rb_intern("type")), plain_block)
|
41
|
+
#define INLINE(H, T) rb_str_append(H, rb_funcall(self, rb_intern(T), 1, regs))
|
42
|
+
#define DONE(H) rb_str_append(html, H); CLEAR(H); CLEAR_REGS()
|
43
|
+
#define PASS(H, A, T) rb_str_append(H, red_pass(self, regs, ID2SYM(rb_intern(A)), rb_intern(T), refs))
|
44
|
+
#define PARSE_ATTR(A) red_parse_attr(self, regs, ID2SYM(rb_intern(A)))
|
45
|
+
#define PARSE_LINK_ATTR(A) red_parse_link_attr(self, regs, ID2SYM(rb_intern(A)))
|
46
|
+
#define PASS_CODE(H, A, T, O) rb_str_append(H, red_pass_code(self, regs, ID2SYM(rb_intern(A)), rb_intern(T)))
|
47
|
+
#define ADD_BLOCK() \
|
48
|
+
rb_str_append(html, red_block(self, regs, block, refs)); \
|
49
|
+
extend = Qnil; \
|
50
|
+
CLEAR(block); \
|
51
|
+
CLEAR_REGS()
|
52
|
+
#define ADD_EXTENDED_BLOCK() rb_str_append(html, red_block(self, regs, block, refs)); CLEAR(block);
|
53
|
+
#define END_EXTENDED() extend = Qnil; CLEAR_REGS();
|
54
|
+
#define IS_NOT_EXTENDED() NIL_P(extend)
|
55
|
+
#define ADD_BLOCKCODE() rb_str_append(html, red_blockcode(self, regs, block)); CLEAR(block); CLEAR_REGS()
|
56
|
+
#define ADD_EXTENDED_BLOCKCODE() rb_str_append(html, red_blockcode(self, regs, block)); CLEAR(block);
|
57
|
+
#define ASET(T, V) rb_hash_aset(regs, ID2SYM(rb_intern(T)), rb_str_new2(V));
|
58
|
+
#define AINC(T) red_inc(regs, ID2SYM(rb_intern(T)));
|
59
|
+
#define SET_ATTRIBUTES() \
|
60
|
+
VALUE buf = Qnil; \
|
61
|
+
SET_ATTRIBUTE("class_buf", "class"); \
|
62
|
+
SET_ATTRIBUTE("id_buf", "id"); \
|
63
|
+
SET_ATTRIBUTE("lang_buf", "lang"); \
|
64
|
+
SET_ATTRIBUTE("style_buf", "style");
|
65
|
+
#define SET_ATTRIBUTE(B, A) \
|
66
|
+
buf = rb_hash_aref(regs, ID2SYM(rb_intern(B))); \
|
67
|
+
if (buf != Qnil) rb_hash_aset(regs, ID2SYM(rb_intern(A)), buf);
|
68
|
+
#define TRANSFORM(T) \
|
69
|
+
if (p > reg && reg >= ts) { \
|
70
|
+
VALUE str = redcloth_transform(self, reg, p, refs); \
|
71
|
+
rb_hash_aset(regs, ID2SYM(rb_intern(T)), str); \
|
72
|
+
/* printf("TRANSFORM(" T ") '%s' (p:'%d' reg:'%d')\n", RSTRING(str)->ptr, p, reg);*/ \
|
73
|
+
} else { \
|
74
|
+
rb_hash_aset(regs, ID2SYM(rb_intern(T)), Qnil); \
|
75
|
+
}
|
76
|
+
#define STORE(T) \
|
77
|
+
if (p > reg && reg >= ts) { \
|
78
|
+
VALUE str = rb_str_new(reg, p-reg); \
|
79
|
+
rb_hash_aset(regs, ID2SYM(rb_intern(T)), str); \
|
80
|
+
/* printf("STORE(" T ") '%s' (p:'%d' reg:'%d')\n", RSTRING(str)->ptr, p, reg);*/ \
|
81
|
+
} else { \
|
82
|
+
rb_hash_aset(regs, ID2SYM(rb_intern(T)), Qnil); \
|
83
|
+
}
|
84
|
+
#define STORE_B(T) \
|
85
|
+
if (p > bck && bck >= ts) { \
|
86
|
+
VALUE str = rb_str_new(bck, p-bck); \
|
87
|
+
rb_hash_aset(regs, ID2SYM(rb_intern(T)), str); \
|
88
|
+
/* printf("STORE_B(" T ") '%s' (p:'%d' reg:'%d')\n", RSTRING(str)->ptr, p, reg);*/ \
|
89
|
+
} else { \
|
90
|
+
rb_hash_aset(regs, ID2SYM(rb_intern(T)), Qnil); \
|
91
|
+
}
|
92
|
+
#define STORE_URL(T) \
|
93
|
+
if (p > reg && reg >= ts) { \
|
94
|
+
char punct = 1; \
|
95
|
+
while (p > reg && punct == 1) { \
|
96
|
+
switch (*(p - 1)) { \
|
97
|
+
case ')': \
|
98
|
+
{ /*needed to keep inside chars scoped for less memory usage*/\
|
99
|
+
char *temp_p = p - 1; \
|
100
|
+
char level = -1; \
|
101
|
+
while (temp_p > reg) { \
|
102
|
+
switch(*(temp_p - 1)) { \
|
103
|
+
case '(': ++level; break; \
|
104
|
+
case ')': --level; break; \
|
105
|
+
} \
|
106
|
+
--temp_p; \
|
107
|
+
} \
|
108
|
+
if (level == 0) { punct = 0; } else { --p; } \
|
109
|
+
} \
|
110
|
+
break; \
|
111
|
+
case '!': case '"': case '#': case '$': case '%': case ']': case '[': case '&': case '\'': \
|
112
|
+
case '*': case '+': case ',': case '-': case '.': case '(': case ':': \
|
113
|
+
case ';': case '=': case '?': case '@': case '\\': case '^': case '_': \
|
114
|
+
case '`': case '|': case '~': p--; break; \
|
115
|
+
default: punct = 0; \
|
116
|
+
} \
|
117
|
+
} \
|
118
|
+
te = p; \
|
119
|
+
} \
|
120
|
+
STORE(T); \
|
121
|
+
if ( !NIL_P(refs) && rb_funcall(refs, rb_intern("has_key?"), 1, rb_hash_aref(regs, ID2SYM(rb_intern(T)))) ) { \
|
122
|
+
rb_hash_aset(regs, ID2SYM(rb_intern(T)), rb_hash_aref(refs, rb_hash_aref(regs, ID2SYM(rb_intern(T))))); \
|
123
|
+
}
|
124
|
+
#define STORE_LINK_ALIAS() \
|
125
|
+
rb_hash_aset(refs_found, rb_hash_aref(regs, ID2SYM(rb_intern("text"))), rb_hash_aref(regs, ID2SYM(rb_intern("href"))))
|
126
|
+
#define CLEAR_LIST() list_layout = rb_ary_new()
|
127
|
+
#define LIST_ITEM() \
|
128
|
+
int aint = 0; \
|
129
|
+
VALUE aval = rb_ary_entry(list_index, nest-1); \
|
130
|
+
if (aval != Qnil) aint = NUM2INT(aval); \
|
131
|
+
if (strcmp(list_type, "ol") == 0) \
|
132
|
+
{ \
|
133
|
+
rb_ary_store(list_index, nest-1, INT2NUM(aint + 1)); \
|
134
|
+
} \
|
135
|
+
if (nest > RARRAY_LEN(list_layout)) \
|
136
|
+
{ \
|
137
|
+
sprintf(listm, "%s_open", list_type); \
|
138
|
+
if (list_continue == 1) \
|
139
|
+
{ \
|
140
|
+
list_continue = 0; \
|
141
|
+
rb_hash_aset(regs, ID2SYM(rb_intern("start")), rb_ary_entry(list_index, nest-1)); \
|
142
|
+
} \
|
143
|
+
else \
|
144
|
+
{ \
|
145
|
+
VALUE start = rb_hash_aref(regs, ID2SYM(rb_intern("start"))); \
|
146
|
+
if (NIL_P(start) ) \
|
147
|
+
{ \
|
148
|
+
rb_ary_store(list_index, nest-1, INT2NUM(1)); \
|
149
|
+
} \
|
150
|
+
else \
|
151
|
+
{ \
|
152
|
+
VALUE start_num = rb_funcall(start,rb_intern("to_i"),0); \
|
153
|
+
rb_ary_store(list_index, nest-1, start_num); \
|
154
|
+
} \
|
155
|
+
} \
|
156
|
+
rb_hash_aset(regs, ID2SYM(rb_intern("nest")), INT2NUM(nest)); \
|
157
|
+
rb_str_append(html, rb_funcall(self, rb_intern(listm), 1, regs)); \
|
158
|
+
rb_ary_store(list_layout, nest-1, rb_str_new2(list_type)); \
|
159
|
+
CLEAR_REGS(); \
|
160
|
+
ASET("first", "true"); \
|
161
|
+
} \
|
162
|
+
LIST_CLOSE(); \
|
163
|
+
rb_hash_aset(regs, ID2SYM(rb_intern("nest")), INT2NUM(RARRAY_LEN(list_layout))); \
|
164
|
+
ASET("type", "li_open")
|
165
|
+
#define LIST_CLOSE() \
|
166
|
+
while (nest < RARRAY_LEN(list_layout)) \
|
167
|
+
{ \
|
168
|
+
rb_hash_aset(regs, ID2SYM(rb_intern("nest")), INT2NUM(RARRAY_LEN(list_layout))); \
|
169
|
+
VALUE end_list = rb_ary_pop(list_layout); \
|
170
|
+
if (!NIL_P(end_list)) \
|
171
|
+
{ \
|
172
|
+
StringValue(end_list); \
|
173
|
+
sprintf(listm, "%s_close", RSTRING_PTR(end_list)); \
|
174
|
+
rb_str_append(html, rb_funcall(self, rb_intern(listm), 1, regs)); \
|
175
|
+
} \
|
176
|
+
}
|
177
|
+
|
178
|
+
#endif
|
@@ -0,0 +1,56 @@
|
|
1
|
+
/*
|
2
|
+
* redcloth_attributes.c.rl
|
3
|
+
*
|
4
|
+
* Copyright (C) 2008 Jason Garber
|
5
|
+
*/
|
6
|
+
#include <ruby.h>
|
7
|
+
#include "redcloth.h"
|
8
|
+
|
9
|
+
%%{
|
10
|
+
|
11
|
+
machine redcloth_attributes;
|
12
|
+
include redcloth_common "redcloth_common.c.rl";
|
13
|
+
include redcloth_attributes "redcloth_attributes.rl";
|
14
|
+
|
15
|
+
}%%
|
16
|
+
|
17
|
+
%% write data nofinal;
|
18
|
+
|
19
|
+
|
20
|
+
VALUE
|
21
|
+
redcloth_attribute_parser(machine, self, p, pe)
|
22
|
+
int machine;
|
23
|
+
VALUE self;
|
24
|
+
char *p, *pe;
|
25
|
+
{
|
26
|
+
int cs, act;
|
27
|
+
char *ts, *te, *reg, *bck, *eof;
|
28
|
+
VALUE regs = rb_hash_new();
|
29
|
+
VALUE buf = Qnil;
|
30
|
+
|
31
|
+
%% write init;
|
32
|
+
|
33
|
+
cs = machine;
|
34
|
+
|
35
|
+
%% write exec;
|
36
|
+
|
37
|
+
return regs;
|
38
|
+
}
|
39
|
+
|
40
|
+
VALUE
|
41
|
+
redcloth_attributes(self, str)
|
42
|
+
VALUE self, str;
|
43
|
+
{
|
44
|
+
StringValue(str);
|
45
|
+
int cs = redcloth_attributes_en_inline;
|
46
|
+
return redcloth_attribute_parser(cs, self, RSTRING_PTR(str), RSTRING_PTR(str) + RSTRING_LEN(str) + 1);
|
47
|
+
}
|
48
|
+
|
49
|
+
VALUE
|
50
|
+
redcloth_link_attributes(self, str)
|
51
|
+
VALUE self, str;
|
52
|
+
{
|
53
|
+
StringValue(str);
|
54
|
+
int cs = redcloth_attributes_en_link_says;
|
55
|
+
return redcloth_attribute_parser(cs, self, RSTRING_PTR(str), RSTRING_PTR(str) + RSTRING_LEN(str) + 1);
|
56
|
+
}
|