-source :gemcutter
+source 'https://rubygems.org'
gemspec
PATH
remote: .
specs:
- wikitext (3.1)
+ wikitext (4.0)
GEM
- remote: http://rubygems.org/
+ remote: https://rubygems.org/
specs:
ZenTest (4.5.0)
diff-lcs (1.1.3)
</li>
</ol>
+= Ruby support
+
+Version 4.0.0 and above target Ruby 2.0.0 or higher.
+
+For older versions of Ruby, you may use the 3.1 release or older.
+
= Rails support
The Wikitext extension provides a template handler so that templates named
= License
-Copyright 2007-2012 Wincent Colaiuta. All rights reserved.
+Copyright 2007-2013 Wincent Colaiuta. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
#!/usr/bin/env ruby
-# encoding: utf-8
-# Copyright 2008-2009 Wincent Colaiuta. All rights reserved.
+# Copyright 2008-2013 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#!/usr/bin/env ruby
-# encoding: utf-8
-# Copyright 2008-2009 Wincent Colaiuta. All rights reserved.
+# Copyright 2008-2013 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#!/usr/bin/env ruby
-# encoding: utf-8
-# Copyright 2008-2009 Wincent Colaiuta. All rights reserved.
+# Copyright 2008-2013 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
in these release notes. For a full listing of all changes see
the source code repository at: http://git.wincent.com.
+= Changes in 4.0
+
+* requires Ruby 2.0.0; for older versions of Ruby please use a previous
+ Wikitext release
+
= Changes in 3.1
* the +link_proc+ parse option can now be set as an attribute on the parser
-# Copyright 2008-2009 Wincent Colaiuta. All rights reserved.
+# Copyright 2008-2013 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
end
case RUBY_VERSION
-when /\A1\.8/
- $CFLAGS += ' -DRUBY_1_8_x'
-when /\A1\.9/
- $CFLAGS += ' -DRUBY_1_9_x'
+when /\A2\.0/
+ $CFLAGS += ' -DRUBY_2_0_x'
else
raise "unsupported Ruby version: #{RUBY_VERSION}"
end
str_append(parser->output, null_str, 1); // null-terminate
len = parser->output->len - 1; // don't count null termination
-#if defined(RUBY_1_9_x)
VALUE out = rb_str_buf_new(RSTRING_EMBED_LEN_MAX + 1);
free(RSTRING_PTR(out));
RSTRING(out)->as.heap.aux.capa = len;
RSTRING(out)->as.heap.ptr = parser->output->ptr;
RSTRING(out)->as.heap.len = len;
-#elif defined(RUBY_1_8_x)
- VALUE out = rb_str_new2("");
- free(RSTRING_PTR(out));
- RSTRING(out)->len = len;
- RSTRING(out)->aux.capa = len;
- RSTRING(out)->ptr = parser->output->ptr;
-#else
-#error unsupported RUBY_VERSION
-#endif
parser->output->ptr = NULL; // don't double-free
return out;
}
VALUE string_from_str(str_t *str)
{
- return rb_str_new(str->ptr, str->len);
+ VALUE string = rb_str_new(str->ptr, str->len);
+ rb_funcall(string, rb_intern("force_encoding"), 1, rb_str_new2("UTF-8"));
+ return string;
}
void str_grow(str_t *str, long len)
# POSSIBILITY OF SUCH DAMAGE.
module Wikitext
- VERSION = '3.1.0.99'
+ VERSION = '4.0'
end # module Wikitext
-# Copyright 2007-2010 Wincent Colaiuta. All rights reserved.
+# Copyright 2007-2013 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# POSSIBILITY OF SUCH DAMAGE.
require 'spec_helper'
-require 'iconv'
describe Wikitext, 'with invalidly encoded input' do
before do
-# encoding: utf-8
-# Copyright 2007-2012 Wincent Colaiuta. All rights reserved.
+# Copyright 2007-2013 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
-# encoding: utf-8
-# Copyright 2008-2010 Wincent Colaiuta. All rights reserved.
+# Copyright 2008-2013 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
-# encoding: utf-8
-# Copyright 2008-2010 Wincent Colaiuta. All rights reserved.
+# Copyright 2008-2013 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
-# encoding: utf-8
-# Copyright 2007-2010 Wincent Colaiuta. All rights reserved.
+# Copyright 2007-2013 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
-# encoding: utf-8
# Copyright 2007-2013 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
lambda { @parser.parse('[[foo]]', :link_proc => lambda { |target| raise 'bar' }) }.should raise_error(RuntimeError, /bar/)
end
- it 'should complain if the link proc returns a non-stringy object (Proc object version)' do
- lambda {
- @parser.parse '[[foo]]', :link_proc => Proc.new { 1 }
- }.should raise_error(TypeError, /can't convert/)
+ it 'complains if the link proc returns a non-stringy object (Proc object version)' do
+ expect { @parser.parse '[[foo]]', link_proc: proc { 1 } }.
+ to raise_error(TypeError)
end
- it 'should complain if the link proc returns a non-stringy object (lambda version)' do
- lambda {
- @parser.parse '[[foo]]', :link_proc => lambda { 1 }
- }.should raise_error(TypeError, /can't convert/)
+ it 'complains if the link proc returns a non-stringy object (lambda version)' do
+ expect { @parser.parse '[[foo]]', link_proc: lambda { |target| 1 } }.
+ to raise_error(TypeError)
end
# a couple of Ruby's idiosynchrasies: different behaviour of lambdas and Procs
}.should raise_error(ArgumentError, /wrong number/)
end
- it 'should complain when "return" is used inside a "Proc.new" block' do
- lambda {
- @parser.parse '[[foo]]', :link_proc => Proc.new { return 'bar' }
- }.should raise_error(LocalJumpError)
+ it 'complains when "return" is used inside a "Proc.new" block' do
+ expect {
+ @parser.parse '[[foo]]', link_proc: proc { return 'bar' }
+ }.to raise_error(LocalJumpError)
end
it 'should not complain when "return" is used inside a lambda' do
- lambda {
- @parser.parse '[[foo]]', :link_proc => lambda { return 'bar' }
- }.should_not raise_error(LocalJumpError)
+ expect {
+ @parser.parse '[[foo]]', link_proc: lambda { return 'bar' }
+ }.to_not raise_error(LocalJumpError)
end
it 'should interact correctly with spaces in link targets (Proc object version)' do
@parser.parse('[[foo a|hello]] [[bar b|world]]', :link_proc => link_proc).should == expected
end
- it 'should handle link targets with encoded parts (Proc object version)' do
- link_proc = Proc.new { |target| target == 'información' ? 'redlink' : nil }
+ it 'handles link targets with encoded parts (Proc object version)' do
+ link_proc = proc { |target| target == 'información' ? 'redlink' : nil }
expected = %Q{<p><a href="/wiki/informaci%c3%b3n" class="redlink">información</a> <a href="/wiki/bar">bar</a></p>\n}
- @parser.parse('[[información]] [[bar]]', :link_proc => link_proc).should == expected
+ @parser.parse('[[información]] [[bar]]', link_proc: link_proc).should == expected
end
it 'should handle link targets with encoded parts (lambda version)' do
lambda { @parser.parse('[[foo]]', :link_proc => lambda { |target| raise 'bar' }) }.should raise_error(RuntimeError, /bar/)
end
- it 'should complain if the link proc returns a non-stringy object (Proc object version)' do
- lambda {
- @parser.parse '[[foo]]', :link_proc => Proc.new { 1 }
- }.should raise_error(TypeError, /can't convert/)
+ it 'complains if the link proc returns a non-stringy object (Proc object version)' do
+ expect { @parser.parse '[[foo]]', link_proc: proc { 1 } }.
+ to raise_error(TypeError)
end
- it 'should complain if the link proc returns a non-stringy object (lambda version)' do
- lambda {
- @parser.parse '[[foo]]', :link_proc => lambda { 1 }
- }.should raise_error(TypeError, /can't convert/)
+ it 'complains if the link proc returns a non-stringy object (lambda version)' do
+ expect { @parser.parse '[[foo]]', link_proc: lambda { |target| 1 } }.
+ to raise_error(TypeError)
end
# a couple of Ruby's idiosynchrasies: different behaviour of lambdas and Procs
it 'should not complain if the Proc object accepts too many arguments' do
lambda {
- @parser.parse '[[foo]]', :link_proc => Proc.new { |a,b| }
+ @parser.parse '[[foo]]', :link_proc => Proc.new { |a, b| }
}.should_not raise_error(ArgumentError, /wrong number/)
end
it 'should complain if the lambda accepts too many arguments' do
lambda {
- @parser.parse '[[foo]]', :link_proc => lambda { |a,b| }
+ @parser.parse '[[foo]]', :link_proc => lambda { |a, b| }
}.should raise_error(ArgumentError, /wrong number/)
end
it 'should complain when "return" is used inside a "Proc.new" block' do
- lambda {
+ expect {
@parser.parse '[[foo]]', :link_proc => Proc.new { return 'bar' }
- }.should raise_error(LocalJumpError)
+ }.to raise_error(LocalJumpError)
end
it 'should not complain when "return" is used inside a lambda' do
- lambda {
+ expect {
@parser.parse '[[foo]]', :link_proc => lambda { return 'bar' }
- }.should_not raise_error(LocalJumpError)
+ }.to_not raise_error(LocalJumpError)
end
it 'should interact correctly with spaces in link targets (Proc object version)' do
@parser.parse('[[información]] [[bar]]', :link_proc => link_proc).should == expected
end
- it 'should handle link targets with encoded parts (lambda version)' do
+ it 'handles link targets with encoded parts (lambda version)' do
link_proc = lambda { |target| target == 'información' ? 'redlink' : nil }
expected = %Q{<p><a href="/wiki/informaci%c3%b3n" class="redlink">información</a> <a href="/wiki/bar">bar</a></p>\n}
- @parser.parse('[[información]] [[bar]]', :link_proc => link_proc).should == expected
+ @parser.parse('[[información]] [[bar]]', link_proc: link_proc).should == expected
end
end
-# encoding: utf-8
-# Copyright 2007-2010 Wincent Colaiuta. All rights reserved.
+# Copyright 2007-2013 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
-# encoding: utf-8
-# Copyright 2007-2010 Wincent Colaiuta. All rights reserved.
+# Copyright 2007-2013 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
-# encoding: utf-8
-# Copyright 2007-2010 Wincent Colaiuta. All rights reserved.
+# Copyright 2007-2013 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
-# encoding: utf-8
-# Copyright 2007-2010 Wincent Colaiuta. All rights reserved.
+# Copyright 2007-2013 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
-# encoding: utf-8
-# Copyright 2008-2011 Wincent Colaiuta. All rights reserved.
+# Copyright 2008-2013 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
-# Copyright 2007-2010 Wincent Colaiuta. All rights reserved.
+# Copyright 2007-2013 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# allow indenting of multiline spec data for better readability
# but must dedent it before actually doing the comparison
-def dedent spaces, string = nil
+def dedent(spaces, string = nil)
if spaces.kind_of? String
- if not string.nil?
+ if !string.nil?
raise 'When first argument is a String, second argument must be nil'
else
# default use: single String parameter, dedent by 6
spaces = 6
end
elsif spaces.kind_of? Integer
- if string.nil? or not string.kind_of?(String)
+ if string.nil? || !string.kind_of?(String)
raise 'When first argument is a number, second must be a String'
end
else
raise 'Invalid argument'
end
string.each_line do |line|
- if not line =~ /\A {#{spaces.to_i}}/
+ if line !~ /\A {#{spaces.to_i}}/
raise "Underlength indent for line: #{line.inspect}"
end
end
end
# prepend local directories to search path if not already present
-basedir = Pathname.new(__FILE__).dirname + '..'
+basedir = Pathname.new(__dir__) + '..'
extdir = (basedir + 'ext').realpath
libdir = (basedir + 'lib').realpath
normalized = $:.map { |path| Pathname.new(path).realpath rescue path }
[libdir, extdir].each { |d| $:.unshift(d) unless normalized.include?(d) }
module UTF8
- if not const_defined? 'Invalid'
- module Invalid
- TWO_BYTES_MISSING_SECOND_BYTE = [0b11011111].pack('C*')
- TWO_BYTES_MALFORMED_SECOND_BYTE = [0b11011111, 0b00001111].pack('C*') # should be 10......
- OVERLONG = [0b11000000, 0b10000000].pack('C*') # lead byte is 110..... but code point is <= 127
- OVERLONG_ALT = [0b11000001, 0b10000000].pack('C*') # lead byte is 110..... but code point is <= 127
- THREE_BYTES_MISSING_SECOND_BYTE = [0b11100000].pack('C*')
- THREE_BYTES_MISSING_THIRD_BYTE = [0b11100000, 0b10000000].pack('C*')
- THREE_BYTES_MALFORMED_SECOND_BYTE = [0b11100000, 0b00001111, 0b10000000].pack('C*') # should be 10......
- THREE_BYTES_MALFORMED_THIRD_BYTE = [0b11100000, 0b10000000, 0b00001111].pack('C*') # should be 10......
- FOUR_BYTES_MISSING_SECOND_BYTE = [0b11110000].pack('C*')
- FOUR_BYTES_MISSING_THIRD_BYTE = [0b11110000, 0x10111111].pack('C*')
- FOUR_BYTES_MISSING_FOURTH_BYTE = [0b11110000, 0x10111111, 0x10111111].pack('C*')
- FOUR_BYTES_ILLEGAL_FIRST_BYTE = [0b11110101, 0x10111111, 0x10111111, 0x10111111].pack('C*')
- FOUR_BYTES_ILLEGAL_FIRST_BYTE_ALT = [0b11110101, 0x10111111, 0x10111111, 0x10111111].pack('C*')
- FOUR_BYTES_ILLEGAL_FIRST_BYTE_ALT2 = [0b11110101, 0x10111111, 0x10111111, 0x10111111].pack('C*')
- UNEXPECTED_BYTE = [0b11111000].pack('C*')
- end # module Invalid
- end
+ module Invalid
+ TWO_BYTES_MISSING_SECOND_BYTE = [0b11011111].pack('C*')
+ TWO_BYTES_MALFORMED_SECOND_BYTE = [0b11011111, 0b00001111].pack('C*') # should be 10......
+ OVERLONG = [0b11000000, 0b10000000].pack('C*') # lead byte is 110..... but code point is <= 127
+ OVERLONG_ALT = [0b11000001, 0b10000000].pack('C*') # lead byte is 110..... but code point is <= 127
+ THREE_BYTES_MISSING_SECOND_BYTE = [0b11100000].pack('C*')
+ THREE_BYTES_MISSING_THIRD_BYTE = [0b11100000, 0b10000000].pack('C*')
+ THREE_BYTES_MALFORMED_SECOND_BYTE = [0b11100000, 0b00001111, 0b10000000].pack('C*') # should be 10......
+ THREE_BYTES_MALFORMED_THIRD_BYTE = [0b11100000, 0b10000000, 0b00001111].pack('C*') # should be 10......
+ FOUR_BYTES_MISSING_SECOND_BYTE = [0b11110000].pack('C*')
+ FOUR_BYTES_MISSING_THIRD_BYTE = [0b11110000, 0x10111111].pack('C*')
+ FOUR_BYTES_MISSING_FOURTH_BYTE = [0b11110000, 0x10111111, 0x10111111].pack('C*')
+ FOUR_BYTES_ILLEGAL_FIRST_BYTE = [0b11110101, 0x10111111, 0x10111111, 0x10111111].pack('C*')
+ FOUR_BYTES_ILLEGAL_FIRST_BYTE_ALT = [0b11110101, 0x10111111, 0x10111111, 0x10111111].pack('C*')
+ FOUR_BYTES_ILLEGAL_FIRST_BYTE_ALT2 = [0b11110101, 0x10111111, 0x10111111, 0x10111111].pack('C*')
+ UNEXPECTED_BYTE = [0b11111000].pack('C*')
+ end # module Invalid
end # module UTF8
require 'wikitext'
-# encoding: utf-8
# Copyright 2007-2013 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
-# Copyright 2010-2012 Wincent Colaiuta. All rights reserved.
+# Copyright 2010-2013 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
require 'wikitext/version'
Gem::Specification.new do |s|
- s.name = 'wikitext'
- s.version = Wikitext::VERSION
- s.author = 'Wincent Colaiuta'
- s.email = 'win@wincent.com'
- s.homepage = 'https://wincent.com/products/wikitext'
- s.rubyforge_project = 'wikitext'
- s.platform = Gem::Platform::RUBY
- s.summary = 'Wikitext-to-HTML translator'
- s.description = <<-ENDDESC
+ s.name = 'wikitext'
+ s.version = Wikitext::VERSION
+ s.author = 'Wincent Colaiuta'
+ s.email = 'win@wincent.com'
+ s.homepage = 'https://wincent.com/products/wikitext'
+ s.rubyforge_project = 'wikitext'
+ s.platform = Gem::Platform::RUBY
+ s.required_ruby_version = '>= 2.0.0'
+ s.summary = 'Wikitext-to-HTML translator'
+ s.description = <<-DESC
Wikitext is a fast wikitext-to-HTML translator written in C.
- ENDDESC
+ DESC
s.require_paths = ['ext', 'lib']
s.files = Dir['bin/wikitext',
'ext/*.{rb,c,h}',
'spec/*.rb']
s.extensions = ['ext/extconf.rb']
s.executables = ['wikitext']
-
- if !s.respond_to? :add_development_dependency
- def s.add_development_dependency gem, *requirements
- s.add_dependency gem, *requirements
- end
- end
s.add_development_dependency 'rake'
s.add_development_dependency 'rspec', '>= 2.0'
s.add_development_dependency 'thor'