redcarpet-3.6.0/0000755000004100000410000000000014370575530013532 5ustar www-datawww-dataredcarpet-3.6.0/COPYING0000644000004100000410000000210414370575530014562 0ustar www-datawww-dataCopyright (c) 2009, Natacha Porté Copyright (c) 2015, Vicent Marti Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. redcarpet-3.6.0/bin/0000755000004100000410000000000014370575530014302 5ustar www-datawww-dataredcarpet-3.6.0/bin/redcarpet0000755000004100000410000000022314370575530016176 0ustar www-datawww-data#!/usr/bin/env ruby lib_path = File.expand_path('../../lib', __FILE__) $:.unshift(lib_path) require 'redcarpet/cli' Redcarpet::CLI.process(ARGV) redcarpet-3.6.0/CHANGELOG.md0000644000004100000410000003024514370575530015347 0ustar www-datawww-data# Changelog ## Version 3.6.0 * Avoid warnings running on Ruby 3.2+. Refs #721. *Jean Boussier* * Match fence char and length when matching closing fence in fenced code blocks. Fixes #208. *Martin Cizek, Orchitech* * Consider `
` as a block-level element. Refs #702. *momijizukamori* * Properly provide a third argument to the `table_cell` callback indicating whether the current cell is part of the header or not. The previous implementation with two parameters is still supported. Fixes #604, Refs #605. *Mark Lambley* * Fix anchor generation on titles with ampersands. Fixes #696. ## Version 3.5.1 (Security) * Fix a security vulnerability using `:quote` in combination with the `:escape_html` option. Reported by *Johan Smits*. ## Version 3.5.0 * Avoid mutating the options hash passed to a render object. Refs #663. *Max Schwenk* * Fix a segfault rendering quotes using `StripDown` and the `:quote` option. Fixes #639. * Fix `warning: instance variable @options not initialized` when running under verbose mode (`-w`, `$VERBOSE = true`). * Fix SmartyPants single quotes right after a link. For example: ~~~markdown [John](http://john.doe)'s cat ~~~ Will now properly converts `'` to a right single quote (i.e. `’`). Fixes #624. * Remove the `rel` and `rev` attributes from the output generated for footnotes as they don't pass the HTML 5 validation. Fixes #536. * Automatically enable the `fenced_code_blocks` option passing a `HTML_TOC` object to the `Markdown` object's constructor since some languages rely on the sharp to comment code. Fixes #451. * Allow passing `Range` objects to the `nesting_level` option to have a higher level of customization for table of contents: ~~~ruby Redcarpet::Render::HTML_TOC.new(nesting_level: 2..5) ~~~ Fixes #519. ## Version 3.4.0 * Rely on djb2 hashing generating anchors with non-ASCII chars. Fix issue [#538](https://github.com/vmg/redcarpet/issues/538). *Alexey Kopytko*, *namusyaka* * Added suppport for HTML 5 `details` and `summary` tags. Fix issue [#578](https://github.com/vmg/redcarpet/issues/578). *James Edwards-Jones* * Multiple single quote pairs are parsed correctly with SmartyPants. Fix issue [#549](https://github.com/vmg/redcarpet/issues/549). *Jan Jędrychowski* * Table headers don't require a minimum of three dashes anymore; a single one can be used for each row. * Remove escaped entities from `HTML` render table of contents' ids to be consistent with the `HTML_TOC` render. Fix issue [#529](https://github.com/vmg/redcarpet/issues/529). * Remove periods at the end of URLs when autolinking to make sure that links at the end of a sentence get properly generated. Fix issue [#465](https://github.com/vmg/redcarpet/issues/465). * Expose the Markdown and rendering options through a `Hash` inside the `@options` instance variable for custom render objects. * Avoid escaping ampersands in href links. *Nolan Evans* ## Version 3.3.4 * Fix `bufprintf` to correctly work on Windows MinGW-w64 so strings are properly written to the buffer. *Kenichi Saita* * Fix the header anchor normalization by skipping non-ASCII chars and not calling tolower because this leads to invalid UTF-8 byte sequences in the HTML output. (tolower is not locale-aware) *Clemens Gruber* ## Version 3.3.3 * Fix a memory leak instantiating a `Redcarpet::Render::Base` object. *Oleg Dashevskii* * Fix the `StripDown` renderer to handle the `:highlight` option. *Itay Grudev* * The `StripDown` renderer handles tables if the `tables` extension is enabled. *amnesia7* * Fix Smarty Pants to avoid fraction conversions when there are several numbers separated with slashes (e.g. for a date). *Sam Saffron* ## Version 3.3.2 * Fix a potential security issue in the HTML renderer (Thanks to Giancarlo Canales Barreto for the heads up) ## Version 3.3.1 * Include the `Redcarpet::CLI`'s file in the gemspec to make it available when downloading. ## Version 3.3.0 * Fix the stripping of surrounding characters that should be removed during anchor generation. * Provide a `Redcarpet::CLI` class to create custom binary files. Relying on Ruby's OptionParser, it's now straightforward to add new options, rely on custom render objects or handle differently the rendering of the provided files. * Undeprecate the compatibility layer for the old RedCloth API. This layer actually ease the support of libraries supporting different Markdown processors. * Strip out `style` tags at the HTML-block rendering level when the `:no_styles` options is enabled ; previously they were only removed inside paragraphs. * Avoid parsing images when the given URL isn't safe and the `:safe_links_only` option is enabled. *Alex Serban* * Avoid parsing references inside fenced code blocks so they are now kept in the code snippet. *David Waller* * Avoid escaping table-of-contents' headers by default. A new `:escape_html` option is now available for the `HTML_TOC` object if there are security concerns. * Add the `lang-` prefix in front of the language's name when using `:prettify` along with `:fenced_code_blocks`. * Non-alphanumeric chars are now stripped out from generated anchors (along the lines of Active Support's `#parameterize` method). ## Version 3.2.3 * Avoid rewinding content of a previous inline when autolinking is enabled. *Daniel LeCheminant* * Fix escaping of forward slashes with the `Safe` render object (add a missing semi-colon). ## Version 3.2.2 * Consider `script` as a block-level element so it doesn't get included inside a paragraph. ## Version 3.2.1 * Load `RedcarpetCompat` when requiring Redcarpet for the sake of backward compatibility. *Loren Segal* ## Version 3.2.0 * Add a `Safe` renderer to deal with users' input. The `escape_html` and `safe_links_only` options are turned on by default. Moreover, the `block_code` callback removes the tag's class since the user can basically set anything with the vanilla one. *Robin Dupret* * HTML5 block-level tags are now recognized *silverhammermba* * The `StripDown` render object now displays the URL of links along with the text. *Robin Dupret* * The RedCloth API compatibility layer is now deprecated. *Robin Dupret* * A hyphen and an equal should not be converted to heading. *namusyaka* * Fix emphasis character escape sequence detection while mid-emphasis. *jcheatham* * Add `=` to the whitelist of escaped chars so it can be used inside highlighted snippets. *jcheatham* * Convert trailing single quotes to curly quotes. For example, `Road Trippin'` now converts to `Road Trippin’`. *Kevin Chen* * Allow in-page links (e.g. `[headline](#headline)`) when `:safe_links_only` is set. *jomo* * Enable emphasis inside of sentences in multi-byte languages when `:no_intra_emphasis` is set. *Chun-wei Kuo* * Avoid making `:no_intra_emphasis` only match spaces. This allows using emphasizes inside quotes when the option is enabled for instance. *Jason Webb* and *BJ Homer* * The StripDown renderer handles image tags now. ## Version 3.1.2 * Remove the yielding of anchors in the `header` callback. This was a breaking change between 3.0 and 3.1 as the method's arity changed. ## Version 3.1.1 * Fix a segfault when parsing text with headers. ## Version 3.1.0 * Yield the anchor of the headers Using the `header` callback, it's now possible to get access to the humanized generated id to easily keep tracking of the tree of headers or simply handle the duplicate values easily. Since the `HTML_TOC` and `HTML` objects both have this callback, it's advisable to define a module and mix it in these objects to avoid code duplication. *Robin Dupret* * Allow using tabs between a reference's colon and its link Fix issue [#337](https://github.com/vmg/redcarpet/issues/337) *Juan Guerrero* * Make ordered lists preceded by paragraph parsed with `:lax_spacing` Previously, enabling the `:lax_spacing` option, if a paragraph was followed by an ordered list it was unparsed and was part of the paragraph but this is no more the case. *Robin Dupret* * Feed the gemspec into ExtensionTask so that we can pre-compile. ie. `rake native gem` *Todd Edwards* * Revert lax indent of less than 4 characters after list items Follow the standard to detect when new paragraph is outside last item. Fixes [issue #111](https://github.com/vmg/redcarpet/issues/111). *Eric Bréchemier* * Fix code blocks' classes when using Google code prettify When using the the `:prettify` option and specifying the language name, the generated code block's class had a missing space. *Simonini* * Add `-v`/`--version` and `-h` flags to commandline redcarpet *Lukas Stabe* * Add optional quote support through the `:quote` option. Render quotations marks to `q` HTML tag. This is a `"quote"`. *Anatol Broder* * Ensure inline markup in titles is correctly stripped when generating headers' anchor. *Robin Dupret* * Revert the unescaping behavior on comments This behavior doesn't follow the conformance suite. *Robin Dupret* * Add optional footnotes support Add PHP-Markdown style footnotes through the `:footnotes` option. *Ben Dolman, Adam Florin, microjo, brief* * Enable GitHub style anchors for headers Passing the `with_toc_data` option to a `HTML` render object now generates GitHub style anchors. *Matt Rogers* * Allow to set a maximum rendering level for HTML_TOC Allow the user to pass a `nesting_level` option when instantiating a new HTML_TOC render object in order to limit the nesting level in the generated table of content. For example: ~~~ruby Redcarpet::Markdown.new(Redcarpet::Render::HTML_TOC.new(nesting_level: 2)) ~~~ *Robin Dupret* ## Version 3.0.0 * Remove support for Ruby 1.8.x *Matt Rogers & Robin Dupret* * Avoid escaping for HTML comments *Robin Dupret* * Make emphasis wrapped inside parenthesis parsed *Robin Dupret* * Remove the Sundown submodule *Robin Dupret* * Fix FTP uris identified as emails *Robin Dupret* * Add optional highlight support *Sam Soffes* This is `==highlighted==`. * Ensure nested parenthesis are handled into links *Robin Dupret* * Ensure nested code spans put in emphasis work correctly *Robin Dupret* ## Version 2.3.0 * Add a `:disable_indented_code_blocks` option *Dmitriy Kiriyenko* * Fix issue [#57](https://github.com/vmg/redcarpet/issues/57) *Mike Morearty* * Ensure new lines characters are inserted when using the StripDown render. *Robin Dupret* * Mark all symbols as hidden except the main entry point *Tom Hughes* This avoids conflicts with other gems that may have some of the same symbols, such as escape_utils which also uses houdini. * Remove unnecessary function pointer *Sam Soffes* * Add optional underline support *Sam Soffes* This is `*italic*` and this is `_underline_` when enabled. * Test that links with quotes work *Michael Grosser* * Adding a prettyprint class for google-code-prettify *Joel Rosenberg* * Remove unused C macros *Matt Rogers* * Remove 'extern' definition for Init_redcarpet_rndr() *Matt Rogers* * Remove Gemfile.lock from the gemspec *Matt Rogers* * Removed extra unused test statement. *Slipp D. Thompson* * Use test-unit gem to get some red/green output when running tests *Michael Grosser* * Remove a deprecation warning and update Gemfile.lock *Robin Dupret* * Added contributing file *Brent Beer* * For tests for libxml2 > 2.8 *strzibny* * SmartyPants: Preserve single `backticks` in HTML *Mike Morearty* When SmartyPants is processing HTML, single `backticks` should be left intact. Previously they were being deleted. * Removed and ignored Gemfile.lock *Ryan McGeary* * Added support for org-table syntax *Ryan McGeary* Adds support for using a plus (+) as an intersection character instead of requiring pipes (|). The emacs org-mode table syntax automatically manages ascii tables, but uses pluses for line intersections. * Ignore /tmp directory *Ryan McGeary* * Add redcarpet_ prefix for `stack_*` functions *Kenta Murata* * Mark any html_attributes has held by a renderer as used *Tom Hughes* * Add Rubinius to the list of tested implementations *Gibheer* * Add a changelog file redcarpet-3.6.0/Rakefile0000644000004100000410000000252314370575530015201 0ustar www-datawww-datarequire 'date' require 'rake/clean' require 'rake/extensiontask' require 'digest/md5' task :default => [:test] # Gem Spec gem_spec = Gem::Specification.load('redcarpet.gemspec') # Ruby Extension Rake::ExtensionTask.new('redcarpet', gem_spec) # Packaging require 'bundler/gem_tasks' # Testing require 'rake/testtask' Rake::TestTask.new('test:unit') do |t| t.libs << 'lib' t.libs << 'test' t.pattern = 'test/*_test.rb' t.verbose = true t.warning = false end task 'test:unit' => :compile desc 'Run conformance tests (MARKDOWN_TEST_VER=1.0.3)' task 'test:conformance' => :compile do |t| script = "#{pwd}/bin/redcarpet" version = ENV['MARKDOWN_TEST_VER'] || '1.0.3' lib_dir = "#{pwd}/lib" chdir("test/MarkdownTest_#{version}") do sh "RUBYLIB=#{lib_dir} ./MarkdownTest.pl --script='#{script}' --tidy" end end desc 'Run version 1.0 conformance suite' task 'test:conformance:1.0' => :compile do |t| ENV['MARKDOWN_TEST_VER'] = '1.0' Rake::Task['test:conformance'].invoke end desc 'Run 1.0.3 conformance suite' task 'test:conformance:1.0.3' => :compile do |t| ENV['MARKDOWN_TEST_VER'] = '1.0.3' Rake::Task['test:conformance'].invoke end desc 'Run unit and conformance tests' task :test => %w[test:unit test:conformance] desc 'Run benchmarks' task :benchmark => :compile do |t| $:.unshift 'lib' load 'test/benchmark.rb' end redcarpet-3.6.0/lib/0000755000004100000410000000000014370575530014300 5ustar www-datawww-dataredcarpet-3.6.0/lib/redcarpet.rb0000644000004100000410000000420214370575530016574 0ustar www-datawww-datarequire 'redcarpet.so' require 'redcarpet/compat' module Redcarpet VERSION = '3.6.0' class Markdown attr_reader :renderer end module Render # XHTML Renderer class XHTML < HTML def initialize(extensions = {}) super(extensions.merge(xhtml: true)) end end # HTML + SmartyPants renderer class SmartyHTML < HTML include SmartyPants end # A renderer object you can use to deal with users' input. It # enables +escape_html+ and +safe_links_only+ by default. # # The +block_code+ callback is also overriden not to include # the lang's class as the user can basically specify anything # with the vanilla one. class Safe < HTML def initialize(extensions = {}) super({ escape_html: true, safe_links_only: true }.merge(extensions)) end def block_code(code, lang) "
" \
          "#{html_escape(code)}" \
        "
