redcarpet 1.5.0 → 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,80 +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.5.0'
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
- attr_accessor :fold_lines # Ignore, just for compatibility
41
-
42
- # Do not output any raw HTML included in the source text.
43
- attr_accessor :filter_html
44
-
45
- # Do not process <tt>![]</tt> and remove <tt><img></tt> tags from the output.
46
- attr_accessor :no_image
47
-
48
- # Do not process <tt>[]</tt> and remove <tt><a></tt> tags from the output.
49
- attr_accessor :no_links
50
-
51
- # Disable superscript and relaxed emphasis processing.
52
- attr_accessor :strict
53
-
54
- # Convert URL in links, even if they aren't encased in <tt><></tt>
55
- attr_accessor :autolink
56
-
57
- # Don't make hyperlinks from <tt>[][]</tt> links that have unknown URL types.
58
- attr_accessor :safelink
1
+ require 'redcarpet.so'
59
2
 
60
- # Add TOC anchors to every header
61
- attr_accessor :generate_toc
3
+ module Redcarpet
4
+ VERSION = '2.0.0b5'
62
5
 
63
- # Do not process tables
64
- attr_accessor :no_tables
6
+ class Markdown
7
+ attr_reader :renderer
8
+ end
65
9
 
66
- # Do not process ~~strikethrough~~
67
- attr_accessor :no_strikethrough
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
68
55
 
69
- # Do not process fenced code blocks
70
- attr_accessor :no_fencedcode
56
+ # Compatibility class;
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
71
68
 
72
- def initialize(text, *extensions)
73
- @text = text
74
- extensions.each { |e| send("#{e}=", true) }
69
+ def to_html(*_dummy)
70
+ @markdown.render(@text)
75
71
  end
76
72
  end
77
73
 
78
- Markdown = Redcarpet unless defined? Markdown
79
-
80
- require 'redcarpet.so'
data/redcarpet.gemspec CHANGED
@@ -1,11 +1,12 @@
1
+ # encoding: utf-8
1
2
  Gem::Specification.new do |s|
2
3
  s.name = 'redcarpet'
3
- s.version = '1.5.0'
4
- s.summary = "Ruby bindings for libupskirt"
5
- s.date = '2011-04-11'
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'
6
8
  s.email = 'vicent@github.com'
7
9
  s.homepage = 'http://github.com/tanoku/redcarpet'
8
- s.has_rdoc = true
9
10
  s.authors = ["Natacha Porté", "Vicent Martí"]
10
11
  # = MANIFEST =
11
12
  s.files = %w[
@@ -13,28 +14,36 @@ Gem::Specification.new do |s|
13
14
  README.markdown
14
15
  Rakefile
15
16
  bin/redcarpet
16
- ext/array.c
17
- ext/array.h
18
- ext/buffer.c
19
- ext/buffer.h
20
- ext/extconf.rb
21
- ext/markdown.c
22
- ext/markdown.h
23
- ext/redcarpet.c
24
- ext/xhtml.c
25
- ext/xhtml.h
26
- lib/markdown.rb
17
+ ext/redcarpet/autolink.c
18
+ ext/redcarpet/autolink.h
19
+ ext/redcarpet/buffer.c
20
+ ext/redcarpet/buffer.h
21
+ ext/redcarpet/extconf.rb
22
+ ext/redcarpet/houdini.h
23
+ ext/redcarpet/houdini_href_e.c
24
+ ext/redcarpet/houdini_html_e.c
25
+ ext/redcarpet/html.c
26
+ ext/redcarpet/html.h
27
+ ext/redcarpet/html_blocks.h
28
+ ext/redcarpet/html_smartypants.c
29
+ ext/redcarpet/markdown.c
30
+ ext/redcarpet/markdown.h
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
27
36
  lib/redcarpet.rb
37
+ lib/redcarpet/render_man.rb
28
38
  redcarpet.gemspec
29
- test/benchmark.rb
30
- test/benchmark.txt
31
- test/markdown_test.rb
39
+ sundown
32
40
  test/redcarpet_test.rb
33
41
  ]
34
42
  # = MANIFEST =
35
- s.test_files = ["test/markdown_test.rb", "test/redcarpet_test.rb"]
43
+ s.test_files = ["test/redcarpet_test.rb"]
36
44
  s.extra_rdoc_files = ["COPYING"]
37
- s.extensions = ["ext/extconf.rb"]
45
+ s.extensions = ["ext/redcarpet/extconf.rb"]
38
46
  s.executables = ["redcarpet"]
39
47
  s.require_paths = ["lib"]
48
+ s.add_development_dependency "rake-compiler"
40
49
  end