redcarpet 1.17.2 → 2.0.0

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.
@@ -0,0 +1,33 @@
1
+ #ifndef REDCARPET_H__
2
+ #define REDCARPET_H__
3
+
4
+ #define RSTRING_NOT_MODIFIED
5
+ #include "ruby.h"
6
+ #include <stdio.h>
7
+
8
+ #ifdef HAVE_RUBY_ENCODING_H
9
+ # include <ruby/encoding.h>
10
+ # define redcarpet_str_new(data, size) rb_enc_str_new(data, size, rb_utf8_encoding())
11
+ #else
12
+ # define redcarpet_str_new(data, size) rb_str_new(data, size)
13
+ #endif
14
+
15
+ #include "markdown.h"
16
+ #include "html.h"
17
+
18
+ #define CSTR2SYM(s) (ID2SYM(rb_intern((s))))
19
+
20
+ extern void Init_redcarpet_rndr();
21
+
22
+ struct redcarpet_renderopt {
23
+ struct html_renderopt html;
24
+ VALUE self;
25
+ VALUE base_class;
26
+ };
27
+
28
+ struct rb_redcarpet_rndr {
29
+ struct sd_callbacks callbacks;
30
+ struct redcarpet_renderopt options;
31
+ };
32
+
33
+ #endif
@@ -0,0 +1,81 @@
1
+ #include "stack.h"
2
+ #include <string.h>
3
+
4
+ int
5
+ 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
+ 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
+ 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 stack_grow(st, initial_size);
52
+ }
53
+
54
+ void *
55
+ stack_pop(struct stack *st)
56
+ {
57
+ if (!st->size)
58
+ return NULL;
59
+
60
+ return st->item[--st->size];
61
+ }
62
+
63
+ int
64
+ stack_push(struct stack *st, void *item)
65
+ {
66
+ if (stack_grow(st, st->size * 2) < 0)
67
+ return -1;
68
+
69
+ st->item[st->size++] = item;
70
+ return 0;
71
+ }
72
+
73
+ void *
74
+ stack_top(struct stack *st)
75
+ {
76
+ if (!st->size)
77
+ return NULL;
78
+
79
+ return st->item[st->size - 1];
80
+ }
81
+
@@ -0,0 +1,21 @@
1
+ #ifndef STACK_H__
2
+ #define STACK_H__
3
+
4
+ #include <stdlib.h>
5
+
6
+ struct stack {
7
+ void **item;
8
+ size_t size;
9
+ size_t asize;
10
+ };
11
+
12
+ void stack_free(struct stack *);
13
+ int stack_grow(struct stack *, size_t);
14
+ int stack_init(struct stack *, size_t);
15
+
16
+ int stack_push(struct stack *, void *);
17
+
18
+ void *stack_pop(struct stack *);
19
+ void *stack_top(struct stack *);
20
+
21
+ #endif
@@ -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
data/lib/redcarpet.rb CHANGED
@@ -1,112 +1,73 @@
1
- # Upskirt is an implementation of John Gruber's Markdown markup
2
- # language. Upskirt is safe, fast and production ready.
3
- #
4
- # Redcarpet is Upskirt with a touch of Ruby. It is mostly based on Ryan
5
- # Tomayko's RDiscount, and inspired by Rick Astley wearing a kilt.
6
- #
7
- # Redcarpet is a drop-in replacement for BlueCloth, RedCloth and RDiscount.
8
- #
9
- # == Usage
10
- #
11
- # Redcarpet implements the basic protocol popularized by RedCloth and adopted
12
- # by BlueCloth:
13
- # require 'redcarpet'
14
- # markdown = Redcarpet.new("Hello World!")
15
- # puts markdown.to_html
16
- #
17
- # == Replacing BlueCloth
18
- #
19
- # Inject Redcarpet into your BlueCloth-using code by replacing your bluecloth
20
- # require statements with the following:
21
- # begin
22
- # require 'redcarpet'
23
- # BlueCloth = Redcarpet
24
- # rescue LoadError
25
- # require 'bluecloth'
26
- # end
27
- #
28
- class Redcarpet
29
- VERSION = '1.17.2'
30
-
31
- # Original Markdown formatted text.
32
- attr_reader :text
33
-
34
- # Set true to have smarty-like quote translation performed.
35
- attr_accessor :smart
36
-
37
- # Do not output <tt><style></tt> tags included in the source text.
38
- attr_accessor :filter_styles
39
-
40
- # Do not output any raw HTML included in the source text.
41
- attr_accessor :filter_html
42
-
43
- # Do not process <tt>![]</tt> and remove <tt><img></tt> tags from the output.
44
- attr_accessor :no_image
45
-
46
- # Do not process <tt>[]</tt> and remove <tt><a></tt> tags from the output.
47
- attr_accessor :no_links
48
-
49
- # Treat newlines in paragraphs as real line breaks, GitHub style
50
- attr_accessor :hard_wrap
51
-
52
- # Generate safer HTML for code blocks (no custom CSS classes)
53
- attr_accessor :gh_blockcode
54
-
55
- # Don't make hyperlinks from <tt>[][]</tt> links that have unknown URL types.
56
- attr_accessor :safelink
57
-
58
- # Add TOC anchors to every header
59
- attr_accessor :generate_toc
60
-
61
- # Enable the Autolinking extension
62
- attr_accessor :autolink
63
-
64
- # Enable PHP-Markdown tables extension
65
- attr_accessor :tables
66
-
67
- # Enable PHP-Markdown ~~strikethrough~~ extension
68
- attr_accessor :strikethrough
69
-
70
- # Enable PHP-Markdown fenced code extension
71
- attr_accessor :fenced_code
72
-
73
- # Allow HTML blocks inside of paragraphs without being surrounded by newlines
74
- attr_accessor :lax_htmlblock
75
-
76
- # Do not render emphasis_inside_words
77
- attr_accessor :no_intraemphasis
1
+ require 'redcarpet.so'
78
2
 