" end private # TODO: This is far from ideal to have such method as we # are duplicating existing code from Houdini. This method # should be defined at the C level. def html_escape(string) string.gsub(/['&\"<>\/]/, { '&' => '&', '<' => '<', '>' => '>', '"' => '"', "'" => ''', "/" => '/', }) end end # SmartyPants Mixin module # # Implements SmartyPants.postprocess, which # performs smartypants replacements on the HTML file, # once it has been fully rendered. # # To add SmartyPants postprocessing to your custom # renderers, just mixin the module `include SmartyPants` # # You can also use this as a standalone SmartyPants # implementation. # # Example: # # # Mixin # class CoolRenderer < HTML # include SmartyPants # # more code here # end # # # Standalone # Redcarpet::Render::SmartyPants.render("you're") # module SmartyPants extend self def self.render(text) postprocess text end end end end redcarpet-3.6.0/lib/redcarpet/0000755000004100000410000000000014370575530016251 5ustar www-datawww-dataredcarpet-3.6.0/lib/redcarpet/compat.rb0000644000004100000410000000400314370575530020056 0ustar www-datawww-data# Creates an instance of Redcarpet with the RedCloth API. class RedcarpetCompat attr_accessor :text def initialize(text, *exts) exts_hash, render_hash = *parse_extensions_and_renderer_options(exts) @text = text renderer = Redcarpet::Render::HTML.new(render_hash) @markdown = Redcarpet::Markdown.new(renderer, exts_hash) end def to_html(*_dummy) @markdown.render(text) end private EXTENSION_MAP = { # old name => new name :autolink => :autolink, :fenced_code => :fenced_code_blocks, :filter_html => :filter_html, :hard_wrap => :hard_wrap, :prettify => :prettify, :lax_htmlblock => :lax_spacing, :no_image => :no_images, :no_intraemphasis => :no_intra_emphasis, :no_links => :no_links, :filter_styles => :no_styles, :safelink => :safe_links_only, :space_header => :space_after_headers, :strikethrough => :strikethrough, :tables => :tables, :generate_toc => :with_toc_data, :xhtml => :xhtml, # old names with no new mapping :gh_blockcode => nil, :no_tables => nil, :smart => nil, :strict => nil } RENDERER_OPTIONS = [:filter_html, :no_images, :no_links, :no_styles, :safe_links_only, :with_toc_data, :hard_wrap, :prettify, :xhtml] def rename_extensions(exts) exts.map do |old_name| if new_name = EXTENSION_MAP[old_name] new_name else old_name end end.compact end # Returns two hashes, the extensions and renderer options # given the extension list def parse_extensions_and_renderer_options(exts) exts = rename_extensions(exts) exts.partition {|ext| !RENDERER_OPTIONS.include?(ext) }. map {|list| list_to_truthy_hash(list) } end # Turns a list of symbols into a hash of symbol => true. def list_to_truthy_hash(list) list.inject({}) {|h, k| h[k] = true; h } end end Markdown = RedcarpetCompat unless defined? Markdown redcarpet-3.6.0/lib/redcarpet/render_man.rb0000644000004100000410000000224214370575530020710 0ustar www-datawww-datamodule Redcarpet module Render class ManPage < Base def normal_text(text) text.gsub('-', '\\-').strip end def block_code(code, language) "\n.nf\n#{normal_text(code)}\n.fi\n" end def codespan(code) block_code(code, nil) end def header(title, level) case level when 1 "\n.TH #{title}\n" when 2 "\n.SH #{title}\n" when 3 "\n.SS #{title}\n" end end def double_emphasis(text) "\\fB#{text}\\fP" end def emphasis(text) "\\fI#{text}\\fP" end def linebreak "\n.LP\n" end def paragraph(text) "\n.TP\n#{text}\n" end def list(content, list_type) case list_type when :ordered "\n\n.nr step 0 1\n#{content}\n" when :unordered "\n.\n#{content}\n" end end def list_item(content, list_type) case list_type when :ordered ".IP \\n+[step]\n#{content.strip}\n" when :unordered ".IP \\[bu] 2 \n#{content.strip}\n" end end end end end redcarpet-3.6.0/lib/redcarpet/render_strip.rb0000644000004100000410000000255514370575530021305 0ustar www-datawww-datamodule Redcarpet module Render # Markdown-stripping renderer. Turns Markdown into plaintext # Thanks to @toupeira (Markus Koller) class StripDown < Base # Methods where the first argument is the text content [ # block-level calls :block_code, :block_quote, :block_html, :list, :list_item, # span-level calls :autolink, :codespan, :double_emphasis, :emphasis, :underline, :raw_html, :triple_emphasis, :strikethrough, :superscript, :highlight, :quote, # footnotes :footnotes, :footnote_def, :footnote_ref, # low level rendering :entity, :normal_text ].each do |method| define_method method do |*args| args.first end end # Other methods where we don't return only a specific argument def link(link, title, content) "#{content} (#{link})" end def image(link, title, content) content &&= content + " " "#{content}#{link}" end def paragraph(text) text + "\n" end def header(text, header_level) text + "\n" end def table(header, body) "#{header}#{body}" end def table_row(content) content + "\n" end def table_cell(content, alignment) content + "\t" end end end end redcarpet-3.6.0/lib/redcarpet/cli.rb0000644000004100000410000000467114370575530017355 0ustar www-datawww-datarequire 'redcarpet' require 'optparse' module Redcarpet # This class aims at easing the creation of custom # binary for your needs. For example, you can add new # options or change the existing ones. The parsing # is handled by Ruby's OptionParser. For instance: # # class Custom::CLI < Redcarpet::CLI # def self.options_parser # super.tap do |opts| # opts.on("--rainbow") do # @@options[:rainbow] = true # end # end # end # # def self.render_object # @@options[:rainbow] ? RainbowRender : super # end # end class CLI def self.options_parser @@options = { render_extensions: {}, parse_extensions: {}, smarty_pants: false } OptionParser.new do |opts| opts.banner = "Usage: redcarpet [--parse ...] " \ "[--render ...] [--smarty] ..." opts.on("--parse EXTENSION", "Enable a parsing extension") do |ext| ext = ext.gsub('-', '_').to_sym @@options[:parse_extensions][ext] = true end opts.on("--render EXTENSION", "Enable a rendering extension") do |ext| ext = ext.gsub('-', '_').to_sym @@options[:render_extensions][ext] = true end opts.on("--smarty", "Enable Smarty Pants") do @@options[:smarty_pants] = true end opts.on_tail("-v", "--version", "Display the current version") do STDOUT.puts "Redcarpet #{Redcarpet::VERSION}" exit end opts.on_tail("-h", "--help", "Display this help message") do puts opts exit end end end def self.process(args) self.legacy_parse!(args) self.options_parser.parse!(args) STDOUT.write parser_object.render(ARGF.read) end def self.render_object @@options[:smarty_pants] ? Render::SmartyHTML : Render::HTML end def self.parser_object renderer = render_object.new(@@options[:render_extensions]) Redcarpet::Markdown.new(renderer, @@options[:parse_extensions]) end def self.legacy_parse!(args) # :nodoc: # Workaround for backward compatibility as OptionParser # doesn't support the --flag-OPTION syntax. args.select {|a| a =~ /--(parse|render)-/ }.each do |arg| args.delete(arg) arg = arg.partition(/\b-/) args.push(arg.first, arg.last) end end end end redcarpet-3.6.0/CONTRIBUTING.md0000644000004100000410000000256714370575530015775 0ustar www-datawww-data## Submitting a Pull Request 1. [Fork the repository.][fork] 2. [Create a topic branch.][branch] 3. Check which version of Ruby is installed on your machine with `ruby -v`. The list of supported Ruby versions is listed in [.travis.yml][travis_yml]. Set up one of these versions; use of [RVM][rvm] is recommended to switch easily between different versions. 4. [Install bundler.][bundler] 5. Make sure to have the `tidy` command on your system: * `apt-get install tidy` * `yum install tidy` * `pacman -S tidyhtml` 6. Check that unit tests pass with `rake test`. 7. Write a failing test to capture existing bug or lack of feature. 8. Run `rake test` to verify that test fails. 9. Implement your feature or bug fix. 10. Ensure tests pass. 11. If it's a new feature or a bug fix, please add an entry to the changelog file. 12. Add, commit, and push your changes. 13. [Submit a pull request.][pr] 14. You will get some feedback and may need to push additional commits with more fixes to the same branch; this will update your pull request automatically. [branch]: http://git-scm.com/book/en/Git-Branching-Branching-Workflows#Topic-Branches [bundler]: http://bundler.io [fork]: https://help.github.com/articles/fork-a-repo [pr]: https://help.github.com/articles/using-pull-requests [rvm]: https://rvm.io [travis_yml]: https://github.com/vmg/redcarpet/blob/master/.travis.yml redcarpet-3.6.0/README.markdown0000644000004100000410000003364014370575530016241 0ustar www-datawww-dataRedcarpet is written with sugar, spice and everything nice ============================================================ [![Build Status](https://travis-ci.org/vmg/redcarpet.svg?branch=master)](https://travis-ci.org/vmg/redcarpet) [![Help Contribute to Open Source](https://www.codetriage.com/vmg/redcarpet/badges/users.svg)](https://www.codetriage.com/vmg/redcarpet) [![Gem Version](https://badge.fury.io/rb/redcarpet.svg)](https://badge.fury.io/rb/redcarpet) Redcarpet is a Ruby library for Markdown processing that smells like butterflies and popcorn. This library is written by people --------------------------------- Redcarpet was written by [Vicent Martí](https://github.com/vmg). It is maintained by [Robin Dupret](https://github.com/robin850) and [Matt Rogers](https://github.com/mattr-). Redcarpet would not be possible without the [Sundown](https://www.github.com/vmg/sundown) library and its authors (Natacha Porté, Vicent Martí, and its many awesome contributors). You can totally install it as a Gem ----------------------------------- Redcarpet is readily available as a Ruby gem. It will build some native extensions, but the parser is standalone and requires no installed libraries. Starting with Redcarpet 3.0, the minimum required Ruby version is 1.9.2 (or Rubinius in 1.9 mode). $ [sudo] gem install redcarpet If you need to use it with Ruby 1.8.7, you will have to stick with 2.3.0: $ [sudo] gem install redcarpet -v 2.3.0 The Redcarpet source is available at GitHub: $ git clone git://github.com/vmg/redcarpet.git And it's like *really* simple to use ------------------------------------ The core of the Redcarpet library is the `Redcarpet::Markdown` class. Each instance of the class is attached to a `Renderer` object; the Markdown class performs parsing of a document and uses the attached renderer to generate output. The `Redcarpet::Markdown` object is encouraged to be instantiated once with the required settings, and reused between parses. ~~~~ ruby # Initializes a Markdown parser markdown = Redcarpet::Markdown.new(renderer, extensions = {}) ~~~~ Here, the `renderer` variable refers to a renderer object, inheriting from `Redcarpet::Render::Base`. If the given object has not been instantiated, the library will do it with default arguments. Rendering with the `Markdown` object is done through `Markdown#render`. Unlike in the RedCloth API, the text to render is passed as an argument and not stored inside the `Markdown` instance, to encourage reusability. Example: ~~~~ ruby markdown.render("This is *bongos*, indeed.") # => "

