redcarpet-3.6.0/ 0000755 0000041 0000041 00000000000 14370575530 013532 5 ustar www-data www-data redcarpet-3.6.0/COPYING 0000644 0000041 0000041 00000002104 14370575530 014562 0 ustar www-data www-data Copyright (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/ 0000755 0000041 0000041 00000000000 14370575530 014302 5 ustar www-data www-data redcarpet-3.6.0/bin/redcarpet 0000755 0000041 0000041 00000000223 14370575530 016176 0 ustar www-data www-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.md 0000644 0000041 0000041 00000030245 14370575530 015347 0 ustar www-data www-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 `
" \
"#{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/ 0000755 0000041 0000041 00000000000 14370575530 016251 5 ustar www-data www-data redcarpet-3.6.0/lib/redcarpet/compat.rb 0000644 0000041 0000041 00000004003 14370575530 020056 0 ustar www-data www-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.rb 0000644 0000041 0000041 00000002242 14370575530 020710 0 ustar www-data www-data module 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.rb 0000644 0000041 0000041 00000002555 14370575530 021305 0 ustar www-data www-data module 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.rb 0000644 0000041 0000041 00000004671 14370575530 017355 0 ustar www-data www-data require '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 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 `