tight-redcarpet 3.1.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 +14 -0
- data/Gemfile +9 -0
- data/README.markdown +386 -0
- data/Rakefile +60 -0
- data/bin/redcarpet +43 -0
- data/ext/redcarpet/autolink.c +296 -0
- data/ext/redcarpet/autolink.h +49 -0
- data/ext/redcarpet/buffer.c +196 -0
- data/ext/redcarpet/buffer.h +83 -0
- data/ext/redcarpet/extconf.rb +6 -0
- data/ext/redcarpet/houdini.h +29 -0
- data/ext/redcarpet/houdini_href_e.c +108 -0
- data/ext/redcarpet/houdini_html_e.c +83 -0
- data/ext/redcarpet/html.c +770 -0
- data/ext/redcarpet/html.h +78 -0
- data/ext/redcarpet/html_blocks.h +206 -0
- data/ext/redcarpet/html_smartypants.c +445 -0
- data/ext/redcarpet/markdown.c +2907 -0
- data/ext/redcarpet/markdown.h +141 -0
- data/ext/redcarpet/rc_markdown.c +165 -0
- data/ext/redcarpet/rc_render.c +529 -0
- data/ext/redcarpet/redcarpet.h +30 -0
- data/ext/redcarpet/stack.c +62 -0
- data/ext/redcarpet/stack.h +26 -0
- data/lib/redcarpet.rb +125 -0
- data/lib/redcarpet/compat.rb +3 -0
- data/lib/redcarpet/render_man.rb +65 -0
- data/lib/redcarpet/render_strip.rb +48 -0
- data/redcarpet.gemspec +65 -0
- data/test/custom_render_test.rb +28 -0
- data/test/html_render_test.rb +232 -0
- data/test/html_toc_render_test.rb +49 -0
- data/test/markdown_test.rb +311 -0
- data/test/pathological_inputs_test.rb +34 -0
- data/test/redcarpet_compat_test.rb +38 -0
- data/test/smarty_html_test.rb +45 -0
- data/test/smarty_pants_test.rb +48 -0
- data/test/stripdown_render_test.rb +42 -0
- data/test/test_helper.rb +18 -0
- metadata +141 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
#ifndef REDCARPET_H__
|
2
|
+
#define REDCARPET_H__
|
3
|
+
|
4
|
+
#define RSTRING_NOT_MODIFIED
|
5
|
+
#include "ruby.h"
|
6
|
+
#include <stdio.h>
|
7
|
+
|
8
|
+
#include <ruby/encoding.h>
|
9
|
+
|
10
|
+
#include "markdown.h"
|
11
|
+
#include "html.h"
|
12
|
+
|
13
|
+
#define CSTR2SYM(s) (ID2SYM(rb_intern((s))))
|
14
|
+
|
15
|
+
void Init_redcarpet_rndr();
|
16
|
+
|
17
|
+
struct redcarpet_renderopt {
|
18
|
+
struct html_renderopt html;
|
19
|
+
VALUE link_attributes;
|
20
|
+
VALUE self;
|
21
|
+
VALUE base_class;
|
22
|
+
rb_encoding *active_enc;
|
23
|
+
};
|
24
|
+
|
25
|
+
struct rb_redcarpet_rndr {
|
26
|
+
struct sd_callbacks callbacks;
|
27
|
+
struct redcarpet_renderopt options;
|
28
|
+
};
|
29
|
+
|
30
|
+
#endif
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#include "stack.h"
|
2
|
+
#include <string.h>
|
3
|
+
|
4
|
+
int
|
5
|
+
redcarpet_stack_grow(struct stack *st, size_t new_size)
|
6
|
+
{
|
7
|
+
void **new_st;
|
8
|
+
|
9
|
+
if (st->asize >= new_size)
|
10
|
+
return 0;
|
11
|
+
|
12
|
+
new_st = realloc(st->item, new_size * sizeof(void *));
|
13
|
+
if (new_st == NULL)
|
14
|
+
return -1;
|
15
|
+
|
16
|
+
memset(new_st + st->asize, 0x0,
|
17
|
+
(new_size - st->asize) * sizeof(void *));
|
18
|
+
|
19
|
+
st->item = new_st;
|
20
|
+
st->asize = new_size;
|
21
|
+
|
22
|
+
if (st->size > new_size)
|
23
|
+
st->size = new_size;
|
24
|
+
|
25
|
+
return 0;
|
26
|
+
}
|
27
|
+
|
28
|
+
void
|
29
|
+
redcarpet_stack_free(struct stack *st)
|
30
|
+
{
|
31
|
+
if (!st)
|
32
|
+
return;
|
33
|
+
|
34
|
+
free(st->item);
|
35
|
+
|
36
|
+
st->item = NULL;
|
37
|
+
st->size = 0;
|
38
|
+
st->asize = 0;
|
39
|
+
}
|
40
|
+
|
41
|
+
int
|
42
|
+
redcarpet_stack_init(struct stack *st, size_t initial_size)
|
43
|
+
{
|
44
|
+
st->item = NULL;
|
45
|
+
st->size = 0;
|
46
|
+
st->asize = 0;
|
47
|
+
|
48
|
+
if (!initial_size)
|
49
|
+
initial_size = 8;
|
50
|
+
|
51
|
+
return redcarpet_stack_grow(st, initial_size);
|
52
|
+
}
|
53
|
+
|
54
|
+
int
|
55
|
+
redcarpet_stack_push(struct stack *st, void *item)
|
56
|
+
{
|
57
|
+
if (redcarpet_stack_grow(st, st->size * 2) < 0)
|
58
|
+
return -1;
|
59
|
+
|
60
|
+
st->item[st->size++] = item;
|
61
|
+
return 0;
|
62
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#ifndef STACK_H__
|
2
|
+
#define STACK_H__
|
3
|
+
|
4
|
+
#include <stdlib.h>
|
5
|
+
|
6
|
+
#ifdef __cplusplus
|
7
|
+
extern "C" {
|
8
|
+
#endif
|
9
|
+
|
10
|
+
struct stack {
|
11
|
+
void **item;
|
12
|
+
size_t size;
|
13
|
+
size_t asize;
|
14
|
+
};
|
15
|
+
|
16
|
+
void redcarpet_stack_free(struct stack *);
|
17
|
+
int redcarpet_stack_grow(struct stack *, size_t);
|
18
|
+
int redcarpet_stack_init(struct stack *, size_t);
|
19
|
+
|
20
|
+
int redcarpet_stack_push(struct stack *, void *);
|
21
|
+
|
22
|
+
#ifdef __cplusplus
|
23
|
+
}
|
24
|
+
#endif
|
25
|
+
|
26
|
+
#endif
|
data/lib/redcarpet.rb
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'redcarpet.so'
|
2
|
+
|
3
|
+
module Redcarpet
|
4
|
+
VERSION = '3.1.1'
|
5
|
+
|
6
|
+
class Markdown
|
7
|
+
attr_reader :renderer
|
8
|
+
end
|
9
|
+
|
10
|
+
module Render
|
11
|
+
|
12
|
+
# XHTML Renderer
|
13
|
+
class XHTML < HTML
|
14
|
+
def initialize(extensions={})
|
15
|
+
super(extensions.merge(:xhtml => true))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# HTML + SmartyPants renderer
|
20
|
+
class SmartyHTML < HTML
|
21
|
+
include SmartyPants
|
22
|
+
end
|
23
|
+
|
24
|
+
# SmartyPants Mixin module
|
25
|
+
#
|
26
|
+
# Implements SmartyPants.postprocess, which
|
27
|
+
# performs smartypants replacements on the HTML file,
|
28
|
+
# once it has been fully rendered.
|
29
|
+
#
|
30
|
+
# To add SmartyPants postprocessing to your custom
|
31
|
+
# renderers, just mixin the module `include SmartyPants`
|
32
|
+
#
|
33
|
+
# You can also use this as a standalone SmartyPants
|
34
|
+
# implementation.
|
35
|
+
#
|
36
|
+
# Example:
|
37
|
+
#
|
38
|
+
# # Mixin
|
39
|
+
# class CoolRenderer < HTML
|
40
|
+
# include SmartyPants
|
41
|
+
# # more code here
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# # Standalone
|
45
|
+
# Redcarpet::Render::SmartyPants.render("you're")
|
46
|
+
#
|
47
|
+
module SmartyPants
|
48
|
+
extend self
|
49
|
+
def self.render(text)
|
50
|
+
postprocess text
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Compatibility class;
|
57
|
+
# Creates an instance of Redcarpet with the RedCloth API.
|
58
|
+
class RedcarpetCompat
|
59
|
+
attr_accessor :text
|
60
|
+
|
61
|
+
def initialize(text, *exts)
|
62
|
+
exts_hash, render_hash = *parse_extensions_and_renderer_options(exts)
|
63
|
+
@text = text
|
64
|
+
renderer = Redcarpet::Render::HTML.new(render_hash)
|
65
|
+
@markdown = Redcarpet::Markdown.new(renderer, exts_hash)
|
66
|
+
end
|
67
|
+
|
68
|
+
def to_html(*_dummy)
|
69
|
+
@markdown.render(@text)
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
EXTENSION_MAP = {
|
75
|
+
# old name => new name
|
76
|
+
:autolink => :autolink,
|
77
|
+
:fenced_code => :fenced_code_blocks,
|
78
|
+
:filter_html => :filter_html,
|
79
|
+
:hard_wrap => :hard_wrap,
|
80
|
+
:prettify => :prettify,
|
81
|
+
:lax_htmlblock => :lax_spacing,
|
82
|
+
:no_image => :no_images,
|
83
|
+
:no_intraemphasis => :no_intra_emphasis,
|
84
|
+
:no_links => :no_links,
|
85
|
+
:filter_styles => :no_styles,
|
86
|
+
:safelink => :safe_links_only,
|
87
|
+
:space_header => :space_after_headers,
|
88
|
+
:strikethrough => :strikethrough,
|
89
|
+
:tables => :tables,
|
90
|
+
:generate_toc => :with_toc_data,
|
91
|
+
:xhtml => :xhtml,
|
92
|
+
# old names with no new mapping
|
93
|
+
:gh_blockcode => nil,
|
94
|
+
:no_tables => nil,
|
95
|
+
:smart => nil,
|
96
|
+
:strict => nil
|
97
|
+
}
|
98
|
+
|
99
|
+
RENDERER_OPTIONS = [:filter_html, :no_images, :no_links, :no_styles,
|
100
|
+
:safe_links_only, :with_toc_data, :hard_wrap, :prettify, :xhtml]
|
101
|
+
|
102
|
+
def rename_extensions(exts)
|
103
|
+
exts.map do |old_name|
|
104
|
+
if new_name = EXTENSION_MAP[old_name]
|
105
|
+
new_name
|
106
|
+
else
|
107
|
+
old_name
|
108
|
+
end
|
109
|
+
end.compact
|
110
|
+
end
|
111
|
+
|
112
|
+
# Returns two hashes, the extensions and renderer options
|
113
|
+
# given the extension list
|
114
|
+
def parse_extensions_and_renderer_options(exts)
|
115
|
+
exts = rename_extensions(exts)
|
116
|
+
exts.partition {|ext| !RENDERER_OPTIONS.include?(ext) }.
|
117
|
+
map {|list| list_to_truthy_hash(list) }
|
118
|
+
end
|
119
|
+
|
120
|
+
# Turns a list of symbols into a hash of <tt>symbol => true</tt>.
|
121
|
+
def list_to_truthy_hash(list)
|
122
|
+
list.inject({}) {|h, k| h[k] = true; h }
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
@@ -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,48 @@
|
|
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,
|
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 the text content is in another argument
|
30
|
+
def link(link, title, content)
|
31
|
+
content
|
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
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/redcarpet.gemspec
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.name = 'tight-redcarpet'
|
4
|
+
s.version = '3.1.1'
|
5
|
+
s.summary = "Markdown that smells nice (patch level 'tight')"
|
6
|
+
s.description = 'A fast, safe and extensible Markdown to (X)HTML parser patched to have smaller headings and no quote-escaping'
|
7
|
+
s.date = '2014-07-04'
|
8
|
+
s.email = 'ujifgc@github.com'
|
9
|
+
s.homepage = 'http://github.com/ujifgc/redcarpet'
|
10
|
+
s.authors = ["Natacha Porté", "Vicent Martí", "Igor Bochkariov"]
|
11
|
+
s.license = 'MIT'
|
12
|
+
s.required_ruby_version = '>= 1.9.2'
|
13
|
+
# = MANIFEST =
|
14
|
+
s.files = %w[
|
15
|
+
COPYING
|
16
|
+
Gemfile
|
17
|
+
README.markdown
|
18
|
+
Rakefile
|
19
|
+
bin/redcarpet
|
20
|
+
ext/redcarpet/autolink.c
|
21
|
+
ext/redcarpet/autolink.h
|
22
|
+
ext/redcarpet/buffer.c
|
23
|
+
ext/redcarpet/buffer.h
|
24
|
+
ext/redcarpet/extconf.rb
|
25
|
+
ext/redcarpet/houdini.h
|
26
|
+
ext/redcarpet/houdini_href_e.c
|
27
|
+
ext/redcarpet/houdini_html_e.c
|
28
|
+
ext/redcarpet/html.c
|
29
|
+
ext/redcarpet/html.h
|
30
|
+
ext/redcarpet/html_blocks.h
|
31
|
+
ext/redcarpet/html_smartypants.c
|
32
|
+
ext/redcarpet/markdown.c
|
33
|
+
ext/redcarpet/markdown.h
|
34
|
+
ext/redcarpet/rc_markdown.c
|
35
|
+
ext/redcarpet/rc_render.c
|
36
|
+
ext/redcarpet/redcarpet.h
|
37
|
+
ext/redcarpet/stack.c
|
38
|
+
ext/redcarpet/stack.h
|
39
|
+
lib/redcarpet.rb
|
40
|
+
lib/redcarpet/compat.rb
|
41
|
+
lib/redcarpet/render_man.rb
|
42
|
+
lib/redcarpet/render_strip.rb
|
43
|
+
redcarpet.gemspec
|
44
|
+
test/test_helper.rb
|
45
|
+
test/custom_render_test.rb
|
46
|
+
test/html_render_test.rb
|
47
|
+
test/html_toc_render_test.rb
|
48
|
+
test/markdown_test.rb
|
49
|
+
test/pathological_inputs_test.rb
|
50
|
+
test/redcarpet_compat_test.rb
|
51
|
+
test/smarty_html_test.rb
|
52
|
+
test/smarty_pants_test.rb
|
53
|
+
test/stripdown_render_test.rb
|
54
|
+
]
|
55
|
+
# = MANIFEST =
|
56
|
+
s.test_files = s.files.grep(%r{^test/})
|
57
|
+
s.extra_rdoc_files = ["COPYING"]
|
58
|
+
s.extensions = ["ext/redcarpet/extconf.rb"]
|
59
|
+
s.executables = ["redcarpet"]
|
60
|
+
s.require_paths = ["lib"]
|
61
|
+
|
62
|
+
s.add_development_dependency "nokogiri", "~> 1.6.0"
|
63
|
+
s.add_development_dependency "rake-compiler", "~> 0.8.3"
|
64
|
+
s.add_development_dependency "test-unit", "~> 2.5.4"
|
65
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class CustomRenderTest < Redcarpet::TestCase
|
5
|
+
class SimpleRender < Redcarpet::Render::HTML
|
6
|
+
def emphasis(text)
|
7
|
+
"<em class=\"cool\">#{text}</em>"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_simple_overload
|
12
|
+
md = Redcarpet::Markdown.new(SimpleRender)
|
13
|
+
html_equal "<p>This is <em class=\"cool\">just</em> a test</p>\n",
|
14
|
+
md.render("This is *just* a test")
|
15
|
+
end
|
16
|
+
|
17
|
+
class NilPreprocessRenderer < Redcarpet::Render::HTML
|
18
|
+
def preprocess(fulldoc)
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_preprocess_returning_nil
|
24
|
+
md = Redcarpet::Markdown.new(NilPreprocessRenderer)
|
25
|
+
assert_equal(nil,md.render("Anything"))
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|