rdiscountwl 1.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/BUILDING +151 -0
- data/COPYING +33 -0
- data/README.markdown +73 -0
- data/Rakefile +224 -0
- data/bin/rdiscount +13 -0
- data/ext/Csio.c +61 -0
- data/ext/VERSION +1 -0
- data/ext/amalloc.c +135 -0
- data/ext/amalloc.h +29 -0
- data/ext/basename.c +43 -0
- data/ext/blocktags +33 -0
- data/ext/config.h +25 -0
- data/ext/css.c +87 -0
- data/ext/cstring.h +77 -0
- data/ext/docheader.c +49 -0
- data/ext/dumptree.c +151 -0
- data/ext/emmatch.c +188 -0
- data/ext/extconf.rb +49 -0
- data/ext/flags.c +91 -0
- data/ext/generate.c +1865 -0
- data/ext/github_flavoured.c +100 -0
- data/ext/html5.c +22 -0
- data/ext/markdown.c +1361 -0
- data/ext/markdown.h +238 -0
- data/ext/mkdio.c +360 -0
- data/ext/mkdio.h +122 -0
- data/ext/mktags.c +89 -0
- data/ext/pgm_options.c +146 -0
- data/ext/pgm_options.h +9 -0
- data/ext/rdiscount.c +150 -0
- data/ext/resource.c +159 -0
- data/ext/setup.c +39 -0
- data/ext/tags.c +94 -0
- data/ext/tags.h +19 -0
- data/ext/toc.c +114 -0
- data/ext/version.c +13 -0
- data/ext/xml.c +82 -0
- data/ext/xmlpage.c +46 -0
- data/lib/markdown.rb +1 -0
- data/lib/rdiscount.rb +108 -0
- data/man/markdown.7 +1020 -0
- data/man/rdiscount.1 +22 -0
- data/man/rdiscount.1.ronn +24 -0
- data/rdiscount.gemspec +71 -0
- data/test/benchmark.rb +56 -0
- data/test/benchmark.txt +306 -0
- data/test/markdown_test.rb +158 -0
- data/test/rdiscount_test.rb +276 -0
- metadata +99 -0
data/ext/toc.c
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
/*
|
2
|
+
* toc -- spit out a table of contents based on header blocks
|
3
|
+
*
|
4
|
+
* Copyright (C) 2008 Jjgod Jiang, David L Parsons
|
5
|
+
* portions Copyright (C) 2011 Stefano D'Angelo
|
6
|
+
* The redistribution terms are provided in the COPYRIGHT file that must
|
7
|
+
* be distributed with this source code.
|
8
|
+
*/
|
9
|
+
#include "config.h"
|
10
|
+
#include <stdio.h>
|
11
|
+
#include <stdlib.h>
|
12
|
+
#include <ctype.h>
|
13
|
+
|
14
|
+
#include "cstring.h"
|
15
|
+
#include "markdown.h"
|
16
|
+
#include "amalloc.h"
|
17
|
+
|
18
|
+
/* write an header index
|
19
|
+
*/
|
20
|
+
int
|
21
|
+
mkd_toc(Document *p, char **doc)
|
22
|
+
{
|
23
|
+
Paragraph *tp, *srcp;
|
24
|
+
int last_hnumber = 0;
|
25
|
+
Cstring res;
|
26
|
+
int size;
|
27
|
+
int first = 1;
|
28
|
+
|
29
|
+
if ( !(doc && p && p->ctx) ) return -1;
|
30
|
+
|
31
|
+
*doc = 0;
|
32
|
+
|
33
|
+
if ( ! (p->ctx->flags & MKD_TOC) ) return 0;
|
34
|
+
|
35
|
+
CREATE(res);
|
36
|
+
RESERVE(res, 100);
|
37
|
+
|
38
|
+
for ( tp = p->code; tp ; tp = tp->next ) {
|
39
|
+
if ( tp->typ == SOURCE ) {
|
40
|
+
for ( srcp = tp->down; srcp; srcp = srcp->next ) {
|
41
|
+
if ( srcp->typ == HDR && srcp->text ) {
|
42
|
+
|
43
|
+
while ( last_hnumber > srcp->hnumber ) {
|
44
|
+
if ( (last_hnumber - srcp->hnumber) > 1 )
|
45
|
+
Csprintf(&res, "\n");
|
46
|
+
Csprintf(&res, "</li>\n%*s</ul>\n%*s",
|
47
|
+
last_hnumber-1, "", last_hnumber-1, "");
|
48
|
+
--last_hnumber;
|
49
|
+
}
|
50
|
+
|
51
|
+
if ( last_hnumber == srcp->hnumber )
|
52
|
+
Csprintf(&res, "</li>\n");
|
53
|
+
else if ( (srcp->hnumber > last_hnumber) && !first )
|
54
|
+
Csprintf(&res, "\n");
|
55
|
+
|
56
|
+
while ( srcp->hnumber > last_hnumber ) {
|
57
|
+
Csprintf(&res, "%*s<ul>\n", last_hnumber, "");
|
58
|
+
if ( (srcp->hnumber - last_hnumber) > 1 )
|
59
|
+
Csprintf(&res, "%*s<li>\n", last_hnumber+1, "");
|
60
|
+
++last_hnumber;
|
61
|
+
}
|
62
|
+
Csprintf(&res, "%*s<li><a href=\"#", srcp->hnumber, "");
|
63
|
+
mkd_string_to_anchor(T(srcp->text->text),
|
64
|
+
S(srcp->text->text),
|
65
|
+
(mkd_sta_function_t)Csputc, &res,1,p->ctx->flags);
|
66
|
+
Csprintf(&res, "\">");
|
67
|
+
mkd_string_to_anchor(T(srcp->text->text),
|
68
|
+
S(srcp->text->text),
|
69
|
+
(mkd_sta_function_t)Csputc, &res,0,p->ctx->flags);
|
70
|
+
Csprintf(&res, "</a>");
|
71
|
+
|
72
|
+
first = 0;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
while ( last_hnumber > 0 ) {
|
79
|
+
--last_hnumber;
|
80
|
+
Csprintf(&res, "</li>\n%*s</ul>\n%*s",
|
81
|
+
last_hnumber, "", last_hnumber, "");
|
82
|
+
}
|
83
|
+
|
84
|
+
if ( (size = S(res)) > 0 ) {
|
85
|
+
EXPAND(res) = 0;
|
86
|
+
/* HACK ALERT! HACK ALERT! HACK ALERT! */
|
87
|
+
*doc = T(res); /* we know that a T(Cstring) is a character pointer
|
88
|
+
* so we can simply pick it up and carry it away,
|
89
|
+
* leaving the husk of the Ctring on the stack
|
90
|
+
* END HACK ALERT
|
91
|
+
*/
|
92
|
+
}
|
93
|
+
else
|
94
|
+
DELETE(res);
|
95
|
+
return size;
|
96
|
+
}
|
97
|
+
|
98
|
+
|
99
|
+
/* write an header index
|
100
|
+
*/
|
101
|
+
int
|
102
|
+
mkd_generatetoc(Document *p, FILE *out)
|
103
|
+
{
|
104
|
+
char *buf = 0;
|
105
|
+
int sz = mkd_toc(p, &buf);
|
106
|
+
int ret = EOF;
|
107
|
+
|
108
|
+
if ( sz > 0 )
|
109
|
+
ret = fwrite(buf, 1, sz, out);
|
110
|
+
|
111
|
+
if ( buf ) free(buf);
|
112
|
+
|
113
|
+
return (ret == sz) ? ret : EOF;
|
114
|
+
}
|
data/ext/version.c
ADDED
data/ext/xml.c
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
/* markdown: a C implementation of John Gruber's Markdown markup language.
|
2
|
+
*
|
3
|
+
* Copyright (C) 2007 David L Parsons.
|
4
|
+
* The redistribution terms are provided in the COPYRIGHT file that must
|
5
|
+
* be distributed with this source code.
|
6
|
+
*/
|
7
|
+
#include <stdio.h>
|
8
|
+
#include <string.h>
|
9
|
+
#include <stdarg.h>
|
10
|
+
#include <stdlib.h>
|
11
|
+
#include <time.h>
|
12
|
+
#include <ctype.h>
|
13
|
+
|
14
|
+
#include "config.h"
|
15
|
+
|
16
|
+
#include "cstring.h"
|
17
|
+
#include "markdown.h"
|
18
|
+
#include "amalloc.h"
|
19
|
+
|
20
|
+
/* return the xml version of a character
|
21
|
+
*/
|
22
|
+
static char *
|
23
|
+
mkd_xmlchar(unsigned char c)
|
24
|
+
{
|
25
|
+
switch (c) {
|
26
|
+
case '<': return "<";
|
27
|
+
case '>': return ">";
|
28
|
+
case '&': return "&";
|
29
|
+
case '"': return """;
|
30
|
+
case '\'': return "'";
|
31
|
+
default: if ( isascii(c) || (c & 0x80) )
|
32
|
+
return 0;
|
33
|
+
return "";
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
|
38
|
+
/* write output in XML format
|
39
|
+
*/
|
40
|
+
int
|
41
|
+
mkd_generatexml(char *p, int size, FILE *out)
|
42
|
+
{
|
43
|
+
unsigned char c;
|
44
|
+
char *entity;
|
45
|
+
|
46
|
+
while ( size-- > 0 ) {
|
47
|
+
c = *p++;
|
48
|
+
|
49
|
+
if ( entity = mkd_xmlchar(c) )
|
50
|
+
DO_OR_DIE( fputs(entity, out) );
|
51
|
+
else
|
52
|
+
DO_OR_DIE( fputc(c, out) );
|
53
|
+
}
|
54
|
+
return 0;
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
/* build a xml'ed version of a string
|
59
|
+
*/
|
60
|
+
int
|
61
|
+
mkd_xml(char *p, int size, char **res)
|
62
|
+
{
|
63
|
+
unsigned char c;
|
64
|
+
char *entity;
|
65
|
+
Cstring f;
|
66
|
+
|
67
|
+
CREATE(f);
|
68
|
+
RESERVE(f, 100);
|
69
|
+
|
70
|
+
while ( size-- > 0 ) {
|
71
|
+
c = *p++;
|
72
|
+
if ( entity = mkd_xmlchar(c) )
|
73
|
+
Cswrite(&f, entity, strlen(entity));
|
74
|
+
else
|
75
|
+
Csputc(c, &f);
|
76
|
+
}
|
77
|
+
/* HACK ALERT! HACK ALERT! HACK ALERT! */
|
78
|
+
*res = T(f); /* we know that a T(Cstring) is a character pointer */
|
79
|
+
/* so we can simply pick it up and carry it away, */
|
80
|
+
return S(f); /* leaving the husk of the Ctring on the stack */
|
81
|
+
/* END HACK ALERT */
|
82
|
+
}
|
data/ext/xmlpage.c
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
/*
|
2
|
+
* xmlpage -- write a skeletal xhtml page
|
3
|
+
*
|
4
|
+
* Copyright (C) 2007 David L Parsons.
|
5
|
+
* The redistribution terms are provided in the COPYRIGHT file that must
|
6
|
+
* be distributed with this source code.
|
7
|
+
*/
|
8
|
+
#include "config.h"
|
9
|
+
#include <stdio.h>
|
10
|
+
#include <stdlib.h>
|
11
|
+
#include <ctype.h>
|
12
|
+
|
13
|
+
#include "cstring.h"
|
14
|
+
#include "markdown.h"
|
15
|
+
#include "amalloc.h"
|
16
|
+
|
17
|
+
|
18
|
+
int
|
19
|
+
mkd_xhtmlpage(Document *p, int flags, FILE *out)
|
20
|
+
{
|
21
|
+
char *title;
|
22
|
+
extern char *mkd_doc_title(Document *);
|
23
|
+
|
24
|
+
if ( mkd_compile(p, flags) ) {
|
25
|
+
DO_OR_DIE( fprintf(out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
26
|
+
"<!DOCTYPE html "
|
27
|
+
" PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\""
|
28
|
+
" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
|
29
|
+
"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n") );
|
30
|
+
|
31
|
+
DO_OR_DIE( fprintf(out, "<head>\n") );
|
32
|
+
if ( title = mkd_doc_title(p) ) {
|
33
|
+
DO_OR_DIE( fprintf(out, "<title>%s</title>\n", title) );
|
34
|
+
}
|
35
|
+
DO_OR_DIE( mkd_generatecss(p, out) );
|
36
|
+
DO_OR_DIE( fprintf(out, "</head>\n"
|
37
|
+
"<body>\n") );
|
38
|
+
|
39
|
+
DO_OR_DIE( mkd_generatehtml(p, out) );
|
40
|
+
DO_OR_DIE( fprintf(out, "</body>\n"
|
41
|
+
"</html>\n") );
|
42
|
+
|
43
|
+
return 0;
|
44
|
+
}
|
45
|
+
return EOF;
|
46
|
+
}
|
data/lib/markdown.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rdiscount'
|
data/lib/rdiscount.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# Discount is an implementation of John Gruber's Markdown markup
|
2
|
+
# language in C. It implements all of the language as described in
|
3
|
+
# {Markdown Syntax}[http://daringfireball.net/projects/markdown/syntax]
|
4
|
+
# and passes the Markdown 1.0 test suite. The RDiscount extension makes
|
5
|
+
# the Discount processor available via a Ruby C Extension library.
|
6
|
+
#
|
7
|
+
# == Usage
|
8
|
+
#
|
9
|
+
# RDiscount implements the basic protocol popularized by RedCloth and adopted
|
10
|
+
# by BlueCloth:
|
11
|
+
# require 'rdiscount'
|
12
|
+
# markdown = RDiscount.new("Hello World!")
|
13
|
+
# puts markdown.to_html
|
14
|
+
#
|
15
|
+
# == Replacing BlueCloth
|
16
|
+
#
|
17
|
+
# Inject RDiscount into your BlueCloth-using code by replacing your bluecloth
|
18
|
+
# require statements with the following:
|
19
|
+
# begin
|
20
|
+
# require 'rdiscount'
|
21
|
+
# BlueCloth = RDiscount
|
22
|
+
# rescue LoadError
|
23
|
+
# require 'bluecloth'
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
class RDiscount
|
27
|
+
VERSION = '2.2.0.2'
|
28
|
+
|
29
|
+
# Original Markdown formatted text.
|
30
|
+
attr_reader :text
|
31
|
+
|
32
|
+
# Set true to have smarty-like quote translation performed.
|
33
|
+
attr_accessor :smart
|
34
|
+
|
35
|
+
# Do not output <tt><style></tt> tags included in the source text.
|
36
|
+
attr_accessor :filter_styles
|
37
|
+
|
38
|
+
# Do not output any raw HTML included in the source text.
|
39
|
+
attr_accessor :filter_html
|
40
|
+
|
41
|
+
# RedCloth compatible line folding -- not used for Markdown but
|
42
|
+
# included for compatibility.
|
43
|
+
attr_accessor :fold_lines
|
44
|
+
|
45
|
+
# Enable php markdown extra-style footnotes
|
46
|
+
attr_accessor :footnotes
|
47
|
+
|
48
|
+
# Enable Table Of Contents generation
|
49
|
+
attr_accessor :generate_toc
|
50
|
+
|
51
|
+
# Do not process <tt>![]</tt> and remove <tt><img></tt> tags from the output.
|
52
|
+
attr_accessor :no_image
|
53
|
+
|
54
|
+
# Do not process <tt>[]</tt> and remove <tt><a></tt> tags from the output.
|
55
|
+
attr_accessor :no_links
|
56
|
+
|
57
|
+
# Do not process tables
|
58
|
+
attr_accessor :no_tables
|
59
|
+
|
60
|
+
# Disable superscript and relaxed emphasis processing.
|
61
|
+
attr_accessor :strict
|
62
|
+
|
63
|
+
# Convert URL in links, even if they aren't encased in <tt><></tt>
|
64
|
+
attr_accessor :autolink
|
65
|
+
|
66
|
+
# Don't make hyperlinks from <tt>[][]</tt> links that have unknown URL types.
|
67
|
+
attr_accessor :safelink
|
68
|
+
|
69
|
+
# Do not process pseudo-protocols like <tt>[](id:name)</tt>
|
70
|
+
attr_accessor :no_pseudo_protocols
|
71
|
+
|
72
|
+
# Disable superscript processing.
|
73
|
+
attr_accessor :no_superscript
|
74
|
+
|
75
|
+
# Disable strikethrough processing.
|
76
|
+
attr_accessor :no_strikethrough
|
77
|
+
|
78
|
+
# Create a RDiscount Markdown processor. The +text+ argument
|
79
|
+
# should be a string containing Markdown text. Additional arguments may be
|
80
|
+
# supplied to set various processing options:
|
81
|
+
#
|
82
|
+
# * <tt>:smart</tt> - Enable SmartyPants processing.
|
83
|
+
# * <tt>:filter_styles</tt> - Do not output <tt><style></tt> tags.
|
84
|
+
# * <tt>:filter_html</tt> - Do not output any raw HTML tags included in
|
85
|
+
# the source text.
|
86
|
+
# * <tt>:fold_lines</tt> - RedCloth compatible line folding (not used).
|
87
|
+
# * <tt>:footnotes</tt> - PHP markdown extra-style footnotes.
|
88
|
+
# * <tt>:generate_toc</tt> - Enable Table Of Contents generation
|
89
|
+
# * <tt>:no_image</tt> - Do not output any <tt><img></tt> tags.
|
90
|
+
# * <tt>:no_links</tt> - Do not output any <tt><a></tt> tags.
|
91
|
+
# * <tt>:no_tables</tt> - Do not output any tables.
|
92
|
+
# * <tt>:strict</tt> - Disable superscript and relaxed emphasis processing.
|
93
|
+
# * <tt>:autolink</tt> - Greedily urlify links.
|
94
|
+
# * <tt>:safelink</tt> - Do not make links for unknown URL types.
|
95
|
+
# * <tt>:no_pseudo_protocols</tt> - Do not process pseudo-protocols.
|
96
|
+
# * <tt>:no_superscript</tt> - Disable superscript processing.
|
97
|
+
# * <tt>:no_strikethrough</tt> - Disable strikethrough processing.
|
98
|
+
#
|
99
|
+
def initialize(text, *extensions)
|
100
|
+
@text = text
|
101
|
+
extensions.each { |e| send("#{e}=", true) }
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
Markdown = RDiscount unless defined? Markdown
|
107
|
+
|
108
|
+
require 'rdiscount.so'
|