redcarpet_yt 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/COPYING +20 -0
- data/Gemfile +9 -0
- data/README.markdown +394 -0
- data/Rakefile +60 -0
- data/bin/redcarpet +7 -0
- data/ext/redcarpet/autolink.c +302 -0
- data/ext/redcarpet/autolink.h +55 -0
- data/ext/redcarpet/buffer.c +203 -0
- data/ext/redcarpet/buffer.h +89 -0
- data/ext/redcarpet/extconf.rb +6 -0
- data/ext/redcarpet/houdini.h +51 -0
- data/ext/redcarpet/houdini_href_e.c +124 -0
- data/ext/redcarpet/houdini_html_e.c +105 -0
- data/ext/redcarpet/html.c +825 -0
- data/ext/redcarpet/html.h +84 -0
- data/ext/redcarpet/html_blocks.h +229 -0
- data/ext/redcarpet/html_smartypants.c +457 -0
- data/ext/redcarpet/markdown.c +2917 -0
- data/ext/redcarpet/markdown.h +143 -0
- data/ext/redcarpet/rc_markdown.c +168 -0
- data/ext/redcarpet/rc_render.c +545 -0
- data/ext/redcarpet/redcarpet.h +52 -0
- data/ext/redcarpet/stack.c +84 -0
- data/ext/redcarpet/stack.h +48 -0
- data/lib/redcarpet/cli.rb +86 -0
- data/lib/redcarpet/compat.rb +73 -0
- data/lib/redcarpet/render_man.rb +65 -0
- data/lib/redcarpet/render_strip.rb +60 -0
- data/lib/redcarpet_yt.rb +103 -0
- data/redcarpet_yt.gemspec +71 -0
- data/test/benchmark.rb +24 -0
- data/test/custom_render_test.rb +28 -0
- data/test/fixtures/benchmark.md +232 -0
- data/test/html5_test.rb +69 -0
- data/test/html_render_test.rb +254 -0
- data/test/html_toc_render_test.rb +75 -0
- data/test/markdown_test.rb +371 -0
- data/test/pathological_inputs_test.rb +34 -0
- data/test/redcarpet_bin_test.rb +80 -0
- data/test/redcarpet_compat_test.rb +38 -0
- data/test/safe_render_test.rb +35 -0
- data/test/smarty_html_test.rb +45 -0
- data/test/smarty_pants_test.rb +53 -0
- data/test/stripdown_render_test.rb +61 -0
- data/test/test_helper.rb +39 -0
- metadata +151 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2015, Vicent Marti
|
3
|
+
*
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
9
|
+
* furnished to do so, subject to the following conditions:
|
10
|
+
*
|
11
|
+
* The above copyright notice and this permission notice shall be included in
|
12
|
+
* all copies or substantial portions of the Software.
|
13
|
+
*
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
* THE SOFTWARE.
|
21
|
+
*/
|
22
|
+
|
23
|
+
#ifndef REDCARPET_H__
|
24
|
+
#define REDCARPET_H__
|
25
|
+
|
26
|
+
#define RSTRING_NOT_MODIFIED
|
27
|
+
#include "ruby.h"
|
28
|
+
#include <stdio.h>
|
29
|
+
|
30
|
+
#include <ruby/encoding.h>
|
31
|
+
|
32
|
+
#include "markdown.h"
|
33
|
+
#include "html.h"
|
34
|
+
|
35
|
+
#define CSTR2SYM(s) (ID2SYM(rb_intern((s))))
|
36
|
+
|
37
|
+
void Init_redcarpet_rndr();
|
38
|
+
|
39
|
+
struct redcarpet_renderopt {
|
40
|
+
struct html_renderopt html;
|
41
|
+
VALUE link_attributes;
|
42
|
+
VALUE self;
|
43
|
+
VALUE base_class;
|
44
|
+
rb_encoding *active_enc;
|
45
|
+
};
|
46
|
+
|
47
|
+
struct rb_redcarpet_rndr {
|
48
|
+
struct sd_callbacks callbacks;
|
49
|
+
struct redcarpet_renderopt options;
|
50
|
+
};
|
51
|
+
|
52
|
+
#endif
|
@@ -0,0 +1,84 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2015, Vicent Marti
|
3
|
+
*
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
9
|
+
* furnished to do so, subject to the following conditions:
|
10
|
+
*
|
11
|
+
* The above copyright notice and this permission notice shall be included in
|
12
|
+
* all copies or substantial portions of the Software.
|
13
|
+
*
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
* THE SOFTWARE.
|
21
|
+
*/
|
22
|
+
|
23
|
+
#include "stack.h"
|
24
|
+
#include <string.h>
|
25
|
+
|
26
|
+
int
|
27
|
+
redcarpet_stack_grow(struct stack *st, size_t new_size)
|
28
|
+
{
|
29
|
+
void **new_st;
|
30
|
+
|
31
|
+
if (st->asize >= new_size)
|
32
|
+
return 0;
|
33
|
+
|
34
|
+
new_st = realloc(st->item, new_size * sizeof(void *));
|
35
|
+
if (new_st == NULL)
|
36
|
+
return -1;
|
37
|
+
|
38
|
+
memset(new_st + st->asize, 0x0,
|
39
|
+
(new_size - st->asize) * sizeof(void *));
|
40
|
+
|
41
|
+
st->item = new_st;
|
42
|
+
st->asize = new_size;
|
43
|
+
|
44
|
+
if (st->size > new_size)
|
45
|
+
st->size = new_size;
|
46
|
+
|
47
|
+
return 0;
|
48
|
+
}
|
49
|
+
|
50
|
+
void
|
51
|
+
redcarpet_stack_free(struct stack *st)
|
52
|
+
{
|
53
|
+
if (!st)
|
54
|
+
return;
|
55
|
+
|
56
|
+
free(st->item);
|
57
|
+
|
58
|
+
st->item = NULL;
|
59
|
+
st->size = 0;
|
60
|
+
st->asize = 0;
|
61
|
+
}
|
62
|
+
|
63
|
+
int
|
64
|
+
redcarpet_stack_init(struct stack *st, size_t initial_size)
|
65
|
+
{
|
66
|
+
st->item = NULL;
|
67
|
+
st->size = 0;
|
68
|
+
st->asize = 0;
|
69
|
+
|
70
|
+
if (!initial_size)
|
71
|
+
initial_size = 8;
|
72
|
+
|
73
|
+
return redcarpet_stack_grow(st, initial_size);
|
74
|
+
}
|
75
|
+
|
76
|
+
int
|
77
|
+
redcarpet_stack_push(struct stack *st, void *item)
|
78
|
+
{
|
79
|
+
if (redcarpet_stack_grow(st, st->size * 2) < 0)
|
80
|
+
return -1;
|
81
|
+
|
82
|
+
st->item[st->size++] = item;
|
83
|
+
return 0;
|
84
|
+
}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2015, Vicent Marti
|
3
|
+
*
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
9
|
+
* furnished to do so, subject to the following conditions:
|
10
|
+
*
|
11
|
+
* The above copyright notice and this permission notice shall be included in
|
12
|
+
* all copies or substantial portions of the Software.
|
13
|
+
*
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
* THE SOFTWARE.
|
21
|
+
*/
|
22
|
+
|
23
|
+
#ifndef STACK_H__
|
24
|
+
#define STACK_H__
|
25
|
+
|
26
|
+
#include <stdlib.h>
|
27
|
+
|
28
|
+
#ifdef __cplusplus
|
29
|
+
extern "C" {
|
30
|
+
#endif
|
31
|
+
|
32
|
+
struct stack {
|
33
|
+
void **item;
|
34
|
+
size_t size;
|
35
|
+
size_t asize;
|
36
|
+
};
|
37
|
+
|
38
|
+
void redcarpet_stack_free(struct stack *);
|
39
|
+
int redcarpet_stack_grow(struct stack *, size_t);
|
40
|
+
int redcarpet_stack_init(struct stack *, size_t);
|
41
|
+
|
42
|
+
int redcarpet_stack_push(struct stack *, void *);
|
43
|
+
|
44
|
+
#ifdef __cplusplus
|
45
|
+
}
|
46
|
+
#endif
|
47
|
+
|
48
|
+
#endif
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'redcarpet'
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
module Redcarpet
|
5
|
+
# This class aims at easing the creation of custom
|
6
|
+
# binary for your needs. For example, you can add new
|
7
|
+
# options or change the existing ones. The parsing
|
8
|
+
# is handled by Ruby's OptionParser. For instance:
|
9
|
+
#
|
10
|
+
# class Custom::CLI < Redcarpet::CLI
|
11
|
+
# def self.options_parser
|
12
|
+
# super.tap do |opts|
|
13
|
+
# opts.on("--rainbow") do
|
14
|
+
# @@options[:rainbow] = true
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# def self.render_object
|
20
|
+
# @@options[:rainbow] ? RainbowRender : super
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
class CLI
|
24
|
+
def self.options_parser
|
25
|
+
@@options = {
|
26
|
+
render_extensions: {},
|
27
|
+
parse_extensions: {},
|
28
|
+
smarty_pants: false
|
29
|
+
}
|
30
|
+
|
31
|
+
OptionParser.new do |opts|
|
32
|
+
opts.banner = "Usage: redcarpet [--parse <extension>...] " \
|
33
|
+
"[--render <extension>...] [--smarty] <file>..."
|
34
|
+
|
35
|
+
opts.on("--parse EXTENSION", "Enable a parsing extension") do |ext|
|
36
|
+
ext = ext.gsub('-', '_').to_sym
|
37
|
+
@@options[:parse_extensions][ext] = true
|
38
|
+
end
|
39
|
+
|
40
|
+
opts.on("--render EXTENSION", "Enable a rendering extension") do |ext|
|
41
|
+
ext = ext.gsub('-', '_').to_sym
|
42
|
+
@@options[:render_extensions][ext] = true
|
43
|
+
end
|
44
|
+
|
45
|
+
opts.on("--smarty", "Enable Smarty Pants") do
|
46
|
+
@@options[:smarty_pants] = true
|
47
|
+
end
|
48
|
+
|
49
|
+
opts.on_tail("-v", "--version", "Display the current version") do
|
50
|
+
STDOUT.write "Redcarpet #{Redcarpet::VERSION}"
|
51
|
+
exit
|
52
|
+
end
|
53
|
+
|
54
|
+
opts.on_tail("-h", "--help", "Display this help message") do
|
55
|
+
puts opts
|
56
|
+
exit
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.process(args)
|
62
|
+
self.legacy_parse!(args)
|
63
|
+
self.options_parser.parse!(args)
|
64
|
+
STDOUT.write parser_object.render(ARGF.read)
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.render_object
|
68
|
+
@@options[:smarty_pants] ? Render::SmartyHTML : Render::HTML
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.parser_object
|
72
|
+
renderer = render_object.new(@@options[:render_extensions])
|
73
|
+
Redcarpet::Markdown.new(renderer, @@options[:parse_extensions])
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.legacy_parse!(args) # :nodoc:
|
77
|
+
# Workaround for backward compatibility as OptionParser
|
78
|
+
# doesn't support the --flag-OPTION syntax.
|
79
|
+
args.select {|a| a =~ /--(parse|render)-/ }.each do |arg|
|
80
|
+
args.delete(arg)
|
81
|
+
arg = arg.partition(/\b-/)
|
82
|
+
args.push(arg.first, arg.last)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'redcarpet'
|
2
|
+
|
3
|
+
# Creates an instance of Redcarpet with the RedCloth API.
|
4
|
+
class RedcarpetCompat
|
5
|
+
attr_accessor :text
|
6
|
+
|
7
|
+
def initialize(text, *exts)
|
8
|
+
exts_hash, render_hash = *parse_extensions_and_renderer_options(exts)
|
9
|
+
@text = text
|
10
|
+
renderer = Redcarpet::Render::HTML.new(render_hash)
|
11
|
+
@markdown = Redcarpet::Markdown.new(renderer, exts_hash)
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_html(*_dummy)
|
15
|
+
@markdown.render(text)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
EXTENSION_MAP = {
|
21
|
+
# old name => new name
|
22
|
+
:autolink => :autolink,
|
23
|
+
:fenced_code => :fenced_code_blocks,
|
24
|
+
:filter_html => :filter_html,
|
25
|
+
:hard_wrap => :hard_wrap,
|
26
|
+
:prettify => :prettify,
|
27
|
+
:lax_htmlblock => :lax_spacing,
|
28
|
+
:no_image => :no_images,
|
29
|
+
:no_intraemphasis => :no_intra_emphasis,
|
30
|
+
:no_links => :no_links,
|
31
|
+
:filter_styles => :no_styles,
|
32
|
+
:safelink => :safe_links_only,
|
33
|
+
:space_header => :space_after_headers,
|
34
|
+
:strikethrough => :strikethrough,
|
35
|
+
:tables => :tables,
|
36
|
+
:generate_toc => :with_toc_data,
|
37
|
+
:xhtml => :xhtml,
|
38
|
+
|
39
|
+
# old names with no new mapping
|
40
|
+
:gh_blockcode => nil,
|
41
|
+
:no_tables => nil,
|
42
|
+
:smart => nil,
|
43
|
+
:strict => nil
|
44
|
+
}
|
45
|
+
|
46
|
+
RENDERER_OPTIONS = [:filter_html, :no_images, :no_links, :no_styles,
|
47
|
+
:safe_links_only, :with_toc_data, :hard_wrap, :prettify, :xhtml]
|
48
|
+
|
49
|
+
def rename_extensions(exts)
|
50
|
+
exts.map do |old_name|
|
51
|
+
if new_name = EXTENSION_MAP[old_name]
|
52
|
+
new_name
|
53
|
+
else
|
54
|
+
old_name
|
55
|
+
end
|
56
|
+
end.compact
|
57
|
+
end
|
58
|
+
|
59
|
+
# Returns two hashes, the extensions and renderer options
|
60
|
+
# given the extension list
|
61
|
+
def parse_extensions_and_renderer_options(exts)
|
62
|
+
exts = rename_extensions(exts)
|
63
|
+
exts.partition {|ext| !RENDERER_OPTIONS.include?(ext) }.
|
64
|
+
map {|list| list_to_truthy_hash(list) }
|
65
|
+
end
|
66
|
+
|
67
|
+
# Turns a list of symbols into a hash of <tt>symbol => true</tt>.
|
68
|
+
def list_to_truthy_hash(list)
|
69
|
+
list.inject({}) {|h, k| h[k] = true; h }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
Markdown = RedcarpetCompat unless defined? Markdown
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Redcarpet
|
2
|
+
module Render
|
3
|
+
class ManPage < Base
|
4
|
+
|
5
|
+
def normal_text(text)
|
6
|
+
text.gsub('-', '\\-').strip
|
7
|
+
end
|
8
|
+
|
9
|
+
def block_code(code, language)
|
10
|
+
"\n.nf\n#{normal_text(code)}\n.fi\n"
|
11
|
+
end
|
12
|
+
|
13
|
+
def codespan(code)
|
14
|
+
block_code(code, nil)
|
15
|
+
end
|
16
|
+
|
17
|
+
def header(title, level)
|
18
|
+
case level
|
19
|
+
when 1
|
20
|
+
"\n.TH #{title}\n"
|
21
|
+
|
22
|
+
when 2
|
23
|
+
"\n.SH #{title}\n"
|
24
|
+
|
25
|
+
when 3
|
26
|
+
"\n.SS #{title}\n"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def double_emphasis(text)
|
31
|
+
"\\fB#{text}\\fP"
|
32
|
+
end
|
33
|
+
|
34
|
+
def emphasis(text)
|
35
|
+
"\\fI#{text}\\fP"
|
36
|
+
end
|
37
|
+
|
38
|
+
def linebreak
|
39
|
+
"\n.LP\n"
|
40
|
+
end
|
41
|
+
|
42
|
+
def paragraph(text)
|
43
|
+
"\n.TP\n#{text}\n"
|
44
|
+
end
|
45
|
+
|
46
|
+
def list(content, list_type)
|
47
|
+
case list_type
|
48
|
+
when :ordered
|
49
|
+
"\n\n.nr step 0 1\n#{content}\n"
|
50
|
+
when :unordered
|
51
|
+
"\n.\n#{content}\n"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def list_item(content, list_type)
|
56
|
+
case list_type
|
57
|
+
when :ordered
|
58
|
+
".IP \\n+[step]\n#{content.strip}\n"
|
59
|
+
when :unordered
|
60
|
+
".IP \\[bu] 2 \n#{content.strip}\n"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Redcarpet
|
2
|
+
module Render
|
3
|
+
# Markdown-stripping renderer. Turns Markdown into plaintext
|
4
|
+
# Thanks to @toupeira (Markus Koller)
|
5
|
+
class StripDown < Base
|
6
|
+
# Methods where the first argument is the text content
|
7
|
+
[
|
8
|
+
# block-level calls
|
9
|
+
:block_code, :block_quote,
|
10
|
+
:block_html, :list, :list_item,
|
11
|
+
|
12
|
+
# span-level calls
|
13
|
+
:autolink, :codespan, :double_emphasis,
|
14
|
+
:emphasis, :underline, :raw_html,
|
15
|
+
:triple_emphasis, :strikethrough,
|
16
|
+
:superscript, :highlight,
|
17
|
+
|
18
|
+
# footnotes
|
19
|
+
:footnotes, :footnote_def, :footnote_ref,
|
20
|
+
|
21
|
+
# low level rendering
|
22
|
+
:entity, :normal_text
|
23
|
+
].each do |method|
|
24
|
+
define_method method do |*args|
|
25
|
+
args.first
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Other methods where we don't return only a specific argument
|
30
|
+
def link(link, title, content)
|
31
|
+
"#{content} (#{link})"
|
32
|
+
end
|
33
|
+
|
34
|
+
def image(link, title, content)
|
35
|
+
content &&= content + " "
|
36
|
+
"#{content}#{link}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def paragraph(text)
|
40
|
+
text + "\n"
|
41
|
+
end
|
42
|
+
|
43
|
+
def header(text, header_level)
|
44
|
+
text + "\n"
|
45
|
+
end
|
46
|
+
|
47
|
+
def table(header, body)
|
48
|
+
"#{header}#{body}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def table_row(content)
|
52
|
+
content + "\n"
|
53
|
+
end
|
54
|
+
|
55
|
+
def table_cell(content, alignment)
|
56
|
+
content + "\t"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|