creole-0.5.0/ 0000755 0000041 0000041 00000000000 12055507032 013014 5 ustar www-data www-data creole-0.5.0/.travis.yml 0000644 0000041 0000041 00000000117 12055507032 015124 0 ustar www-data www-data rvm: - 1.8.7 - 1.9.3 - ruby-head - jruby - rbx-18mode - rbx-19mode creole-0.5.0/test/ 0000755 0000041 0000041 00000000000 12055507032 013773 5 ustar www-data www-data creole-0.5.0/test/parser_test.rb 0000644 0000041 0000041 00000071762 12055507032 016670 0 ustar www-data www-data require 'creole' class Bacon::Context def tc(html, creole, options = {}) Creole.creolize(creole, options).should.equal html end def tce(html, creole) tc(html, creole, :extensions => true) end end describe Creole::Parser do it 'should parse bold' do # Creole1.0: Bold can be used inside paragraphs tc "
This is bold
", "This **is** bold" tc "This is bold and boldish
", "This **is** bold and **bold**ish" # Creole1.0: Bold can be used inside list items tc "This is bold |
A bold link: http://wikicreole.org/ nice!
", "A bold link: **http://wikicreole.org/ nice!**") # Creole1.0: Bold will end at the end of paragraph tc "This is bold
", "This **is bold" # Creole1.0: Bold will end at the end of list items tc("Item bold | Another bold |
This is
bold maybe
", "This **is\n\nbold** maybe") # Creole1.0-Implied: Bold should be able to cross lines tc "This is bold
", "This **is\nbold**" end it 'should parse italic' do # Creole1.0: Italic can be used inside paragraphs tc("This is italic
", "This //is// italic") tc("This is italic and italicish
", "This //is// italic and //italic//ish") # Creole1.0: Italic can be used inside list items tc "This is italic |
A italic link: http://wikicreole.org/ nice!
", "A italic link: //http://wikicreole.org/ nice!//") # Creole1.0: Italic will end at the end of paragraph tc "This is italic
", "This //is italic" # Creole1.0: Italic will end at the end of list items tc("Item italic | Another italic |
This is
italic maybe
", "This //is\n\nitalic// maybe") # Creole1.0-Implied: Italic should be able to cross lines tc "This is italic
", "This //is\nitalic//" end it 'should parse bold italics' do # Creole1.0: By example tc "bold italics
", "**//bold italics//**" # Creole1.0: By example tc "bold italics
", "//**bold italics**//" # Creole1.0: By example tc "This is also good.
", "//This is **also** good.//" end it 'should parse headings' do # Creole1.0: Only three differed sized levels of heading are required. tc "== Heading 2 == foo
", " == Heading 2 == foo" tc "foo = Heading 1 =
", "foo = Heading 1 =" end it 'should parse links' do # Creole1.0: Links tc "", "[[link]]" # Creole1.0: Links can appear in paragraphs (i.e. inline item) tc "Hello, world
", "Hello, [[world]]" # Creole1.0: Named links tc "", "[[MyBigPage|Go to my page]]" # Creole1.0: URLs tc "", "[[http://www.wikicreole.org/]]" # Creole1.0: Single punctuation characters at the end of URLs # should not be considered a part of the URL. [',','.','?','!',':',';','\'','"'].each do |punct| esc_punct = CGI::escapeHTML(punct) tc "http://www.wikicreole.org/#{esc_punct}
", "http://www.wikicreole.org/#{punct}" end # Creole1.0: Nameds URLs (by example) tc("", "[[http://www.wikicreole.org/|Visit the WikiCreole website]]") # WRNING: Parsing markup within a link is optional tc "", "[[Weird Stuff|**Weird** //Stuff//]]" tc("", "[[http://example.org/|{{image.jpg}}]]") # Inside bold tc "", "**[[link]]**" # Whitespace inside [[ ]] should be ignored tc("", "[[ link ]]") tc("", "[[ link me ]]") tc("", "[[ http://dot.com/ \t| \t dot.com ]]") tc("", "[[ http://dot.com/ | dot.com ]]") end it 'should parse freestanding urls' do # Creole1.0: Free-standing URL's should be turned into links tc "", "http://www.wikicreole.org/" # URL ending in . tc "Text http://wikicreole.org. other text
", "Text http://wikicreole.org. other text" # URL ending in ), tc "Text (http://wikicreole.org), other text
", "Text (http://wikicreole.org), other text" # URL ending in ). tc "Text (http://wikicreole.org). other text
", "Text (http://wikicreole.org). other text" # URL ending in ). tc "Text (http://wikicreole.org).
", "Text (http://wikicreole.org)." # URL ending in ) tc "Text (http://wikicreole.org)
", "Text (http://wikicreole.org)" end it 'should parse paragraphs' do # Creole1.0: One or more blank lines end paragraphs. tc "This is my text.
This is more text.
", "This is\nmy text.\n\nThis is\nmore text." tc "This is my text.
This is more text.
", "This is\nmy text.\n\n\nThis is\nmore text." tc "This is my text.
This is more text.
", "This is\nmy text.\n\n\n\nThis is\nmore text." # Creole1.0: A list end paragraphs too. tc "Hello
Hello
Cell |
Hello
nowiki", "Hello\n{{{\nnowiki\n}}}\n" # WARNING: A heading ends a paragraph (not specced) tc "
Hello
This is the first line,
and this is the second.
Par
", "* Item\n\nPar\n") # Creole1.0: An item ends at a heading tc("Cell |
Code", "* Item\n{{{\nCode\n}}}\n") # Creole1.0: An item can span multiple lines tc("
Not bold
", "*Hello,\nWorld!\n\n**Not bold\n") end it 'should parse ordered lists' do # Creole1.0: List items begin with a * at the beginning of a line. # Creole1.0: An item ends at the next * tc "Par
", "# Item\n\nPar\n") # Creole1.0: An item ends at a heading tc("Cell |
Code", "# Item\n{{{\nCode\n}}}\n") # Creole1.0: An item can span multiple lines tc("
This is what can go wrong:this should be an italic text.
", "This is what can go wrong://this should be an italic text//.") # A link inside italic text tc("How about a link, like http://example.org, in italic text?
", "How about //a link, like http://example.org, in italic// text?") # Another test from Creole Wiki tc("Formatted fruits, for example:apples, oranges, pears ...
", "Formatted fruits, for example://apples//, oranges, **pears** ...") end it 'should parse ambiguious bold and lists' do tc "bold text
", "** bold text **" tc "bold text
", " ** bold text **" end it 'should parse nowiki' do # ... works as block tc "Hello", "{{{\nHello\n}}}\n" # ... works inline tc "
Hello world.
", "Hello {{{world}}}." tc "Hello world.
", "{{{Hello}}} {{{world}}}." # Creole1.0: No wiki markup is interpreted inbetween tc "**Hello**", "{{{\n**Hello**\n}}}\n" # Creole1.0: Leading whitespaces are not permitted tc("
{{{ Hello }}}
", " {{{\nHello\n}}}") tc("{{{ Hello }}}
", "{{{\nHello\n }}}") # Assumed: Should preserve whitespace tc("\t Hello, \t \n \t World \t", "{{{\n \t Hello, \t \n \t World \t \n}}}\n") # In preformatted blocks ... one leading space is removed tc("
nowikiblock\n}}}", "{{{\nnowikiblock\n }}}\n}}}\n") # In inline nowiki, any trailing closing brace is included in the span tc("
this is nowiki}
", "this is {{{nowiki}}}}") tc("this is nowiki}}
", "this is {{{nowiki}}}}}") tc("this is nowiki}}}
", "this is {{{nowiki}}}}}}") tc("this is nowiki}}}}
", "this is {{{nowiki}}}}}}}") end it 'should escape html' do # Special HTML chars should be escaped tc("<b>not bold</b>
", "not bold") # Image tags should be escape tc("** Not Bold **
", "~** Not Bold ~**" tc "// Not Italic //
", "~// Not Italic ~//" tc "* Not Bullet
", "~* Not Bullet" # Following char is not a blank (space or line feed) tc "Hello ~ world
", "Hello ~ world\n" tc "Hello ~ world
", "Hello ~\nworld\n" # Not escaping inside URLs (Creole1.0 not clear on this) tc "", "http://example.org/~user/" # Escaping links tc "http://www.wikicreole.org/
", "~http://www.wikicreole.org/" end it 'should parse horizontal rule' do # Creole: Four hyphens make a horizontal rule tc "foo ----
", "foo ----\n" tc "---- foo
", "---- foo\n" # Creole1.0: [...] no whitespace is allowed between them tc "-- --
", " -- -- " tc "-- --
", " --\t-- " end it 'should parse table' do tc "Hello, World! |
c1 | c2 | c3 |
c11 | c12 |
c21 | c22 |
c1 | c2 | c3 |
c1 | c3 |
c1|c2 | c3 |
c1 | c2| |
c1 | c2| |
c1 | c2| |
Header |
---|
c1 | Link text |
table |
table |
table |
par
", "|table|\npar\n") tc("table |
par
", "|table|\n\npar\n") # table followed by unordered list tc("table |
table |
table |
table |
table |
table |
table |
pre", "|table|\n{{{\npre\n}}}\n") tc("
table |
pre", "|table|\n\n{{{\npre\n}}}\n") # table followed by table tc("
table |
table |
table |
table |
par
", "=heading=\npar\n") tc("par
", "=heading=\n\npar\n") # unordered list tc("nowiki", "=heading=\n{{{\nnowiki\n}}}\n") tc("
nowiki", "=heading=\n\n{{{\nnowiki\n}}}\n") # table tc("
table |
table |
par
par
par par
", "par\npar\n") tc("par
par
", "par\n\npar\n") # unordered tc("par
par
par
par
par
par
par
nowiki", "par\n{{{\nnowiki\n}}}\n") tc("
par
nowiki", "par\n\n{{{\nnowiki\n}}}\n") # table tc("
par
table |
par
table |
par
", "*item\n\npar\n") # unordered tc("nowiki", "*item\n{{{\nnowiki\n}}}\n") tc("
nowiki", "*item\n\n{{{\nnowiki\n}}}\n") # table tc("
table |
table |
par
", "#item\n\npar\n") # unordered tc("nowiki", "#item\n{{{\nnowiki\n}}}\n") tc("
nowiki", "#item\n\n{{{\nnowiki\n}}}\n") # table tc("
table |
table |
par
", "----\npar\n") tc("par
", "----\n\npar\n") # unordered tc("nowiki", "----\n{{{\nnowiki\n}}}\n") tc("
nowiki", "----\n\n{{{\nnowiki\n}}}\n") # table tc("
table |
table |
nowiki
nowiki
nowiki
par
", "{{{\nnowiki\n}}}\npar") tc("nowiki
par
", "{{{\nnowiki\n}}}\n\npar") # unordered tc("nowiki
nowiki
nowiki
nowiki
nowiki
nowiki
nowiki
nowiki", "{{{\nnowiki\n}}}\n{{{\nnowiki\n}}}\n") tc("
nowiki
nowiki", "{{{\nnowiki\n}}}\n\n{{{\nnowiki\n}}}\n") # table tc("
nowiki
table |
nowiki
table |
bold and
table |
end
", "**bold and\n|table|\nend**") end it 'should support extensions' do tc("This is not __underlined__
", "This is not __underlined__") tce("This is underlined
", "This is __underlined__") tce("This is deleted
This is inserted
", "This is ++inserted++") tce("This is super
", "This is ^^super^^") tce("This is sub
", "This is ~~sub~~") tce("®
", "(R)") tce("®
", "(r)") tce("©
", "(C)") tce("©
", "(c)") end it 'should support no_escape' do tc("", "[[a/b/c]]") tc("", "[[a/b/c]]", :no_escape => true) end end creole-0.5.0/README.creole 0000644 0000041 0000041 00000001557 12055507032 015154 0 ustar www-data www-data = Creole Creole is a Creole-to-HTML converter for Creole, the lightweight markup language (http://wikicreole.org/). Github uses this converter to render *.creole files. Project page on github: * http://github.com/larsch/creole Project page on rubyforge: * http://creole.rubyforge.org/ * http://rubyforge.org/projects/creole/ RDOC: * http://rdoc.info/projects/larsch/creole == INSTALLATION {{{ gem install creole }}} == SYNOPSIS {{{ require 'creole' html = Creole.creolize('== Creole text') }}} == BUGS If you found a bug, please report it at the Creole project's tracker on GitHub: http://github.com/larsch/creole/issues == AUTHORS * Lars Christensen (larsch) * Daniel Mendler (minad) == LICENSE Creole is Copyright (c) 2008 Lars Christensen. It is free software, and may be redistributed under the terms specified in the README file of the Ruby distribution. creole-0.5.0/Rakefile 0000644 0000041 0000041 00000000240 12055507032 014455 0 ustar www-data www-data task :default => :test desc 'Run tests with bacon' task :test => FileList['test/*_test.rb'] do |t| sh "bacon -q -Ilib:test #{t.prerequisites.join(' ')}" end creole-0.5.0/creole.gemspec 0000644 0000041 0000041 00000001461 12055507032 015634 0 ustar www-data www-data # -*- encoding: utf-8 -*- require File.dirname(__FILE__) + '/lib/creole/version' require 'date' Gem::Specification.new do |s| s.name = 'creole' s.version = Creole::VERSION s.date = Date.today.to_s s.authors = ['Lars Christensen', 'Daniel Mendler'] s.email = ['larsch@belunktum.dk', 'mail@daniel-mendler.de'] s.summary = 'Lightweight markup language' s.description = 'Creole is a lightweight markup language (http://wikicreole.org/).' s.extra_rdoc_files = %w(README.creole) s.rubyforge_project = s.name s.files = `git ls-files`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = %w(lib) s.homepage = 'http://github.com/minad/creole' s.add_development_dependency('bacon') s.add_development_dependency('rake') end creole-0.5.0/metadata.yml 0000644 0000041 0000041 00000003357 12055507032 015327 0 ustar www-data www-data --- !ruby/object:Gem::Specification name: creole version: !ruby/object:Gem::Version version: 0.5.0 prerelease: platform: ruby authors: - Lars Christensen - Daniel Mendler autorequire: bindir: bin cert_chain: [] date: 2012-10-29 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: bacon requirement: &7674580 !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: *7674580 - !ruby/object:Gem::Dependency name: rake requirement: &7674100 !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: *7674100 description: Creole is a lightweight markup language (http://wikicreole.org/). email: - larsch@belunktum.dk - mail@daniel-mendler.de executables: [] extensions: [] extra_rdoc_files: - README.creole files: - .gitignore - .travis.yml - CHANGES - Gemfile - README.creole - Rakefile - creole.gemspec - lib/creole.rb - lib/creole/parser.rb - lib/creole/version.rb - test/parser_test.rb homepage: http://github.com/minad/creole licenses: [] post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: creole rubygems_version: 1.8.15 signing_key: specification_version: 3 summary: Lightweight markup language test_files: [] creole-0.5.0/Gemfile 0000644 0000041 0000041 00000000032 12055507032 014302 0 ustar www-data www-data source :rubygems gemspec creole-0.5.0/CHANGES 0000644 0000041 0000041 00000000146 12055507032 014010 0 ustar www-data www-data 0.5.0 * Remove methods make_*_anchor * Add method make_headline * Parse tags inside link text creole-0.5.0/.gitignore 0000644 0000041 0000041 00000000004 12055507032 014776 0 ustar www-data www-data doc creole-0.5.0/lib/ 0000755 0000041 0000041 00000000000 12055507032 013562 5 ustar www-data www-data creole-0.5.0/lib/creole.rb 0000644 0000041 0000041 00000000661 12055507032 015363 0 ustar www-data www-data require 'creole/parser' require 'creole/version' module Creole # Convert the argument in Creole format to HTML and return the # result. Example: # # Creole.creolize("**Hello //World//**") # #=> "Hello World
" # # This is an alias for calling Creole#parse: # Creole.new(text).to_html def self.creolize(text, options = {}) Parser.new(text, options).to_html end end creole-0.5.0/lib/creole/ 0000755 0000041 0000041 00000000000 12055507032 015033 5 ustar www-data www-data creole-0.5.0/lib/creole/version.rb 0000644 0000041 0000041 00000000046 12055507032 017045 0 ustar www-data www-data module Creole VERSION = '0.5.0' end creole-0.5.0/lib/creole/parser.rb 0000644 0000041 0000041 00000025305 12055507032 016661 0 ustar www-data www-data require 'cgi' require 'uri' # :main: Creole # The Creole parses and translates Creole formatted text into # XHTML. Creole is a lightweight markup syntax similar to what many # WikiWikiWebs use. Example syntax: # # = Heading 1 = # == Heading 2 == # === Heading 3 === # **Bold text** # //Italic text// # [[Links]] # |=Table|=Heading| # |Table |Cells | # {{image.png}} # # The simplest interface is Creole.creolize. The default handling of # links allow explicit local links using the [[link]] syntax. External # links will only be allowed if specified using http(s) and ftp(s) # schemes. If special link handling is needed, such as inter-wiki or # hierachical local links, you must inherit Creole::CreoleParser and # override make_local_link. # # You can customize the created image markup by overriding # make_image. # Main Creole parser class. Call CreoleParser#parse to parse Creole # formatted text. # # This class is not reentrant. A separate instance is needed for # each thread that needs to convert Creole to HTML. # # Inherit this to provide custom handling of links. The overrideable # methods are: make_local_link module Creole class Parser # Allowed url schemes # Examples: http https ftp ftps attr_accessor :allowed_schemes # Non-standard wiki text extensions enabled? # E.g. underlined, deleted text etc attr_writer :extensions def extensions?; @extensions; end # Disable url escaping for local links # Escaping: [[/Test]] --> %2FTest # No escaping: [[/Test]] --> Test attr_writer :no_escape def no_escape?; @no_escape; end # Create a new CreoleParser instance. def initialize(text, options = {}) @allowed_schemes = %w(http https ftp ftps) @text = text @extensions = @no_escape = nil options.each_pair {|k,v| send("#{k}=", v) } end # Convert CCreole text to HTML and return # the result. The resulting HTML does not contain and # tags. # # Example: # # parser = CreoleParser.new("**Hello //World//**", :extensions => true) # parser.to_html # #=> "Hello World
" def to_html @out = '' @p = false @stack = [] parse_block(@text) @out end protected # Escape any characters with special meaning in HTML using HTML # entities. def escape_html(string) CGI::escapeHTML(string) end # Escape any characters with special meaning in URLs using URL # encoding. def escape_url(string) CGI::escape(string) end def start_tag(tag) @stack.push(tag) @out << '<' << tag << '>' end def end_tag @out << '' << @stack.pop << '>' end def toggle_tag(tag, match) if @stack.include?(tag) if @stack.last == tag end_tag else @out << escape_html(match) end else start_tag(tag) end end def end_paragraph end_tag while !@stack.empty? @p = false end def start_paragraph if @p @out << ' ' if @out[-1] != ?\s else end_paragraph start_tag('p') @p = true end end # Translate an explicit local link to a desired URL that is # properly URL-escaped. The default behaviour is to convert local # links directly, escaping any characters that have special # meaning in URLs. Relative URLs in local links are not handled. # # Examples: # # make_local_link("LocalLink") #=> "LocalLink" # make_local_link("/Foo/Bar") #=> "%2FFoo%2FBar" # # Must ensure that the result is properly URL-escaped. The caller # will handle HTML escaping as necessary. HTML links will not be # inserted if the function returns nil. # # Example custom behaviour: # # make_local_link("LocalLink") #=> "/LocalLink" # make_local_link("Wikipedia:Bread") #=> "http://en.wikipedia.org/wiki/Bread" def make_local_link(link) #:doc: no_escape? ? link : escape_url(link) end # Sanatize a direct url (e.g. http://wikipedia.org/). The default # behaviour returns the original link as-is. # # Must ensure that the result is properly URL-escaped. The caller # will handle HTML escaping as necessary. Links will not be # converted to HTML links if the function returns link. # # Custom versions of this function in inherited classes can # implement specific link handling behaviour, such as redirection # to intermediate pages (for example, for notifing the user that # he is leaving the site). def make_direct_link(url) #:doc: url end # Sanatize and prefix image URLs. When images are encountered in # Creole text, this function is called to obtain the actual URL of # the image. The default behaviour is to return the image link # as-is. No image tags are inserted if the function returns nil. # # Custom version of the method can be used to sanatize URLs # (e.g. remove query-parts), inhibit off-site images, or add a # base URL, for example: # # def make_image_link(url) # URI.join("http://mywiki.org/images/", url) # end def make_image_link(url) #:doc: url end # Create image markup. This # method can be overridden to generate custom # markup, for example to add html additional attributes or # to put divs around the imgs. def make_image(uri, alt) if alt '' << escape_html(nowikiblock) << '' when /\A\s*-{4,}\s*$/ end_paragraph @out << '