discount 1.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +52 -0
- data/README +17 -0
- data/Rakefile +126 -0
- data/ext/amalloc.h +29 -0
- data/ext/config.h +14 -0
- data/ext/cstring.h +68 -0
- data/ext/discount.c +48 -0
- data/ext/docheader.c +43 -0
- data/ext/dumptree.c +147 -0
- data/ext/extconf.rb +4 -0
- data/ext/generate.c +1319 -0
- data/ext/markdown.c +866 -0
- data/ext/markdown.h +125 -0
- data/ext/mkdio.c +223 -0
- data/ext/mkdio.h +58 -0
- data/ext/rbstrio.c +29 -0
- data/ext/rbstrio.h +5 -0
- data/ext/resource.c +167 -0
- data/lib/discount.rb +27 -0
- data/test.rb +76 -0
- data/test/MarkdownTest_1.0.3/MarkdownTest.pl +176 -0
- data/test/MarkdownTest_1.0.3/Tests/Amps and angle encoding.html +17 -0
- data/test/MarkdownTest_1.0.3/Tests/Amps and angle encoding.text +21 -0
- data/test/MarkdownTest_1.0.3/Tests/Auto links.html +18 -0
- data/test/MarkdownTest_1.0.3/Tests/Auto links.text +13 -0
- data/test/MarkdownTest_1.0.3/Tests/Backslash escapes.html +118 -0
- data/test/MarkdownTest_1.0.3/Tests/Backslash escapes.text +120 -0
- data/test/MarkdownTest_1.0.3/Tests/Blockquotes with code blocks.html +15 -0
- data/test/MarkdownTest_1.0.3/Tests/Blockquotes with code blocks.text +11 -0
- data/test/MarkdownTest_1.0.3/Tests/Code Blocks.html +18 -0
- data/test/MarkdownTest_1.0.3/Tests/Code Blocks.text +14 -0
- data/test/MarkdownTest_1.0.3/Tests/Code Spans.html +6 -0
- data/test/MarkdownTest_1.0.3/Tests/Code Spans.text +6 -0
- data/test/MarkdownTest_1.0.3/Tests/Hard-wrapped paragraphs with list-like lines.html +8 -0
- data/test/MarkdownTest_1.0.3/Tests/Hard-wrapped paragraphs with list-like lines.text +8 -0
- data/test/MarkdownTest_1.0.3/Tests/Horizontal rules.html +71 -0
- data/test/MarkdownTest_1.0.3/Tests/Horizontal rules.text +67 -0
- data/test/MarkdownTest_1.0.3/Tests/Inline HTML (Advanced).html +15 -0
- data/test/MarkdownTest_1.0.3/Tests/Inline HTML (Advanced).text +15 -0
- data/test/MarkdownTest_1.0.3/Tests/Inline HTML (Simple).html +72 -0
- data/test/MarkdownTest_1.0.3/Tests/Inline HTML (Simple).text +69 -0
- data/test/MarkdownTest_1.0.3/Tests/Inline HTML comments.html +13 -0
- data/test/MarkdownTest_1.0.3/Tests/Inline HTML comments.text +13 -0
- data/test/MarkdownTest_1.0.3/Tests/Links, inline style.html +11 -0
- data/test/MarkdownTest_1.0.3/Tests/Links, inline style.text +12 -0
- data/test/MarkdownTest_1.0.3/Tests/Links, reference style.html +52 -0
- data/test/MarkdownTest_1.0.3/Tests/Links, reference style.text +71 -0
- data/test/MarkdownTest_1.0.3/Tests/Links, shortcut references.html +9 -0
- data/test/MarkdownTest_1.0.3/Tests/Links, shortcut references.text +20 -0
- data/test/MarkdownTest_1.0.3/Tests/Literal quotes in titles.html +3 -0
- data/test/MarkdownTest_1.0.3/Tests/Literal quotes in titles.text +7 -0
- data/test/MarkdownTest_1.0.3/Tests/Markdown Documentation - Basics.html +314 -0
- data/test/MarkdownTest_1.0.3/Tests/Markdown Documentation - Basics.text +306 -0
- data/test/MarkdownTest_1.0.3/Tests/Markdown Documentation - Syntax.html +942 -0
- data/test/MarkdownTest_1.0.3/Tests/Markdown Documentation - Syntax.text +888 -0
- data/test/MarkdownTest_1.0.3/Tests/Nested blockquotes.html +9 -0
- data/test/MarkdownTest_1.0.3/Tests/Nested blockquotes.text +5 -0
- data/test/MarkdownTest_1.0.3/Tests/Ordered and unordered lists.html +148 -0
- data/test/MarkdownTest_1.0.3/Tests/Ordered and unordered lists.text +131 -0
- data/test/MarkdownTest_1.0.3/Tests/Strong and em together.html +7 -0
- data/test/MarkdownTest_1.0.3/Tests/Strong and em together.text +7 -0
- data/test/MarkdownTest_1.0.3/Tests/Tabs.html +25 -0
- data/test/MarkdownTest_1.0.3/Tests/Tabs.text +21 -0
- data/test/MarkdownTest_1.0.3/Tests/Tidyness.html +8 -0
- data/test/MarkdownTest_1.0.3/Tests/Tidyness.text +5 -0
- data/test/MarkdownTest_1.0/MarkdownTest.pl +157 -0
- data/test/MarkdownTest_1.0/Tests/Amps and angle encoding.html +17 -0
- data/test/MarkdownTest_1.0/Tests/Amps and angle encoding.text +21 -0
- data/test/MarkdownTest_1.0/Tests/Auto links.html +18 -0
- data/test/MarkdownTest_1.0/Tests/Auto links.text +13 -0
- data/test/MarkdownTest_1.0/Tests/Backslash escapes.html +102 -0
- data/test/MarkdownTest_1.0/Tests/Backslash escapes.text +104 -0
- data/test/MarkdownTest_1.0/Tests/Blockquotes with code blocks.html +15 -0
- data/test/MarkdownTest_1.0/Tests/Blockquotes with code blocks.text +11 -0
- data/test/MarkdownTest_1.0/Tests/Hard-wrapped paragraphs with list-like lines.html +8 -0
- data/test/MarkdownTest_1.0/Tests/Hard-wrapped paragraphs with list-like lines.text +8 -0
- data/test/MarkdownTest_1.0/Tests/Horizontal rules.html +71 -0
- data/test/MarkdownTest_1.0/Tests/Horizontal rules.text +67 -0
- data/test/MarkdownTest_1.0/Tests/Inline HTML (Advanced).html +14 -0
- data/test/MarkdownTest_1.0/Tests/Inline HTML (Advanced).text +14 -0
- data/test/MarkdownTest_1.0/Tests/Inline HTML (Simple).html +72 -0
- data/test/MarkdownTest_1.0/Tests/Inline HTML (Simple).text +69 -0
- data/test/MarkdownTest_1.0/Tests/Inline HTML comments.html +13 -0
- data/test/MarkdownTest_1.0/Tests/Inline HTML comments.text +13 -0
- data/test/MarkdownTest_1.0/Tests/Links, inline style.html +9 -0
- data/test/MarkdownTest_1.0/Tests/Links, inline style.text +9 -0
- data/test/MarkdownTest_1.0/Tests/Links, reference style.html +18 -0
- data/test/MarkdownTest_1.0/Tests/Links, reference style.text +31 -0
- data/test/MarkdownTest_1.0/Tests/Literal quotes in titles.html +3 -0
- data/test/MarkdownTest_1.0/Tests/Literal quotes in titles.text +7 -0
- data/test/MarkdownTest_1.0/Tests/Markdown Documentation - Basics.html +314 -0
- data/test/MarkdownTest_1.0/Tests/Markdown Documentation - Basics.text +306 -0
- data/test/MarkdownTest_1.0/Tests/Markdown Documentation - Syntax.html +942 -0
- data/test/MarkdownTest_1.0/Tests/Markdown Documentation - Syntax.text +888 -0
- data/test/MarkdownTest_1.0/Tests/Nested blockquotes.html +9 -0
- data/test/MarkdownTest_1.0/Tests/Nested blockquotes.text +5 -0
- data/test/MarkdownTest_1.0/Tests/Ordered and unordered lists.html +137 -0
- data/test/MarkdownTest_1.0/Tests/Ordered and unordered lists.text +122 -0
- data/test/MarkdownTest_1.0/Tests/Strong and em together.html +7 -0
- data/test/MarkdownTest_1.0/Tests/Strong and em together.text +7 -0
- data/test/MarkdownTest_1.0/Tests/Tabs.html +25 -0
- data/test/MarkdownTest_1.0/Tests/Tabs.text +21 -0
- data/test/MarkdownTest_1.0/Tests/Tidyness.html +8 -0
- data/test/MarkdownTest_1.0/Tests/Tidyness.text +5 -0
- metadata +160 -0
data/COPYING
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
The core Discount C sources are
|
2
|
+
Copyright (C) 2007 David Loren Parsons.
|
3
|
+
|
4
|
+
The Discount Ruby extension sources are
|
5
|
+
Copyright (C) 2008 Ryan Tomayko.
|
6
|
+
|
7
|
+
All rights reserved.
|
8
|
+
|
9
|
+
Permission is hereby granted, free of charge, to any person
|
10
|
+
obtaining a copy of this software and associated documentation files
|
11
|
+
(the "Software"), to deal in the Software without restriction,
|
12
|
+
including without limitation the rights to use, copy, modify, merge,
|
13
|
+
publish, distribute, sublicence, and/or sell copies of the Software,
|
14
|
+
and to permit persons to whom the Software is furnished to do so,
|
15
|
+
subject to the following conditions:
|
16
|
+
|
17
|
+
1. Redistributions of source code must retain the above copyright
|
18
|
+
notice, this list of conditions, and the following disclaimer.
|
19
|
+
|
20
|
+
2. Redistributions in binary form must reproduce the above
|
21
|
+
copyright notice, this list of conditions and the following
|
22
|
+
disclaimer in the documentation and/or other materials provided
|
23
|
+
with the distribution, and in the same place and form as other
|
24
|
+
copyright, license and disclaimer information.
|
25
|
+
|
26
|
+
3. The end-user documentation included with the redistribution, if
|
27
|
+
any, must include the following acknowledgment:
|
28
|
+
|
29
|
+
This product includes software developed by
|
30
|
+
David Loren Parsons <http://www.pell.portland.or.us/~orc>
|
31
|
+
|
32
|
+
in the same place and form as other third-party acknowledgments.
|
33
|
+
Alternately, this acknowledgment may appear in the software
|
34
|
+
itself, in the same form and location as other such third-party
|
35
|
+
acknowledgments.
|
36
|
+
|
37
|
+
4. Except as contained in this notice, the name of David Loren
|
38
|
+
Parsons shall not be used in advertising or otherwise to promote
|
39
|
+
the sale, use or other dealings in this Software without prior
|
40
|
+
written authorization from David Loren Parsons.
|
41
|
+
|
42
|
+
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
43
|
+
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
44
|
+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
45
|
+
IN NO EVENT SHALL DAVID LOREN PARSONS BE LIABLE FOR ANY DIRECT,
|
46
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
47
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
48
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
49
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
50
|
+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
51
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
52
|
+
OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Discount (For Ruby)
|
2
|
+
===================
|
3
|
+
|
4
|
+
Discount is a implementation of John Gruber's Markdown markup
|
5
|
+
language in C. It implements all of the language as described in
|
6
|
+
<http://daringfireball.net/projects/markdown/syntax>
|
7
|
+
and passes the Markdown test suite at
|
8
|
+
<http://daringfireball.net/projects/downloads/MarkdownTest_1.0.zip>
|
9
|
+
|
10
|
+
Discount was developed by
|
11
|
+
David Loren Parsons <http://www.pell.portland.or.us/~orc>. The Ruby
|
12
|
+
extension was developed by Ryan Tomayko <http://tomayko.com/>.
|
13
|
+
|
14
|
+
Discount is free software; it is released under a BSD-style license
|
15
|
+
that allows you to do as you wish with it as long as you don't attempt
|
16
|
+
to claim it as your own work. The Ruby Discount extension adopts
|
17
|
+
Discount's license verbatim. See the file COPYING for more information.
|
data/Rakefile
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'rake/clean'
|
2
|
+
require 'rake/packagetask'
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
|
5
|
+
task :default => 'test:unit'
|
6
|
+
|
7
|
+
DLEXT = Config::CONFIG['DLEXT']
|
8
|
+
VERS = '1.2.6'
|
9
|
+
|
10
|
+
spec =
|
11
|
+
Gem::Specification.new do |s|
|
12
|
+
s.name = "discount"
|
13
|
+
s.version = VERS
|
14
|
+
s.summary = "Discount Implementation of Gruber's Markdown"
|
15
|
+
s.files = FileList['README','COPYING','Rakefile','test/**/*','{lib,ext}/**.rb','ext/*.{c,h}']
|
16
|
+
s.bindir = 'bin'
|
17
|
+
s.require_path = 'lib'
|
18
|
+
s.has_rdoc = true
|
19
|
+
s.extra_rdoc_files = ['README', 'COPYING']
|
20
|
+
s.test_files = Dir['test.rb']
|
21
|
+
s.extensions = ['ext/extconf.rb']
|
22
|
+
|
23
|
+
s.author = 'Ryan Tomayko'
|
24
|
+
s.email = 'r@tomayko.com'
|
25
|
+
s.homepage = 'http://github.com/rtomayko/rdiscount'
|
26
|
+
s.rubyforge_project = 'wink'
|
27
|
+
end
|
28
|
+
|
29
|
+
Rake::GemPackageTask.new(spec) do |p|
|
30
|
+
p.gem_spec = spec
|
31
|
+
p.need_tar_gz = true
|
32
|
+
p.need_tar = false
|
33
|
+
p.need_zip = false
|
34
|
+
end
|
35
|
+
|
36
|
+
namespace :submodule do
|
37
|
+
desc 'Init the upstream submodule'
|
38
|
+
task :init do |t|
|
39
|
+
unless File.exist? 'discount/markdown.c'
|
40
|
+
rm_rf 'discount'
|
41
|
+
sh 'git submodule init discount'
|
42
|
+
sh 'git submodule update discount'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
desc 'Update the discount submodule'
|
47
|
+
task :update => :init do
|
48
|
+
sh 'git submodule update discount' unless File.symlink?('discount')
|
49
|
+
end
|
50
|
+
|
51
|
+
file 'discount/markdown.c' do
|
52
|
+
Rake::Task['submodule:init'].invoke
|
53
|
+
end
|
54
|
+
task :exist => 'discount/markdown.c'
|
55
|
+
end
|
56
|
+
|
57
|
+
desc 'Gather required discount sources into extension directory'
|
58
|
+
task :gather => 'submodule:exist' do |t|
|
59
|
+
files =
|
60
|
+
FileList[
|
61
|
+
'discount/{markdown,mkdio,amalloc,cstring}.h',
|
62
|
+
'discount/{markdown,docheader,dumptree,generate,mkdio,resource}.c'
|
63
|
+
]
|
64
|
+
cp files, 'ext/',
|
65
|
+
:preserve => true,
|
66
|
+
:verbose => true
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
file 'ext/Makefile' => FileList['ext/{*.c,*.h,*.rb}'] do
|
71
|
+
chdir('ext') { ruby 'extconf.rb' }
|
72
|
+
end
|
73
|
+
CLEAN.include 'ext/Makefile'
|
74
|
+
|
75
|
+
file "ext/discount.#{DLEXT}" => FileList['ext/Makefile', 'ext/*.{c,h,rb}'] do |f|
|
76
|
+
sh 'cd ext && make'
|
77
|
+
end
|
78
|
+
CLEAN.include 'ext/*.{o,bundle,so,dll}'
|
79
|
+
|
80
|
+
file "lib/discount.#{DLEXT}" => "ext/discount.#{DLEXT}" do |f|
|
81
|
+
cp f.prerequisites, "lib/", :preserve => true
|
82
|
+
end
|
83
|
+
|
84
|
+
desc 'Build the discount extension'
|
85
|
+
task :build => "lib/discount.#{DLEXT}"
|
86
|
+
|
87
|
+
desc 'Run unit tests'
|
88
|
+
task 'test:unit' => [:build] do |t|
|
89
|
+
ruby 'test.rb'
|
90
|
+
end
|
91
|
+
|
92
|
+
desc 'Run conformance tests (MARKDOWN_TEST_VER=1.0)'
|
93
|
+
task 'test:conformance' => [:build] do |t|
|
94
|
+
script = "#{pwd}/bin/rdiscount"
|
95
|
+
test_version = ENV['MARKDOWN_TEST_VER'] || '1.0'
|
96
|
+
chdir("test/MarkdownTest_#{test_version}") do
|
97
|
+
sh "./MarkdownTest.pl --script='#{script}' --tidy"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
desc 'Run version 1.0 conformance suite'
|
102
|
+
task 'test:conformance:1.0' => 'test:conformance'
|
103
|
+
|
104
|
+
desc 'Run 1.0.3 conformance suite'
|
105
|
+
task 'test:conformance:1.0.3' => [:build] do |t|
|
106
|
+
ENV['MARKDOWN_TEST_VER'] = '1.0.3'
|
107
|
+
Rake::Task['test:conformance'].invoke
|
108
|
+
end
|
109
|
+
|
110
|
+
desc 'Run unit and conformance tests'
|
111
|
+
task :test => %w[test:unit test:conformance]
|
112
|
+
|
113
|
+
|
114
|
+
# ==========================================================
|
115
|
+
# Rubyforge
|
116
|
+
# ==========================================================
|
117
|
+
|
118
|
+
PKGNAME = "pkg/discount-#{VERS}"
|
119
|
+
|
120
|
+
desc 'Publish new release to rubyforge'
|
121
|
+
task :release => [ "#{PKGNAME}.gem", "#{PKGNAME}.tar.gz" ] do |t|
|
122
|
+
sh <<-end
|
123
|
+
rubyforge add_release wink discount #{VERS} #{PKGNAME}.gem &&
|
124
|
+
rubyforge add_file wink discount #{VERS} #{PKGNAME}.tar.gz
|
125
|
+
end
|
126
|
+
end
|
data/ext/amalloc.h
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
/*
|
2
|
+
* debugging malloc()/realloc()/calloc()/free() that attempts
|
3
|
+
* to keep track of just what's been allocated today.
|
4
|
+
*/
|
5
|
+
#ifndef AMALLOC_D
|
6
|
+
#define AMALLOC_D
|
7
|
+
|
8
|
+
#include "config.h"
|
9
|
+
|
10
|
+
#ifdef USE_AMALLOC
|
11
|
+
|
12
|
+
extern void *amalloc(int);
|
13
|
+
extern void *acalloc(int,int);
|
14
|
+
extern void *arealloc(void*,int);
|
15
|
+
extern void afree(void*);
|
16
|
+
extern void adump();
|
17
|
+
|
18
|
+
#define malloc amalloc
|
19
|
+
#define calloc acalloc
|
20
|
+
#define realloc arealloc
|
21
|
+
#define free afree
|
22
|
+
|
23
|
+
#else
|
24
|
+
|
25
|
+
#define adump() (void)1
|
26
|
+
|
27
|
+
#endif
|
28
|
+
|
29
|
+
#endif/*AMALLOC_D*/
|
data/ext/config.h
ADDED
data/ext/cstring.h
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
/* two template types: STRING(t) which defines a pascal-style string
|
2
|
+
* of element (t) [STRING(char) is the closest to the pascal string],
|
3
|
+
* and ANCHOR(t) which defines a baseplate that a linked list can be
|
4
|
+
* built up from. [The linked list /must/ contain a ->next pointer
|
5
|
+
* for linking the list together with.]
|
6
|
+
*/
|
7
|
+
#ifndef _CSTRING_D
|
8
|
+
#define _CSTRING_D
|
9
|
+
|
10
|
+
#include <string.h>
|
11
|
+
#include <stdlib.h>
|
12
|
+
|
13
|
+
#include "amalloc.h"
|
14
|
+
|
15
|
+
/* expandable Pascal-style string.
|
16
|
+
*/
|
17
|
+
#define STRING(type) struct { type *text; int size, alloc; }
|
18
|
+
|
19
|
+
#define CREATE(x) T(x) = (void*)(S(x) = (x).alloc = 0)
|
20
|
+
#define EXPAND(x) (S(x)++)[(S(x) < (x).alloc) \
|
21
|
+
? (T(x)) \
|
22
|
+
: (T(x) = T(x) ? realloc(T(x), sizeof T(x)[0] * ((x).alloc += 100)) \
|
23
|
+
: malloc(sizeof T(x)[0] * ((x).alloc += 100)) )]
|
24
|
+
|
25
|
+
#define DELETE(x) (x).alloc ? (free(T(x)), S(x) = (x).alloc = 0) \
|
26
|
+
: ( S(x) = 0 )
|
27
|
+
#define CLIP(t,i,sz) \
|
28
|
+
( ((i) >= 0) && ((sz) > 0) && (((i)+(sz)) <= S(t)) ) ? \
|
29
|
+
(memmove(&T(t)[i], &T(t)[i+sz], (S(t)-(i+sz)+1)*sizeof(T(t)[0])), \
|
30
|
+
S(t) -= (sz)) : -1
|
31
|
+
|
32
|
+
#define RESERVE(x, sz) T(x) = ((x).alloc > S(x) + (sz) \
|
33
|
+
? T(x) \
|
34
|
+
: T(x) \
|
35
|
+
? realloc(T(x), sizeof T(x)[0] * ((x).alloc = 100+(sz)+S(x))) \
|
36
|
+
: malloc(sizeof T(x)[0] * ((x).alloc = 100+(sz)+S(x))))
|
37
|
+
#define SUFFIX(t,p,sz) \
|
38
|
+
memcpy(((S(t) += (sz)) - (sz)) + \
|
39
|
+
(T(t) = T(t) ? realloc(T(t), sizeof T(t)[0] * ((t).alloc += sz)) \
|
40
|
+
: malloc(sizeof T(t)[0] * ((t).alloc += sz))), \
|
41
|
+
(p), sizeof(T(t)[0])*(sz))
|
42
|
+
|
43
|
+
#define PREFIX(t,p,sz) \
|
44
|
+
RESERVE( (t), (sz) ); \
|
45
|
+
if ( S(t) ) { memmove(T(t)+(sz), T(t), S(t)); } \
|
46
|
+
memcpy( T(t), (p), (sz) ); \
|
47
|
+
S(t) += (sz)
|
48
|
+
|
49
|
+
/* reference-style links (and images) are stored in an array
|
50
|
+
*/
|
51
|
+
#define T(x) (x).text
|
52
|
+
#define S(x) (x).size
|
53
|
+
|
54
|
+
/* abstract anchor type that defines a list base
|
55
|
+
* with a function that attaches an element to
|
56
|
+
* the end of the list.
|
57
|
+
*
|
58
|
+
* the list base field is named .text so that the T()
|
59
|
+
* macro will work with it.
|
60
|
+
*/
|
61
|
+
#define ANCHOR(t) struct { t *text, *end; }
|
62
|
+
|
63
|
+
#define ATTACH(t, p) ( (t).text ?( ((t).end->next = (p)), ((t).end = (p)) ) \
|
64
|
+
:( ((t).text = (t).end = (p)) ) )
|
65
|
+
|
66
|
+
typedef STRING(char) Cstring;
|
67
|
+
|
68
|
+
#endif/*_CSTRING_D*/
|
data/ext/discount.c
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#include <stdio.h>
|
2
|
+
#include "ruby.h"
|
3
|
+
#include "mkdio.h"
|
4
|
+
#include "rbstrio.h"
|
5
|
+
|
6
|
+
static VALUE rb_cDiscount;
|
7
|
+
|
8
|
+
static ID id_text;
|
9
|
+
static ID id_smart;
|
10
|
+
static ID id_notes;
|
11
|
+
|
12
|
+
|
13
|
+
static VALUE
|
14
|
+
rb_discount_to_html(int argc, VALUE *argv, VALUE self)
|
15
|
+
{
|
16
|
+
/* grab char pointer to markdown input text */
|
17
|
+
VALUE text = rb_funcall(self, id_text, 0);
|
18
|
+
Check_Type(text, T_STRING);
|
19
|
+
|
20
|
+
/* allocate a ruby string buffer and wrap it in a stream */
|
21
|
+
VALUE buf = rb_str_buf_new(4096);
|
22
|
+
FILE *stream = rb_str_io_new(buf);
|
23
|
+
|
24
|
+
/* compile flags */
|
25
|
+
int flags = MKD_TABSTOP | MKD_NOHEADER;
|
26
|
+
if (rb_funcall(self, id_smart, 0) != Qtrue )
|
27
|
+
flags = flags | MKD_NOPANTS;
|
28
|
+
|
29
|
+
MMIOT *doc = mkd_string(RSTRING(text)->ptr, RSTRING(text)->len, flags);
|
30
|
+
markdown(doc, stream, flags);
|
31
|
+
|
32
|
+
fclose(stream);
|
33
|
+
|
34
|
+
return buf;
|
35
|
+
}
|
36
|
+
|
37
|
+
void Init_discount()
|
38
|
+
{
|
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
|
+
rb_cDiscount = rb_define_class("Discount", rb_cObject);
|
45
|
+
rb_define_method(rb_cDiscount, "to_html", rb_discount_to_html, -1);
|
46
|
+
}
|
47
|
+
|
48
|
+
// vim: ts=4 sw=4
|
data/ext/docheader.c
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
/*
|
2
|
+
* docheader -- get values from the document header
|
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
|
+
#define afterdle(t) (T((t)->text) + (t)->dle)
|
18
|
+
|
19
|
+
char *
|
20
|
+
mkd_doc_title(Document *doc)
|
21
|
+
{
|
22
|
+
if ( doc && doc->headers )
|
23
|
+
return afterdle(doc->headers);
|
24
|
+
return 0;
|
25
|
+
}
|
26
|
+
|
27
|
+
|
28
|
+
char *
|
29
|
+
mkd_doc_author(Document *doc)
|
30
|
+
{
|
31
|
+
if ( doc && doc->headers && doc->headers->next )
|
32
|
+
return afterdle(doc->headers->next);
|
33
|
+
return 0;
|
34
|
+
}
|
35
|
+
|
36
|
+
|
37
|
+
char *
|
38
|
+
mkd_doc_date(Document *doc)
|
39
|
+
{
|
40
|
+
if ( doc && doc->headers && doc->headers->next && doc->headers->next->next )
|
41
|
+
return afterdle(doc->headers->next->next);
|
42
|
+
return 0;
|
43
|
+
}
|
data/ext/dumptree.c
ADDED
@@ -0,0 +1,147 @@
|
|
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 "markdown.h"
|
9
|
+
#include "cstring.h"
|
10
|
+
#include "amalloc.h"
|
11
|
+
|
12
|
+
struct frame {
|
13
|
+
int indent;
|
14
|
+
char c;
|
15
|
+
};
|
16
|
+
|
17
|
+
typedef STRING(struct frame) Stack;
|
18
|
+
|
19
|
+
static char *
|
20
|
+
Pptype(int typ)
|
21
|
+
{
|
22
|
+
switch (typ) {
|
23
|
+
case WHITESPACE: return "whitespace";
|
24
|
+
case CODE : return "code";
|
25
|
+
case QUOTE : return "quote";
|
26
|
+
case MARKUP : return "markup";
|
27
|
+
case HTML : return "html";
|
28
|
+
case DL : return "dl";
|
29
|
+
case UL : return "ul";
|
30
|
+
case OL : return "ol";
|
31
|
+
case LISTITEM : return "item";
|
32
|
+
case HDR : return "header";
|
33
|
+
case HR : return "HR";
|
34
|
+
default : return "mystery node!";
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
static void
|
39
|
+
pushpfx(int indent, char c, Stack *sp)
|
40
|
+
{
|
41
|
+
struct frame *q = &EXPAND(*sp);
|
42
|
+
|
43
|
+
q->indent = indent;
|
44
|
+
q->c = c;
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
static void
|
49
|
+
poppfx(Stack *sp)
|
50
|
+
{
|
51
|
+
S(*sp)--;
|
52
|
+
}
|
53
|
+
|
54
|
+
|
55
|
+
static void
|
56
|
+
changepfx(Stack *sp, char c)
|
57
|
+
{
|
58
|
+
char ch;
|
59
|
+
|
60
|
+
if ( !S(*sp) ) return;
|
61
|
+
|
62
|
+
ch = T(*sp)[S(*sp)-1].c;
|
63
|
+
|
64
|
+
if ( ch == '+' || ch == '|' )
|
65
|
+
T(*sp)[S(*sp)-1].c = c;
|
66
|
+
}
|
67
|
+
|
68
|
+
|
69
|
+
static void
|
70
|
+
printpfx(Stack *sp, FILE *f)
|
71
|
+
{
|
72
|
+
int i;
|
73
|
+
char c;
|
74
|
+
|
75
|
+
if ( !S(*sp) ) return;
|
76
|
+
|
77
|
+
c = T(*sp)[S(*sp)-1].c;
|
78
|
+
|
79
|
+
if ( c == '+' || c == '-' ) {
|
80
|
+
fprintf(f, "--%c", c);
|
81
|
+
T(*sp)[S(*sp)-1].c = (c == '-') ? ' ' : '|';
|
82
|
+
}
|
83
|
+
else
|
84
|
+
for ( i=0; i < S(*sp); i++ ) {
|
85
|
+
if ( i )
|
86
|
+
fprintf(f, " ");
|
87
|
+
fprintf(f, "%*s%c", T(*sp)[i].indent + 2, " ", T(*sp)[i].c);
|
88
|
+
if ( T(*sp)[i].c == '`' )
|
89
|
+
T(*sp)[i].c = ' ';
|
90
|
+
}
|
91
|
+
fprintf(f, "--");
|
92
|
+
}
|
93
|
+
|
94
|
+
|
95
|
+
static void
|
96
|
+
dumptree(Paragraph *pp, Stack *sp, FILE *f)
|
97
|
+
{
|
98
|
+
int count;
|
99
|
+
Line *p;
|
100
|
+
int d;
|
101
|
+
static char *Begin[] = { 0, "P", "center" };
|
102
|
+
|
103
|
+
while ( pp ) {
|
104
|
+
if ( !pp->next )
|
105
|
+
changepfx(sp, '`');
|
106
|
+
printpfx(sp, f);
|
107
|
+
|
108
|
+
d = fprintf(f, "[%s", Pptype(pp->typ));
|
109
|
+
if ( pp->align )
|
110
|
+
d += fprintf(f, ", <%s>", Begin[pp->align]);
|
111
|
+
|
112
|
+
for (count=0, p=pp->text; p; ++count, (p = p->next) )
|
113
|
+
;
|
114
|
+
|
115
|
+
if ( count )
|
116
|
+
d += fprintf(f, ", %d line%s", count, (count==1)?"":"s");
|
117
|
+
|
118
|
+
d += fprintf(f, "]");
|
119
|
+
|
120
|
+
if ( pp->down ) {
|
121
|
+
pushpfx(d, pp->down->next ? '+' : '-', sp);
|
122
|
+
dumptree(pp->down, sp, f);
|
123
|
+
poppfx(sp);
|
124
|
+
}
|
125
|
+
else fputc('\n', f);
|
126
|
+
pp = pp->next;
|
127
|
+
}
|
128
|
+
}
|
129
|
+
|
130
|
+
|
131
|
+
int
|
132
|
+
mkd_dump(Document *doc, FILE *out, int flags, char *title)
|
133
|
+
{
|
134
|
+
Stack stack;
|
135
|
+
|
136
|
+
if (mkd_compile(doc, flags) ) {
|
137
|
+
|
138
|
+
CREATE(stack);
|
139
|
+
pushpfx(fprintf(out, "%s", title), doc->code->next ? '+' : '-', &stack);
|
140
|
+
dumptree(doc->code, &stack, out);
|
141
|
+
DELETE(stack);
|
142
|
+
|
143
|
+
mkd_cleanup(doc);
|
144
|
+
return 0;
|
145
|
+
}
|
146
|
+
return -1;
|
147
|
+
}
|