Upgraded RedCloth to 3.0.4

This commit is contained in:
Alexey Verkhovsky 2005-09-16 04:27:07 +00:00
parent 79cf8a0ea1
commit 1d44ce1c18
24 changed files with 1521 additions and 1160 deletions

View file

@ -1,3 +1,9 @@
* instiki-ar
SQL-based backend (ActiveRecord)
Upgrade to RedCloth 3.0.4
Replaced internal link generator with routing
Fixed --daemon option
* 0.10.2:
Upgraded to Rails 0.13.1
Fixed HTML export

View file

@ -24,7 +24,7 @@ spec = Gem::Specification.new do |s|
s.has_rdoc = false
s.add_dependency('RedCloth', '= 3.0.3')
s.add_dependency('RedCloth', '= 3.0.4')
s.add_dependency('rubyzip', '= 0.5.8')
s.add_dependency('rails', '= 0.13.1')
s.add_dependency('sqlite3-ruby', '= 1.1.0')

View file

@ -84,7 +84,7 @@ ADDITIONAL_LOAD_PATHS = %w(
app/models
lib
vendor/madeleine-0.7.1/lib
vendor/RedCloth-3.0.3/lib
vendor/RedCloth-3.0.4/lib
vendor/rubyzip-0.5.8/lib
).map { |dir| "#{File.expand_path(File.join(INSTIKI_ROOT, dir))}"
}.delete_if { |dir| not File.exist?(dir) }

View file

@ -1,52 +0,0 @@
require 'rubygems'
spec = Gem::Specification.new do |s|
## Basic Information
s.name = 'RedCloth'
s.version = "3.0.3"
s.platform = Gem::Platform::RUBY
s.summary = <<-TXT
RedCloth is a module for using Textile and Markdown in Ruby. Textile and Markdown are text formats.
A very simple text format. Another stab at making readable text that can be converted to HTML.
TXT
s.description = <<-TXT
No need to use verbose HTML to build your docs, your blogs, your pages. Textile gives you readable text while you're writing and beautiful text for your readers. And if you need to break out into HTML, Textile will allow you to do so.
Textile also handles some subtleties of formatting which will enhance your document's readability:
* Single- and double-quotes around words or phrases are converted to curly quotations, much easier on
the eye. "Observe!"
* Double hyphens are replaced with an em-dash. Observe -- very nice!
* Single hyphens are replaced with en-dashes. Observe - so cute!
* Triplets of periods become an ellipsis. Observe...
* The letter 'x' becomes a dimension sign when used alone. Observe: 2 x 2.
* Conversion of ==(TM)== to (TM), ==(R)== to (R), ==(C)== to (C).
For more on Textile's language, hop over to "A Textile Reference":http://hobix.com/textile/. For more
on Markdown, see "Daring Fireball's page":http://daringfireball.net/projects/markdown/.
TXT
## Include tests, libs, docs
s.files = ['bin/**/*', 'tests/**/*', 'lib/**/*', 'docs/**/*', 'run-tests.rb'].collect do |dirglob|
Dir.glob(dirglob)
end.flatten.delete_if {|item| item.include?("CVS")}
## Load-time details
s.require_path = 'lib'
s.autorequire = 'redcloth'
## Author and project details
s.author = "Why the Lucky Stiff"
s.email = "why@ruby-lang.org"
s.rubyforge_project = "redcloth"
s.homepage = "http://www.whytheluckystiff.net/ruby/redcloth/"
end

File diff suppressed because it is too large Load diff

View file

@ -1,3 +1,3 @@
#!/usr/local/bin/ruby18
#!/usr/bin/ruby18
require 'redcloth'
puts RedCloth.new( ARGF.read ).to_html

View file

@ -1,4 +1,15 @@
--- %YAML:1.0
- version: 3.0.4
date: 2005-02-18
changes:
- The caps class doesn't swallow spaces.
- Horizontal rules required to be on an empty line.
- Hard breaks don't screw with Markdown headers any longer.
- Fixed error triggered by complex lists.
- Inline markups need to be butted up against enclosing text, no spaces.
- Fixed problem with intermingled single and double quotes.
- Brought back lite_mode.
- version: 3.0.3
date: 2005-02-06
changes:

