skwp-superredcloth 1.160

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ = 4.0
2
+ === 27th January 2007
3
+
4
+ * Rewrote RedCloth using the Ragel State Machine Compiler. Ten times faster and more correct!
data/COPYING ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2006 why the lucky stiff
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to
5
+ deal in the Software without restriction, including without limitation the
6
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ sell copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,162 @@
1
+ = RedCloth - Textile and Markdown Hybrid for Ruby
2
+
3
+ Homepage:: http://whytheluckystiff.net/ruby/redcloth/
4
+ Author:: why the lucky stiff (http://whytheluckystiff.net/)
5
+ Copyright:: (cc) 2004 why the lucky stiff (and his puppet organizations.)
6
+ License:: BSD
7
+
8
+ (see http://hobix.com/textile/ for a Textile Reference.)
9
+
10
+ Based on (and also inspired by) both:
11
+
12
+ PyTextile: http://diveintomark.org/projects/textile/textile.py.txt
13
+ Textism for PHP: http://www.textism.com/tools/textile/
14
+
15
+ = RedCloth
16
+
17
+ RedCloth is a Ruby library for converting Textile and/or Markdown
18
+ into HTML. You can use either format, intermingled or separately.
19
+ You can also extend RedCloth to honor your own custom text stylings.
20
+
21
+ RedCloth users are encouraged to use Textile if they are generating
22
+ HTML and to use Markdown if others will be viewing the plain text.
23
+
24
+ == What is Textile?
25
+
26
+ Textile is a simple formatting style for text
27
+ documents, loosely based on some HTML conventions.
28
+
29
+ == Sample Textile Text
30
+
31
+ h2. This is a title
32
+
33
+ h3. This is a subhead
34
+
35
+ This is a bit of paragraph.
36
+
37
+ bq. This is a blockquote.
38
+
39
+ = Writing Textile
40
+
41
+ A Textile document consists of paragraphs. Paragraphs
42
+ can be specially formatted by adding a small instruction
43
+ to the beginning of the paragraph.
44
+
45
+ h[n]. Header of size [n].
46
+ bq. Blockquote.
47
+ # Numeric list.
48
+ * Bulleted list.
49
+
50
+ == Quick Phrase Modifiers
51
+
52
+ Quick phrase modifiers are also included, to allow formatting
53
+ of small portions of text within a paragraph.
54
+
55
+ \_emphasis\_
56
+ \_\_italicized\_\_
57
+ \*strong\*
58
+ \*\*bold\*\*
59
+ ??citation??
60
+ -deleted text-
61
+ +inserted text+
62
+ ^superscript^
63
+ ~subscript~
64
+ @code@
65
+ %(classname)span%
66
+
67
+ ==notextile== (leave text alone)
68
+
69
+ == Links
70
+
71
+ To make a hypertext link, put the link text in "quotation
72
+ marks" followed immediately by a colon and the URL of the link.
73
+
74
+ Optional: text in (parentheses) following the link text,
75
+ but before the closing quotation mark, will become a Title
76
+ attribute for the link, visible as a tool tip when a cursor is above it.
77
+
78
+ Example:
79
+
80
+ "This is a link (This is a title) ":http://www.textism.com
81
+
82
+ Will become:
83
+
84
+ <a href="http://www.textism.com" title="This is a title">This is a link</a>
85
+
86
+ == Images
87
+
88
+ To insert an image, put the URL for the image inside exclamation marks.
89
+
90
+ Optional: text that immediately follows the URL in (parentheses) will
91
+ be used as the Alt text for the image. Images on the web should always
92
+ have descriptive Alt text for the benefit of readers using non-graphical
93
+ browsers.
94
+
95
+ Optional: place a colon followed by a URL immediately after the
96
+ closing ! to make the image into a link.
97
+
98
+ Example:
99
+
100
+ !http://www.textism.com/common/textist.gif(Textist)!
101
+
102
+ Will become:
103
+
104
+ <img src="http://www.textism.com/common/textist.gif" alt="Textist" />
105
+
106
+ With a link:
107
+
108
+ !/common/textist.gif(Textist)!:http://textism.com
109
+
110
+ Will become:
111
+
112
+ <a href="http://textism.com"><img src="/common/textist.gif" alt="Textist" /></a>
113
+
114
+ == Defining Acronyms
115
+
116
+ HTML allows authors to define acronyms via the tag. The definition appears as a
117
+ tool tip when a cursor hovers over the acronym. A crucial aid to clear writing,
118
+ this should be used at least once for each acronym in documents where they appear.
119
+
120
+ To quickly define an acronym in Textile, place the full text in (parentheses)
121
+ immediately following the acronym.
122
+
123
+ Example:
124
+
125
+ ACLU(American Civil Liberties Union)
126
+
127
+ Will become:
128
+
129
+ <acronym title="American Civil Liberties Union">ACLU</acronym>
130
+
131
+ == Adding Tables
132
+
133
+ In Textile, simple tables can be added by seperating each column by
134
+ a pipe.
135
+
136
+ |a|simple|table|row|
137
+ |And|Another|table|row|
138
+
139
+ Attributes are defined by style definitions in parentheses.
140
+
141
+ table(border:1px solid black).
142
+ (background:#ddd;color:red). |{}| | | |
143
+
144
+ == Using RedCloth
145
+
146
+ RedCloth is simply an extension of the String class, which can handle
147
+ Textile formatting. Use it like a String and output HTML with its
148
+ RedCloth#to_html method.
149
+
150
+ doc = RedCloth.new "
151
+
152
+ h2. Test document
153
+
154
+ Just a simple test."
155
+
156
+ puts doc.to_html
157
+
158
+ By default, RedCloth uses both Textile and Markdown formatting, with
159
+ Textile formatting taking precedence. If you want to turn off Markdown
160
+ formatting, to boost speed and limit the processor:
161
+
162
+ class RedCloth::Textile.new( str )
@@ -0,0 +1,180 @@
1
+ require 'rake'
2
+ require 'rake/clean'
3
+ require 'rake/gempackagetask'
4
+ require 'rake/rdoctask'
5
+ require 'rake/testtask'
6
+ require 'fileutils'
7
+ include FileUtils
8
+
9
+ NAME = "superredcloth"
10
+ SUMMARY = "a fast library for formatting Textile and Markdown as HTML"
11
+ REV = `svn info`[/Revision: (\d+)/, 1] rescue nil
12
+ VERS = ENV['VERSION'] || "1" + (REV ? ".#{REV}" : "")
13
+ CLEAN.include ['ext/superredcloth_scan/*.{bundle,so,obj,pdb,lib,def,exp}', 'ext/superredcloth_scan/Makefile',
14
+ '**/.*.sw?', '*.gem', '.config']
15
+
16
+ desc "Does a full compile, test run"
17
+ task :default => [:compile, :test]
18
+
19
+ desc "Compiles all extensions"
20
+ task :compile => [:superredcloth_scan] do
21
+ if Dir.glob(File.join("lib","superredcloth_scan.*")).length == 0
22
+ STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
23
+ STDERR.puts "Gem actually failed to build. Your system is"
24
+ STDERR.puts "NOT configured properly to build superredcloth."
25
+ STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
26
+ exit(1)
27
+ end
28
+ end
29
+ task :superredcloth_scan => [:ragel]
30
+
31
+ desc "Packages up SuperRedCloth."
32
+ task :package => [:clean, :ragel]
33
+
34
+ desc "Releases packages for all SuperRedCloth packages and platforms."
35
+ task :release => [:package, :rubygems_win32]
36
+
37
+ desc "Run all the tests"
38
+ Rake::TestTask.new do |t|
39
+ t.libs << "test"
40
+ t.test_files = FileList['test/test_*.rb']
41
+ t.verbose = true
42
+ end
43
+
44
+ Rake::RDocTask.new do |rdoc|
45
+ rdoc.rdoc_dir = 'doc/rdoc'
46
+ # rdoc.options += RDOC_OPTS
47
+ # rdoc.template = "extras/flipbook_rdoc.rb"
48
+ rdoc.main = "README"
49
+ rdoc.title = "SuperRedCloth Documentation"
50
+ rdoc.rdoc_files.add ['README', 'CHANGELOG', 'COPYING', 'lib/**/*.rb']
51
+ end
52
+
53
+ spec =
54
+ Gem::Specification.new do |s|
55
+ s.name = NAME
56
+ s.version = VERS
57
+ s.platform = Gem::Platform::RUBY
58
+ s.has_rdoc = true
59
+ s.extra_rdoc_files = ["README", "CHANGELOG", "COPYING"]
60
+ s.summary = SUMMARY
61
+ s.description = s.summary
62
+ s.author = "why the lucky stiff"
63
+ s.email = 'why@ruby-lang.org'
64
+ s.homepage = 'http://code.whytheluckystiff.net/redcloth/'
65
+
66
+ s.files = %w(COPYING README Rakefile) +
67
+ Dir.glob("{bin,doc,test,lib,extras}/**/*") +
68
+ Dir.glob("ext/**/*.{h,c,rb,rl}") +
69
+ %w[ext/superredcloth_scan/superredcloth_scan.c] # needed because it's generated later
70
+
71
+ s.require_path = "lib"
72
+ #s.autorequire = "superredcloth" # no no no this is tHe 3v1l
73
+ s.extensions = FileList["ext/**/extconf.rb"].to_a
74
+ s.bindir = "bin"
75
+ end
76
+
77
+ Rake::GemPackageTask.new(spec) do |p|
78
+ p.need_tar = true
79
+ p.gem_spec = spec
80
+ end
81
+
82
+ extension = "superredcloth_scan"
83
+ ext = "ext/superredcloth_scan"
84
+ ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}"
85
+ ext_files = FileList[
86
+ "#{ext}/*.c",
87
+ "#{ext}/*.h",
88
+ "#{ext}/*.rl",
89
+ "#{ext}/extconf.rb",
90
+ "#{ext}/Makefile",
91
+ "lib"
92
+ ]
93
+
94
+ task "lib" do
95
+ directory "lib"
96
+ end
97
+
98
+ desc "Builds just the #{extension} extension"
99
+ task extension.to_sym => ["#{ext}/Makefile", ext_so ]
100
+
101
+ file "#{ext}/Makefile" => ["#{ext}/extconf.rb"] do
102
+ Dir.chdir(ext) do ruby "extconf.rb" end
103
+ end
104
+
105
+ file ext_so => ext_files do
106
+ Dir.chdir(ext) do
107
+ sh(PLATFORM =~ /win32/ ? 'nmake' : 'make')
108
+ end
109
+ cp ext_so, "lib"
110
+ end
111
+
112
+ desc "Generates the scanner code with Ragel."
113
+ task :ragel do
114
+ Dir.chdir('ext/superredcloth_scan') do
115
+ ['superredcloth_scan', 'superredcloth_inline'].each do |src|
116
+ sh %{ragel #{src}.rl | rlcodegen -G2 -o #{src}.c}
117
+ end
118
+ end
119
+ end
120
+
121
+ PKG_FILES = FileList[
122
+ "test/**/*.{rb,html,xhtml}",
123
+ "lib/**/*.rb",
124
+ "ext/**/*.{c,rb,h,rl}",
125
+ "CHANGELOG", "README", "Rakefile", "COPYING",
126
+ "extras/**/*", "lib/superredcloth_scan.so"]
127
+
128
+ Win32Spec = Gem::Specification.new do |s|
129
+ s.name = NAME
130
+ s.version = VERS
131
+ s.platform = Gem::Platform::WIN32
132
+ s.has_rdoc = false
133
+ s.extra_rdoc_files = ["README", "CHANGELOG", "COPYING"]
134
+ s.summary = SUMMARY
135
+ s.description = s.summary
136
+ s.author = "why the lucky stiff"
137
+ s.email = 'why@ruby-lang.org'
138
+ s.homepage = 'http://code.whytheluckystiff.net/redcloth/'
139
+
140
+ s.files = PKG_FILES
141
+
142
+ s.require_path = "lib"
143
+ #s.autorequire = "superredcloth" # no no no this is tHe 3v1l
144
+ s.extensions = []
145
+ s.bindir = "bin"
146
+ end
147
+
148
+ WIN32_PKG_DIR = "superredcloth-" + VERS
149
+
150
+ file WIN32_PKG_DIR => [:package] do
151
+ sh "tar zxf pkg/#{WIN32_PKG_DIR}.tgz"
152
+ end
153
+
154
+ desc "Cross-compile the superredcloth_scan extension for win32"
155
+ file "superredcloth_scan_win32" => [WIN32_PKG_DIR] do
156
+ cp "extras/mingw-rbconfig.rb", "#{WIN32_PKG_DIR}/ext/superredcloth_scan/rbconfig.rb"
157
+ sh "cd #{WIN32_PKG_DIR}/ext/superredcloth_scan/ && ruby -I. extconf.rb && make"
158
+ mv "#{WIN32_PKG_DIR}/ext/superredcloth_scan/superredcloth_scan.so", "#{WIN32_PKG_DIR}/lib"
159
+ end
160
+
161
+ desc "Build the binary RubyGems package for win32"
162
+ task :rubygems_win32 => ["superredcloth_scan_win32"] do
163
+ Dir.chdir("#{WIN32_PKG_DIR}") do
164
+ Gem::Builder.new(Win32Spec).build
165
+ verbose(true) {
166
+ mv Dir["*.gem"].first, "../pkg/superredcloth-#{VERS}-mswin32.gem"
167
+ }
168
+ end
169
+ end
170
+
171
+ CLEAN.include WIN32_PKG_DIR
172
+
173
+ task :install do
174
+ sh %{rake package}
175
+ sh %{sudo gem install pkg/#{NAME}-#{VERS}}
176
+ end
177
+
178
+ task :uninstall => [:clean] do
179
+ sh %{sudo gem uninstall #{NAME}}
180
+ end
@@ -0,0 +1,6 @@
1
+ require 'mkmf'
2
+
3
+ dir_config("superredcloth_scan")
4
+ have_library("c", "main")
5
+
6
+ create_makefile("superredcloth_scan")
@@ -0,0 +1,77 @@
1
+ #ifndef superredcloth_h
2
+ #define superredcloth_h
3
+
4
+ /* variable defs */
5
+ #ifndef superredcloth_scan_c
6
+ extern VALUE super_ParseError, super_RedCloth;
7
+ #endif
8
+
9
+ /* function defs */
10
+ void rb_str_cat_escaped(VALUE str, char *tokstart, char *tokend);
11
+ VALUE superredcloth_inline(char *p, char *pe);
12
+ VALUE superredcloth_inline2(VALUE str);
13
+ VALUE superredcloth_transform(char *p, char *pe);
14
+ VALUE superredcloth_transform2(VALUE str);
15
+ void red_inc(VALUE regs, VALUE ref);
16
+ VALUE red_block(VALUE block, ID meth);
17
+ VALUE red_pass2(VALUE regs, VALUE ref, VALUE btype);
18
+ VALUE red_pass(VALUE regs, VALUE ref, ID meth);
19
+
20
+ /* parser macros */
21
+ #define CAT(H) rb_str_cat(H, tokstart, tokend-tokstart)
22
+ #define CLEAR(H) H = rb_str_new2("")
23
+ #define INLINE(H, T) rb_str_append(H, rb_funcall(super_RedCloth, rb_intern(#T), 1, regs))
24
+ #define DONE(H) rb_str_append(html, H); CLEAR(H); regs = rb_hash_new()
25
+ #define PASS(H, A, T) rb_str_append(H, red_pass(regs, ID2SYM(rb_intern(#A)), rb_intern(#T)))
26
+ #define PASS2(H, A, T) rb_str_append(H, red_pass2(regs, ID2SYM(rb_intern(#A)), ID2SYM(rb_intern(#T))))
27
+ #define ADD_BLOCK() rb_str_append(html, red_block(regs, block)); CLEAR(block); regs = rb_hash_new()
28
+ #define ASET(T, V) rb_hash_aset(regs, ID2SYM(rb_intern(#T)), rb_str_new2(#V));
29
+ #define AINC(T) red_inc(regs, ID2SYM(rb_intern(#T)));
30
+ #define STORE(T) \
31
+ if (p > reg && reg >= tokstart) { \
32
+ while (reg < p && ( *reg == '\r' || *reg == '\n' ) ) { reg++; } \
33
+ while (p > reg && ( *(p - 1) == '\r' || *(p - 1) == '\n' ) ) { p--; } \
34
+ } \
35
+ if (p > reg && reg >= tokstart) { \
36
+ VALUE str = rb_str_new(reg, p-reg); \
37
+ rb_hash_aset(regs, ID2SYM(rb_intern(#T)), str); \
38
+ /* printf("STORE(" #T ") %s\n", RSTRING(str)->ptr); */ \
39
+ } else { \
40
+ rb_hash_aset(regs, ID2SYM(rb_intern(#T)), Qnil); \
41
+ }
42
+ #define STORE_URL(T) \
43
+ if (p > reg && reg >= tokstart) { \
44
+ char punct = 1; \
45
+ while (p > reg && punct == 1) { \
46
+ switch (*(p - 1)) { \
47
+ case '!': case '"': case '#': case '$': case '%': case ']': case '[': case '&': case '\'': \
48
+ case '*': case '+': case ',': case '-': case '.': case ')': case '(': case ':': \
49
+ case ';': case '=': case '?': case '@': case '\\': case '^': case '_': \
50
+ case '`': case '|': case '~': p--; break; \
51
+ default: punct = 0; \
52
+ } \
53
+ } \
54
+ tokend = p; \
55
+ } \
56
+ STORE(T)
57
+ #define LIST_ITEM() \
58
+ char listm[10] = ""; \
59
+ if (nest > RARRAY(list_layout)->len) \
60
+ { \
61
+ sprintf(listm, "%s_open", list_type); \
62
+ rb_str_append(html, rb_funcall(super_RedCloth, rb_intern(listm), 1, regs)); \
63
+ rb_ary_store(list_layout, nest-1, rb_str_new2(list_type)); \
64
+ } \
65
+ while (nest < RARRAY(list_layout)->len) \
66
+ { \
67
+ VALUE end_list = rb_ary_pop(list_layout); \
68
+ if (!NIL_P(end_list)) \
69
+ { \
70
+ StringValue(end_list); \
71
+ sprintf(listm, "%s_close", RSTRING(end_list)->ptr); \
72
+ rb_str_append(html, rb_funcall(super_RedCloth, rb_intern(listm), 1, regs)); \
73
+ } \
74
+ } \
75
+ ASET(type, li)
76
+
77
+ #endif