79
- # Generate XHTML 1.0 compilant self-closing tags (e.g. <br/>)
80
- attr_accessor :xhtml
3
+ module Redcarpet
4
+ VERSION = '2.0.0b5'
81
5
 
82
- # Force a space between header hashes and the header itself
83
- attr_accessor :space_header
6
+ class Markdown
7
+ attr_reader :renderer
8
+ end
84
9
 
85
- def initialize(text, *extensions)
86
- @text = text
87
- extensions.each { |e| send("#{e}=", true) }
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
88
53
  end
89
54
  end
90
55
 
91
- Markdown = Redcarpet unless defined? Markdown
92
-
93
56
  # Compatibility class;
94
- # Creates a instance of Redcarpet with all markdown
95
- # extensions enabled, same behavior as in RDiscount
96
- class RedcarpetCompat < Redcarpet
97
- # Backwards compatibility
98
- attr_accessor :fold_lines
99
- attr_accessor :no_tables
100
- attr_accessor :fold_lines
101
- attr_accessor :strict
57
+ # Creates a instance of Redcarpet with the RedCloth
58
+ # API. This instance has no extensions enabled whatsoever,
59
+ # and no accessors to change this. 100% pure, standard
60
+ # Markdown.
61
+ class RedcarpetCompat
62
+ attr_accessor :text
63
+
64
+ def initialize(text, *_dummy)
65
+ @text = text
66
+ @markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
67
+ end
102
68
 
103
- def initialize(text, *extensions)
104
- super(text, *extensions)
105
- self.tables = !self.no_tables
106
- self.strikethrough = true
107
- self.lax_htmlblock = true
108
- self.no_intraemphasis = !self.strict
69
+ def to_html(*_dummy)
70
+ @markdown.render(@text)
109
71
  end
110
72
  end
111
73
 
112
- require 'redcarpet.so'
data/redcarpet.gemspec CHANGED
@@ -1,9 +1,10 @@
1
+ # encoding: utf-8
1
2
  Gem::Specification.new do |s|
2
3
  s.name = 'redcarpet'
3
- s.version = '1.17.2'
4
- s.summary = "Ruby bindings for libupskirt"
5
- s.description = 'A fast and safe Markdown to (X)HTML parser'
6
- s.date = '2011-06-19'
4
+ s.version = '2.0.0'
5
+ s.summary = "Markdown that smells nice"
6
+ s.description = 'A fast, safe and extensible Markdown to (X)HTML parser'
7
+ s.date = '2011-09-14'
7
8
  s.email = 'vicent@github.com'
8
9
  s.homepage = 'http://github.com/tanoku/redcarpet'
9
10
  s.authors = ["Natacha Porté", "Vicent Martí"]
@@ -13,32 +14,36 @@ Gem::Specification.new do |s|
13
14
  README.markdown
14
15
  Rakefile
15
16
  bin/redcarpet
16
- ext/redcarpet/array.c
17
- ext/redcarpet/array.h
18
17
  ext/redcarpet/autolink.c
19
18
  ext/redcarpet/autolink.h
20
19
  ext/redcarpet/buffer.c
21
20
  ext/redcarpet/buffer.h
22
21
  ext/redcarpet/extconf.rb
22
+ ext/redcarpet/houdini.h
23
+ ext/redcarpet/houdini_href_e.c
24
+ ext/redcarpet/houdini_html_e.c
23
25
  ext/redcarpet/html.c
24
26
  ext/redcarpet/html.h
27
+ ext/redcarpet/html_blocks.h
25
28
  ext/redcarpet/html_smartypants.c
26
29
  ext/redcarpet/markdown.c
27
30
  ext/redcarpet/markdown.h
28
- ext/redcarpet/redcarpet.c
29
- lib/markdown.rb
31
+ ext/redcarpet/rc_markdown.c
32
+ ext/redcarpet/rc_render.c
33
+ ext/redcarpet/redcarpet.h
34
+ ext/redcarpet/stack.c
35
+ ext/redcarpet/stack.h
30
36
  lib/redcarpet.rb
37
+ lib/redcarpet/render_man.rb
31
38
  redcarpet.gemspec
32
- test/benchmark.rb
33
- test/benchmark.txt
34
- test/markdown_test.rb
39
+ sundown
35
40
  test/redcarpet_test.rb
36
- upskirt
37
41
  ]
38
42
  # = MANIFEST =
39
- s.test_files = ["test/markdown_test.rb", "test/redcarpet_test.rb"]
43
+ s.test_files = ["test/redcarpet_test.rb"]
40
44
  s.extra_rdoc_files = ["COPYING"]
41
45
  s.extensions = ["ext/redcarpet/extconf.rb"]
42
46
  s.executables = ["redcarpet"]
43
47
  s.require_paths = ["lib"]
48
+ s.add_development_dependency "rake-compiler"
44
49
  end