View file

@ -4,9 +4,7 @@ p=. !redcloth3-title.png!
h4. Get RedCloth 3
p(example1). *Stable version:* "2.0.11":http://rubyforge.org/frs/download.php/698/redcloth-2.0.11.tar.gz
p(example1). *Unstable version:* "3.0.2":http://rubyforge.org/frs/download.php/2852/RedCloth-3.0.2.tar.gz
p(example1). *Stable version:* "3.0.3":http://rubyforge.org/frs/download.php/2896/RedCloth-3.0.3.tar.gz
Take a complete tour of Textile at "A Textile Reference":http://hobix.com/textile/.
@ -91,7 +89,7 @@ To install RedCloth via RubyGems:
gem install RedCloth
</pre>
Or "download RedCloth":http://rubyforge.org/frs/download.php/2852/RedCloth-3.0.2.tar.gz and simply run the install.rb like so:
Or "download RedCloth":http://rubyforge.org/frs/download.php/2896/RedCloth-3.0.3.tar.gz and simply run the install.rb like so:
<pre>
ruby install.rb config

View file

@ -24,9 +24,9 @@
if it's found in a @pre@ or @code@ block.
- !!example "I am <b>very</b> serious.\n\n<pre>\n I am <b>very</b> serious.\n</pre>"
- h4. Line Breaks
- Line breaks are converted to HTML breaks.
- Line breaks are ignored.
- !!example "I spoke.\nAnd none replied."
- Line breaks can be disabled in RedCloth by turning on @fold_lines@.
- Line breaks can be converted to HTML breaks by setting @hard_breaks@.
- h4. Entities
- Single- and double-quotes around words or phrases are converted to curly quotations, much easier on the eye.
- !!example '"Observe!"'
@ -78,9 +78,9 @@
- Pluses around a passage indicate its insertion.
- !!example "You are a +pleasant+ child."
- To superscript a phrase, surround with carets.
- !!example "a ^2^ + b ^2^ = c ^2^"
- !!example "a^2^ + b^2^ = c^2^"
- To subscript, surround with tildes.
- !!example "log ~2~ x"
- !!example "log~2~x"
- h4. HTML-Specific
- Lastly, if you find yourself needing to customize the style of a passage, use percent symbols
to translate the passage as an HTML span.

View file

