rdiscount 1.2.7.1 → 1.2.9
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.
- data/Rakefile +20 -24
- data/ext/config.h +1 -0
- data/ext/generate.c +16 -17
- data/ext/markdown.c +4 -1
- data/ext/markdown.h +1 -0
- data/ext/mkdio.c +3 -1
- data/ext/mkdio.h +1 -0
- data/ext/rdiscount.c +8 -12
- data/lib/rdiscount.rb +6 -4
- data/test/markdown_test.rb +5 -0
- metadata +2 -2
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ require 'rake/gempackagetask'
|
|
5
5
|
task :default => 'test:unit'
|
6
6
|
|
7
7
|
DLEXT = Config::CONFIG['DLEXT']
|
8
|
-
VERS = '1.2.
|
8
|
+
VERS = '1.2.9'
|
9
9
|
|
10
10
|
spec =
|
11
11
|
Gem::Specification.new do |s|
|
@@ -135,32 +135,11 @@ task :publish => :doc do |t|
|
|
135
135
|
end
|
136
136
|
|
137
137
|
# ==========================================================
|
138
|
-
# Discount
|
138
|
+
# Update package's Discount sources
|
139
139
|
# ==========================================================
|
140
140
|
|
141
|
-
namespace :submodule do
|
142
|
-
desc 'Init the upstream submodule'
|
143
|
-
task :init do |t|
|
144
|
-
unless File.exist? 'discount/markdown.c'
|
145
|
-
rm_rf 'discount'
|
146
|
-
sh 'git submodule init discount'
|
147
|
-
sh 'git submodule update discount'
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
desc 'Update the discount submodule'
|
152
|
-
task :update => :init do
|
153
|
-
sh 'git submodule update discount' unless File.symlink?('discount')
|
154
|
-
end
|
155
|
-
|
156
|
-
file 'discount/markdown.c' do
|
157
|
-
Rake::Task['submodule:init'].invoke
|
158
|
-
end
|
159
|
-
task :exist => 'discount/markdown.c'
|
160
|
-
end
|
161
|
-
|
162
141
|
desc 'Gather required discount sources into extension directory'
|
163
|
-
task :gather => '
|
142
|
+
task :gather => 'discount' do |t|
|
164
143
|
files =
|
165
144
|
FileList[
|
166
145
|
'discount/{markdown,mkdio,amalloc,cstring}.h',
|
@@ -171,3 +150,20 @@ task :gather => 'submodule:exist' do |t|
|
|
171
150
|
:verbose => true
|
172
151
|
end
|
173
152
|
|
153
|
+
# best. task. ever.
|
154
|
+
file 'discount' do |f|
|
155
|
+
STDERR.puts((<<-TEXT).gsub(/^ +/, ''))
|
156
|
+
Sorry, this operation requires a human. Tell your human to:
|
157
|
+
|
158
|
+
Grab a discount tarball from:
|
159
|
+
http://www.pell.portland.or.us/~orc/Code/discount/
|
160
|
+
|
161
|
+
Extract here with something like:
|
162
|
+
tar xvzf discount-1.2.9.tar.gz
|
163
|
+
|
164
|
+
Create a discount symlink pointing at the version directory:
|
165
|
+
ln -hsf discount-1.2.9 discount
|
166
|
+
|
167
|
+
TEXT
|
168
|
+
fail "discount sources required."
|
169
|
+
end
|
data/ext/config.h
CHANGED
data/ext/generate.c
CHANGED
@@ -642,11 +642,11 @@ cputc(int c, MMIOT *f)
|
|
642
642
|
* convert an email address to a string of nonsense
|
643
643
|
*/
|
644
644
|
static void
|
645
|
-
mangle(
|
645
|
+
mangle(char *s, int len, MMIOT *f)
|
646
646
|
{
|
647
647
|
while ( len-- > 0 ) {
|
648
648
|
Qstring("&#", f);
|
649
|
-
Qprintf(f, COINTOSS() ? "x%02x;" : "%02d;", *s++);
|
649
|
+
Qprintf(f, COINTOSS() ? "x%02x;" : "%02d;", *((unsigned char*)(s++)) );
|
650
650
|
}
|
651
651
|
}
|
652
652
|
|
@@ -659,6 +659,9 @@ forbidden_tag(MMIOT *f)
|
|
659
659
|
{
|
660
660
|
int c = toupper(peek(f, 1));
|
661
661
|
|
662
|
+
if ( f->flags & DENY_HTML )
|
663
|
+
return 1;
|
664
|
+
|
662
665
|
if ( c == 'A' && (f->flags & DENY_A) && !isalnum(peek(f,2)) )
|
663
666
|
return 1;
|
664
667
|
if ( c == 'I' && (f->flags & DENY_IMG)
|
@@ -941,29 +944,25 @@ text(MMIOT *f)
|
|
941
944
|
}
|
942
945
|
break;
|
943
946
|
#endif
|
944
|
-
case '
|
945
|
-
case '_': if ( tag_text(f) || (isthisspace(f,-1) && isthisspace(f,1)) || (isalnum(peek(f,-1)) && isalnum(peek(f,1))) )
|
946
|
-
Qchar(c, f);
|
947
|
+
case '_':
|
947
948
|
#if RELAXED_EMPHASIS
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
}
|
954
|
-
else if ( (isthisspace(f,-1) && isthisspace(f,1))
|
955
|
-
|| (isalnum(peek(f,-1)) && isalnum(peek(f,1))) )
|
949
|
+
/* If RELAXED_EMPHASIS, underscores don't count when
|
950
|
+
* they're in the middle of a word.
|
951
|
+
*/
|
952
|
+
if ( (isthisspace(f,-1) && isthisspace(f,1))
|
953
|
+
|| (isalnum(peek(f,-1)) && isalnum(peek(f,1))) ) {
|
956
954
|
Qchar(c, f);
|
957
|
-
|
958
|
-
Qem(f, c, 1);
|
955
|
+
break;
|
959
956
|
}
|
960
|
-
|
957
|
+
/* else fall into the regular old emphasis case */
|
958
|
+
#endif
|
959
|
+
case '*': if ( tag_text(f) )
|
960
|
+
Qchar(c, f);
|
961
961
|
else {
|
962
962
|
for (rep = 1; peek(f,1) == c; pull(f) )
|
963
963
|
++rep;
|
964
964
|
Qem(f,c,rep);
|
965
965
|
}
|
966
|
-
#endif
|
967
966
|
break;
|
968
967
|
|
969
968
|
case '`': if ( tag_text(f) )
|
data/ext/markdown.c
CHANGED
@@ -411,6 +411,9 @@ headerblock(Paragraph *pp, int htyp)
|
|
411
411
|
|
412
412
|
pp->hnumber = i;
|
413
413
|
|
414
|
+
while ( (i < S(p->text)) && isspace(T(p->text)[i]) )
|
415
|
+
++i;
|
416
|
+
|
414
417
|
CLIP(p->text, 0, i);
|
415
418
|
|
416
419
|
for (j=S(p->text); j && (T(p->text)[j-1] == '#'); --j)
|
@@ -762,7 +765,7 @@ compile(Line *ptr, int toplevel, MMIOT *f)
|
|
762
765
|
ptr = consume(ptr, ¶);
|
763
766
|
|
764
767
|
while ( ptr ) {
|
765
|
-
if ( toplevel && (key = isopentag(ptr)) ) {
|
768
|
+
if ( toplevel && !(f->flags & DENY_HTML) && (key = isopentag(ptr)) ) {
|
766
769
|
p = Pp(&d, ptr, strcmp(key, "STYLE") == 0 ? STYLE : HTML);
|
767
770
|
if ( strcmp(key, "!--") == 0 )
|
768
771
|
ptr = comment(p, key);
|
data/ext/markdown.h
CHANGED
data/ext/mkdio.c
CHANGED
@@ -41,7 +41,7 @@ queue(Document* a, Cstring *line)
|
|
41
41
|
unsigned char c;
|
42
42
|
int xp = 0;
|
43
43
|
int size = S(*line);
|
44
|
-
unsigned char *str = T(*line);
|
44
|
+
unsigned char *str = (unsigned char*)T(*line);
|
45
45
|
|
46
46
|
CREATE(p->text);
|
47
47
|
ATTACH(a->content, p);
|
@@ -68,6 +68,7 @@ queue(Document* a, Cstring *line)
|
|
68
68
|
}
|
69
69
|
|
70
70
|
|
71
|
+
#ifdef PANDOC_HEADER
|
71
72
|
/* trim leading blanks from a header line
|
72
73
|
*/
|
73
74
|
static void
|
@@ -76,6 +77,7 @@ snip(Line *p)
|
|
76
77
|
CLIP(p->text, 0, 1);
|
77
78
|
p->dle = mkd_firstnonblank(p);
|
78
79
|
}
|
80
|
+
#endif
|
79
81
|
|
80
82
|
|
81
83
|
/* build a Document from any old input.
|
data/ext/mkdio.h
CHANGED
@@ -45,6 +45,7 @@ extern char markdown_version[];
|
|
45
45
|
#define MKD_NOLINKS 0x0001 /* don't do link processing, block <a> tags */
|
46
46
|
#define MKD_NOIMAGE 0x0002 /* don't do image processing, block <img> */
|
47
47
|
#define MKD_NOPANTS 0x0004 /* don't run smartypants() */
|
48
|
+
#define MKD_NOHTML 0x0008 /* don't allow raw html through AT ALL */
|
48
49
|
#define MKD_TAGTEXT 0x0020 /* don't expand `_` and `*` */
|
49
50
|
#define MKD_NO_EXT 0x0040 /* don't allow pseudo-protocols */
|
50
51
|
#define MKD_CDATA 0x0080 /* generate code for xml ![CDATA[...]] */
|
data/ext/rdiscount.c
CHANGED
@@ -5,16 +5,11 @@
|
|
5
5
|
|
6
6
|
static VALUE rb_cRDiscount;
|
7
7
|
|
8
|
-
static ID id_text;
|
9
|
-
static ID id_smart;
|
10
|
-
static ID id_notes;
|
11
|
-
|
12
|
-
|
13
8
|
static VALUE
|
14
9
|
rb_rdiscount_to_html(int argc, VALUE *argv, VALUE self)
|
15
10
|
{
|
16
11
|
/* grab char pointer to markdown input text */
|
17
|
-
VALUE text = rb_funcall(self,
|
12
|
+
VALUE text = rb_funcall(self, rb_intern("text"), 0);
|
18
13
|
Check_Type(text, T_STRING);
|
19
14
|
|
20
15
|
/* allocate a ruby string buffer and wrap it in a stream */
|
@@ -23,9 +18,15 @@ rb_rdiscount_to_html(int argc, VALUE *argv, VALUE self)
|
|
23
18
|
|
24
19
|
/* compile flags */
|
25
20
|
int flags = MKD_TABSTOP | MKD_NOHEADER;
|
26
|
-
|
21
|
+
|
22
|
+
/* smart */
|
23
|
+
if ( rb_funcall(self, rb_intern("smart"), 0) != Qtrue )
|
27
24
|
flags = flags | MKD_NOPANTS;
|
28
25
|
|
26
|
+
/* filter_html */
|
27
|
+
if ( rb_funcall(self, rb_intern("filter_html"), 0) == Qtrue )
|
28
|
+
flags = flags | MKD_NOHTML;
|
29
|
+
|
29
30
|
MMIOT *doc = mkd_string(RSTRING(text)->ptr, RSTRING(text)->len, flags);
|
30
31
|
markdown(doc, stream, flags);
|
31
32
|
|
@@ -36,11 +37,6 @@ rb_rdiscount_to_html(int argc, VALUE *argv, VALUE self)
|
|
36
37
|
|
37
38
|
void Init_rdiscount()
|
38
39
|
{
|
39
|
-
/* Initialize frequently used Symbols */
|
40
|
-
id_text = rb_intern("text");
|
41
|
-
id_smart = rb_intern("smart");
|
42
|
-
id_notes = rb_intern("notes");
|
43
|
-
|
44
40
|
rb_cRDiscount = rb_define_class("RDiscount", rb_cObject);
|
45
41
|
rb_define_method(rb_cRDiscount, "to_html", rb_rdiscount_to_html, -1);
|
46
42
|
}
|
data/lib/rdiscount.rb
CHANGED
@@ -31,8 +31,11 @@ class RDiscount
|
|
31
31
|
# Set true to have smarty-like quote translation performed.
|
32
32
|
attr_accessor :smart
|
33
33
|
|
34
|
-
#
|
35
|
-
attr_accessor :filter_styles
|
34
|
+
# Do not output <style> tags included in the source text.
|
35
|
+
attr_accessor :filter_styles
|
36
|
+
|
37
|
+
# Do not output any raw HTML included in the source text.
|
38
|
+
attr_accessor :filter_html
|
36
39
|
|
37
40
|
# RedCloth compatible line folding -- not used for Markdown but
|
38
41
|
# included for compatibility.
|
@@ -48,8 +51,7 @@ class RDiscount
|
|
48
51
|
# the source text.
|
49
52
|
# * <tt>:fold_lines</tt> - RedCloth compatible line folding (not used).
|
50
53
|
#
|
51
|
-
# NOTE: The <tt>:filter_styles</tt>
|
52
|
-
# are not yet implemented.
|
54
|
+
# NOTE: The <tt>:filter_styles</tt> extension is not yet implemented.
|
53
55
|
def initialize(text, *extensions)
|
54
56
|
@text = text
|
55
57
|
@smart = nil
|
data/test/markdown_test.rb
CHANGED
@@ -30,6 +30,11 @@ class MarkdownTest < Test::Unit::TestCase
|
|
30
30
|
assert_equal "<p><em>start _ foo_bar bar_baz _ end</em> <em>italic</em> <strong>bold</strong> <a><em>blah</em></a></p>", markdown.to_html.strip
|
31
31
|
end
|
32
32
|
|
33
|
+
def test_that_filter_html_works
|
34
|
+
markdown = Markdown.new('Through <em>NO</em> <script>DOUBLE NO</script>', :filter_html)
|
35
|
+
assert_equal "<p>Through <em>NO</em> <script>DOUBLE NO</script></p>", markdown.to_html.strip
|
36
|
+
end
|
37
|
+
|
33
38
|
def test_that_bluecloth_restrictions_are_supported
|
34
39
|
markdown = Markdown.new('Hello World.')
|
35
40
|
[:filter_html, :filter_styles].each do |restriction|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdiscount
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Tomayko
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-08-
|
12
|
+
date: 2008-08-26 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|