This is bongos, indeed.

" ~~~~ You can also specify a hash containing the Markdown extensions which the parser will identify. The following extensions are accepted: * `:no_intra_emphasis`: do not parse emphasis inside of words. Strings such as `foo_bar_baz` will not generate `` tags. * `:tables`: parse tables, PHP-Markdown style. * `:fenced_code_blocks`: parse fenced code blocks, PHP-Markdown style. Blocks delimited with 3 or more `~` or backticks will be considered as code, without the need to be indented. An optional language name may be added at the end of the opening fence for the code block. * `:autolink`: parse links even when they are not enclosed in `<>` characters. Autolinks for the http, https and ftp protocols will be automatically detected. Email addresses and http links without protocol, but starting with `www` are also handled. * `:disable_indented_code_blocks`: do not parse usual markdown code blocks. Markdown converts text with four spaces at the front of each line to code blocks. This option prevents it from doing so. Recommended to use with `fenced_code_blocks: true`. * `:strikethrough`: parse strikethrough, PHP-Markdown style. Two `~` characters mark the start of a strikethrough, e.g. `this is ~~good~~ bad`. * `:lax_spacing`: HTML blocks do not require to be surrounded by an empty line as in the Markdown standard. * `:space_after_headers`: A space is always required between the hash at the beginning of a header and its name, e.g. `#this is my header` would not be a valid header. * `:superscript`: parse superscripts after the `^` character; contiguous superscripts are nested together, and complex values can be enclosed in parenthesis, e.g. `this is the 2^(nd) time`. * `:underline`: parse underscored emphasis as underlines. `This is _underlined_ but this is still *italic*`. * `:highlight`: parse highlights. `This is ==highlighted==`. It looks like this: `highlighted` * `:quote`: parse quotes. `This is a "quote"`. It looks like this: `quote` * `:footnotes`: parse footnotes, PHP-Markdown style. A footnote works very much like a reference-style link: it consists of a marker next to the text (e.g. `This is a sentence.[^1]`) and a footnote definition on its own line anywhere within the document (e.g. `[^1]: This is a footnote.`). Example: ~~~~ ruby markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true) ~~~~ Darling, I packed you a couple renderers for lunch -------------------------------------------------- Redcarpet comes with two built-in renderers, `Redcarpet::Render::HTML` and `Redcarpet::Render::XHTML`, which output HTML and XHTML, respectively. These renderers are actually implemented in C and hence offer brilliant performance — several degrees of magnitude faster than other Ruby Markdown solutions. All the rendering flags that previously applied only to HTML output have now been moved to the `Redcarpet::Render::HTML` class, and may be enabled when instantiating the renderer: ~~~~ ruby Redcarpet::Render::HTML.new(render_options = {}) ~~~~ Initializes an HTML renderer. The following flags are available: * `:filter_html`: do not allow any user-inputted HTML in the output. * `:no_images`: do not generate any `` tags. * `:no_links`: do not generate any `` tags. * `:no_styles`: do not generate any `