@ -166,7 +166,7 @@
class RedCloth < String
VERSION = '3.0.3'
VERSION = '3.0.4'
DEFAULT_RULES = [:textile, :markdown]
#
@ -193,6 +193,18 @@ class RedCloth < String
#
attr_accessor :hard_breaks
# Accessor for toggling lite mode.
#
# In lite mode, block-level rules are ignored. This means
# that tables, paragraphs, lists, and such aren't available.
# Only the inline markup for bold, italics, entities and so on.
#
# r = RedCloth.new( "And then? She *fell*!", [:lite_mode] )
# r.to_html
# #=> "And then? She <strong>fell</strong>!"
#
attr_accessor :lite_mode
#
# Accessor for toggling span caps.
#
@ -219,7 +231,7 @@ class RedCloth < String
# inline_textile_image:: Textile inline images
# inline_textile_link:: Textile inline links
# inline_textile_span:: Textile inline spans
# inline_textile_glyphs:: Textile entities (such as em-dashes and smart quotes)
# glyphs_textile:: Textile entities (such as em-dashes and smart quotes)
#
# == Markdown
#
@ -260,7 +272,7 @@ class RedCloth < String
@shelf = []
textile_rules = [:refs_textile, :block_textile_table, :block_textile_lists,
:block_textile_prefix, :inline_textile_image, :inline_textile_link,
:inline_textile_code, :inline_textile_glyphs, :inline_textile_span]
:inline_textile_code, :inline_textile_span, :glyphs_textile]
markdown_rules = [:refs_markdown, :block_markdown_setext, :block_markdown_atx, :block_markdown_rule,
:block_markdown_bq, :block_markdown_lists,
:inline_markdown_reflink, :inline_markdown_link]
@ -278,14 +290,16 @@ class RedCloth < String
# standard clean up
incoming_entities text
clean_white_space text
no_textile text
# start processor
@pre_list = []
rip_offtags text
hard_break text
refs text
blocks text
no_textile text
hard_break text
unless @lite_mode
refs text
blocks text
end
inline text
smooth_offtags text
@ -333,6 +347,8 @@ class RedCloth < String
C = "(?:#{C_CLAS}?#{C_STYL}?#{C_LNGE}?|#{C_STYL}?#{C_LNGE}?#{C_CLAS}?|#{C_LNGE}?#{C_STYL}?#{C_CLAS}?)"
# PUNCT = Regexp::quote( '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' )
PUNCT = Regexp::quote( '!"#$%&\'*+,-./:;=?@\\^_`|~' )
PUNCT_NOQ = Regexp::quote( '!"#$&\',./:;=?@\\`|' )
PUNCT_Q = Regexp::quote( '*-_+^~%' )
HYPERLINK = '(\S+?)([^\w\s/;=\?]*?)(?=\s|<|$)'
# Text markup tags, don't conflict with block tags
@ -342,41 +358,6 @@ class RedCloth < String
'br', 'map', 'q', 'sub', 'sup', 'span', 'bdo'
]
# Elements to handle
GLYPHS = [
# [ /([^\s\[{(>])?\'([dmst]\b|ll\b|ve\b|\s|:|$)/, '\1&#8217;\2' ], # single closing
[ /([^\s\[{(>])\'/, '\1&#8217;' ], # single closing
[ /\'(?=\s|s\b|[#{PUNCT}])/, '&#8217;' ], # single closing
[ /\'/, '&#8216;' ], # single opening
# [ /([^\s\[{(])?"(\s|:|$)/, '\1&#8221;\2' ], # double closing
[ /([^\s\[{(>])"/, '\1&#8221;' ], # double closing
[ /"(?=\s|[#{PUNCT}])/, '&#8221;' ], # double closing
[ /"/, '&#8220;' ], # double opening
[ /\b( )?\.{3}/, '\1&#8230;' ], # ellipsis
[ /\b([A-Z][A-Z0-9]{2,})\b(?:[(]([^)]*)[)])/, '<acronym title="\2">\1</acronym>' ], # 3+ uppercase acronym
[ /(^|[^"][>\s])([A-Z][A-Z0-9 ]{2,})([^<a-z0-9]|$)/, '\1<span class="caps">\2</span>\3', :no_span_caps ], # 3+ uppercase caps
[ /(\.\s)?\s?--\s?/, '\1&#8212;' ], # em dash
[ /\s->\s/, ' &rarr; ' ], # right arrow
[ /\s-\s/, ' &#8211; ' ], # en dash
[ /(\d+) ?x ?(\d+)/, '\1&#215;\2' ], # dimension sign
[ /\b ?[(\[]TM[\])]/i, '&#8482;' ], # trademark
[ /\b ?[(\[]R[\])]/i, '&#174;' ], # registered
[ /\b ?[(\[]C[\])]/i, '&#169;' ] # copyright
]
H_ALGN_VALS = {
'<' => 'left',
'=' => 'center',
'>' => 'right',
'<>' => 'justify'
}
V_ALGN_VALS = {
'^' => 'top',
'-' => 'middle',
'~' => 'bottom'
}
QTAGS = [
['**', 'b'],
['*', 'strong'],
@ -398,19 +379,56 @@ class RedCloth < String
(#{rcq})
(#{C})
(?::(\S+?))?
(.+?)
(\S.*?\S|\S)
#{rcq}
(?=\W)/x
else
/(#{rcq})
(#{C})
(?::(\S+?))?
(.+?)
(?::(\S+))?
(\S.*?\S|\S)
#{rcq}/xm
end
[rc, ht, re, rtype]
end
# Elements to handle
GLYPHS = [
# [ /([^\s\[{(>])?\'([dmst]\b|ll\b|ve\b|\s|:|$)/, '\1&#8217;\2' ], # single closing
[ /([^\s\[{(>#{PUNCT_Q}][#{PUNCT_Q}]*)\'/, '\1&#8217;' ], # single closing
[ /\'(?=[#{PUNCT_Q}]*(s\b|[\s#{PUNCT_NOQ}]))/, '&#8217;' ], # single closing
[ /\'/, '&#8216;' ], # single opening
[ /</, '&lt;' ], # less-than
[ />/, '&gt;' ], # greater-than
# [ /([^\s\[{(])?"(\s|:|$)/, '\1&#8221;\2' ], # double closing
[ /([^\s\[{(>#{PUNCT_Q}][#{PUNCT_Q}]*)"/, '\1&#8221;' ], # double closing
[ /"(?=[#{PUNCT_Q}]*[\s#{PUNCT_NOQ}])/, '&#8221;' ], # double closing
[ /"/, '&#8220;' ], # double opening
[ /\b( )?\.{3}/, '\1&#8230;' ], # ellipsis
[ /\b([A-Z][A-Z0-9]{2,})\b(?:[(]([^)]*)[)])/, '<acronym title="\2">\1</acronym>' ], # 3+ uppercase acronym
[ /(^|[^"][>\s])([A-Z][A-Z0-9 ]+[A-Z0-9])([^<A-Za-z0-9]|$)/, '\1<span class="caps">\2</span>\3', :no_span_caps ], # 3+ uppercase caps
[ /(\.\s)?\s?--\s?/, '\1&#8212;' ], # em dash
[ /\s->\s/, ' &rarr; ' ], # right arrow
[ /\s-\s/, ' &#8211; ' ], # en dash
[ /(\d+) ?x ?(\d+)/, '\1&#215;\2' ], # dimension sign
[ /\b ?[(\[]TM[\])]/i, '&#8482;' ], # trademark
[ /\b ?[(\[]R[\])]/i, '&#174;' ], # registered
[ /\b ?[(\[]C[\])]/i, '&#169;' ] # copyright
]
H_ALGN_VALS = {
'<' => 'left',
'=' => 'center',
'>' => 'right',
'<>' => 'justify'
}
V_ALGN_VALS = {
'^' => 'top',
'-' => 'middle',
'~' => 'bottom'
}
#
# Flexible HTML escaping
#
@ -530,7 +548,7 @@ class RedCloth < String
depth.pop
end
end
if depth.last.length == tl.length
if depth.last and depth.last.length == tl.length
lines[line_id - 1] << '</li>'
end
end
@ -577,7 +595,7 @@ class RedCloth < String
end
def hard_break( text )
text.gsub!( /(.)\n(?! *[#*\s|]|$)/, "\\1<br />" ) if hard_breaks
text.gsub!( /(.)\n(?!\Z| *([#*=]+(\s|$)|[{|]))/, "\\1<br />" ) if hard_breaks
end
BLOCKS_GROUP_RE = /\n{2,}(?! )/m
@ -705,9 +723,9 @@ class RedCloth < String
end
end
MARKDOWN_RULE_RE = /^#{
MARKDOWN_RULE_RE = /^(#{
['*', '-', '_'].collect { |ch| '( ?' + Regexp::quote( ch ) + ' ?){3,}' }.join( '|' )
}$/
})$/
def block_markdown_rule( text )
text.gsub!( MARKDOWN_RULE_RE ) do |blk|
@ -719,9 +737,6 @@ class RedCloth < String
def block_markdown_lists( text )
end
def inline_markdown_link( text )
end
def inline_textile_span( text )
QTAGS.each do |qtag_rc, ht, qtag_re, rtype|
text.gsub!( qtag_re ) do |m|
@ -903,12 +918,12 @@ class RedCloth < String
def shelve( val )
@shelf << val
" <#{ @shelf.length }>"
" :redsh##{ @shelf.length }:"
end
def retrieve( text )
@shelf.each_with_index do |r, i|
text.gsub!( " <#{ i + 1 }>", r )
text.gsub!( " :redsh##{ i + 1 }:", r )
end
end
@ -965,7 +980,7 @@ class RedCloth < String
HASTAG_MATCH = /(<\/?\w[^\n]*?>)/m
ALLTAG_MATCH = /(<\/?\w[^\n]*?>)|.*?(?=<\/?\w[^\n]*?>|$)/m
def inline_textile_glyphs( text, level = 0 )
def glyphs_textile( text, level = 0 )
if text !~ HASTAG_MATCH
pgl text
footnote_ref text
@ -981,11 +996,11 @@ class RedCloth < String
codepre = 0 if codepre < 0
end
elsif codepre.zero?
inline_textile_glyphs( line, level + 1 )
glyphs_textile( line, level + 1 )
else
htmlesc( line, :NoQuotes )
end
## p [level, codepre, orig_line, line]
# p [level, codepre, line]
line
end
@ -1033,8 +1048,10 @@ class RedCloth < String
end
def inline( text )
@rules.each do |rule_name|
method( rule_name ).call( text ) if rule_name.to_s.match /^inline_/
[/^inline_/, /^glyphs_/].each do |meth_re|
@rules.each do |rule_name|
method( rule_name ).call( text ) if rule_name.to_s.match( meth_re )
end
end
end
@ -1097,7 +1114,7 @@ class RedCloth < String
q2 = ( q != '' ? q : '\s' )
if raw[3] =~ /#{prop}\s*=\s*#{q}([^#{q2}]+)#{q}/i
attrv = $1
next if prop == 'src' and attrv !~ /^http/
next if prop == 'src' and attrv =~ %r{^(?!http)\w+:}
pcs << "#{prop}=\"#{$1.gsub('"', '\\"')}\""
break
end

View file

@ -5,7 +5,9 @@ require 'yaml'
Dir["tests/*.yml"].each do |testfile|
YAML::load_documents( File.open( testfile ) ) do |doc|
if doc['in'] and doc['out']
red = RedCloth.new( doc['in'] )
opts = []
opts << :hard_breaks if testfile =~ /hard_breaks/
red = RedCloth.new( doc['in'], opts )
html = if testfile =~ /markdown/
red.to_html( :markdown )
else

1376
vendor/RedCloth-3.0.4/setup.rb vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,26 @@
---
in: |
|This|is|a|row|
{background:#ddd}. |This|is|grey|row|
|This|is|another|row|
out: |-
<table>
<tr>
<td>This</td>
<td>is</td>
<td>a</td>
<td>row</td>
</tr>
<tr style="background:#ddd;">
<td>This</td>
<td>is</td>
<td>grey</td>
<td>row</td>
</tr>
<tr>
<td>This</td>
<td>is</td>
<td>another</td>
<td>row</td>
</tr>
</table>

View file

@ -39,28 +39,28 @@ out: |-
<td>11/18/04</td>
<td>11/18/04</td>
<td>070</td>
<td>XML spec complete</td>
<td><span class="caps">XML</span> spec complete</td>
</tr>
<tr>
<td><img src="/i/g.gif" alt="" /></td>
<td>11/29/04</td>
<td>11/29/04</td>
<td>011</td>
<td>XML spec complete (KH is on schedule)</td>
<td><span class="caps">XML</span> spec complete (KH is on schedule)</td>
</tr>
<tr>
<td><img src="/i/g.gif" alt="" /></td>
<td>11/29/04</td>
<td>11/29/04</td>
<td>051</td>
<td>XML spec complete (KH is on schedule)</td>
<td><span class="caps">XML</span> spec complete (KH is on schedule)</td>
</tr>
<tr>
<td><img src="/i/g.gif" alt="" /></td>
<td>11/29/04</td>
<td>11/29/04</td>
<td>081</td>
<td>XML spec complete (KH is on schedule)</td>
<td><span class="caps">XML</span> spec complete (KH is on schedule)</td>
</tr>
<tr>
<td><img src="/i/g.gif" alt="" /></td>

View file

@ -71,6 +71,12 @@ out: <p><strong>a phrase</strong></p>
in: '**a phrase**'
out: <p><b>a phrase</b></p>
---
in: '*(a)* a'
out: <p><strong>(a)</strong> a</p>
---
in: '*(a)* *'
out: <p><strong>(a)</strong> *</p>
---
in: Nabokov's ??Pnin??
out: <p>Nabokov&#8217;s <cite>Pnin</cite></p>
---
@ -395,3 +401,6 @@ out: |-
<li>We must act</li>
</ul>
---
in: '"test":http://foo.com/b---ar'
out: <p><a href="http://foo.com/b---ar">test</a></p>