moredown 1.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.
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.
@@ -0,0 +1,109 @@
1
+ Discount Markdown Processor for Ruby (with some extras)
2
+ =======================================================
3
+
4
+ Discount is an implementation of John Gruber's Markdown markup language in C. It
5
+ implements all of the language described in [the markdown syntax document][1] and
6
+ passes the [Markdown 1.0 test suite][2].
7
+
8
+ Discount was developed by [David Loren Parsons][3]. The Ruby extension was
9
+ developed by [Ryan Tomayko][4] and extended by [Nathan Hoad][5].
10
+
11
+ [1]: http://daringfireball.net/projects/markdown/syntax
12
+ [2]: http://daringfireball.net/projects/downloads/MarkdownTest_1.0.zip
13
+ [3]: http://www.pell.portland.or.us/~orc
14
+ [4]: http://tomayko.com/
15
+ [5]: http://nathanhoad.net/
16
+
17
+ Installation, Hacking
18
+ ---------------------
19
+
20
+ The Moredown gem can be installed from Github:
21
+
22
+ $ gem sources -a http://gems.github.com
23
+ $ [sudo] gem install nathanhoad-moredown
24
+
25
+ The Moredown sources are available via Git:
26
+
27
+ $ git clone git://github.com/nathanhoad/moredown.git
28
+ $ cd moredown
29
+ $ rake --tasks
30
+
31
+ For more information, see [the project page](http://github.com/nathanhoad/moredown).
32
+
33
+ Usage
34
+ -----
35
+
36
+ Moredown can be used in any way that RDiscount can be (see below). In addition, Moredown
37
+ implements some extras:
38
+
39
+ * Static method for simple calls
40
+
41
+ require 'nathanhoad-moredown'
42
+ html = Moredown.text_to_html("Hello World!")
43
+
44
+ * Remap relative URLs
45
+
46
+ Moredown.new(text, :base_url => 'http://nathanhoad.net').to_html
47
+
48
+ * Remap headings (eg. h1 becomes h3).
49
+
50
+ Moredown.new(text, :map_headings => 2)
51
+
52
+ * Embed Youtube videos (similar to image syntax except the title text is used for width and height)
53
+
54
+ ![Video](youtube:lfAzVe5H-vE)
55
+ ![Blah](youtube:lfAzVe5H-vE "400 300")
56
+
57
+ * Use Flash movies (include the width and height if you want)
58
+
59
+ ![Flash](flash:movieclip.swf)
60
+ ![Something](flash:something.swf "200 100")
61
+
62
+ * Use SwfObject (javascript not included) for graceful Flash degradation
63
+
64
+ Moredown.new(text, :swfobject => { :src => 'swfobject.js', :version => '10', :fallback => 'No Flash' })
65
+
66
+ * Image alignments (extension to image syntax)
67
+
68
+ ![Image](/images/test.jpg):left
69
+ ![Image](/images/test.jpg):right
70
+ ![Image](/images/test.jpg):center
71
+
72
+ * Emoticons
73
+
74
+ :-)
75
+ :-P
76
+ :-D
77
+ :-(
78
+ :-@
79
+ ;-)
80
+
81
+ * RDiscount extensions are now passed under `:extensions`
82
+
83
+ Moredown.new(text, :extensions => [:smart])
84
+
85
+ RDiscount implements the basic protocol popularized by RedCloth and adopted
86
+ by BlueCloth:
87
+
88
+ require 'nathanhoad-moredown'
89
+ markdown = Moredown.new("Hello World!")
90
+ puts markdown.to_html
91
+
92
+ Inject Moredown into your BlueCloth-using code by replacing your bluecloth
93
+ require statements with the following:
94
+
95
+ begin
96
+ require 'nathanhoad-moredown'
97
+ BlueCloth = Moredown
98
+ rescue LoadError
99
+ require 'bluecloth'
100
+ end
101
+
102
+
103
+ COPYING
104
+ -------
105
+
106
+ Discount is free software; it is released under a BSD-style license
107
+ that allows you to do as you wish with it as long as you don't attempt
108
+ to claim it as your own work. RDiscount adopts Discount's license
109
+ verbatim. See the file `COPYING` for more information.
@@ -0,0 +1,121 @@
1
+ require 'rake/clean'
2
+
3
+ task :default => :test
4
+
5
+
6
+ # ==========================================================
7
+ # Packaging
8
+ # ==========================================================
9
+
10
+ begin
11
+ require 'jeweler'
12
+ Jeweler::Tasks.new do |gemspec|
13
+ gemspec.name = "moredown"
14
+ gemspec.summary = "Markdown plus more!"
15
+ gemspec.description = "An extension to the RDiscount Markdown formatter"
16
+ gemspec.email = "nathan@nathanhoad.net"
17
+ gemspec.homepage = "http://nathanhoad.net/projects/moredown"
18
+ gemspec.authors = ["Nathan Hoad", "Ryan Tomayko", "David Loren Parsons"]
19
+ gemspec.files = `git ls-files`.split("\n").sort.reject{ |file| file =~ /^\./ || file =~ /^test\/MarkdownTest/ }
20
+ end
21
+ rescue LoadError
22
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
23
+ end
24
+
25
+
26
+
27
+ # ==========================================================
28
+ # Ruby Extension
29
+ # ==========================================================
30
+
31
+ DLEXT = Config::CONFIG['DLEXT']
32
+
33
+ file 'ext/Makefile' => FileList['ext/{*.c,*.h,*.rb}'] do
34
+ chdir('ext') { ruby 'extconf.rb' }
35
+ end
36
+ CLEAN.include 'ext/Makefile', 'ext/mkmf.log'
37
+
38
+ file "ext/rdiscount.#{DLEXT}" => FileList['ext/Makefile', 'ext/*.{c,h,rb}'] do |f|
39
+ sh 'cd ext && make'
40
+ end
41
+ CLEAN.include 'ext/*.{o,bundle,so,dll}'
42
+
43
+ file "lib/rdiscount.#{DLEXT}" => "ext/rdiscount.#{DLEXT}" do |f|
44
+ cp f.prerequisites, "lib/", :preserve => true
45
+ end
46
+
47
+ desc 'Build the rdiscount extension'
48
+ task :build_ext => "lib/rdiscount.#{DLEXT}"
49
+
50
+ # ==========================================================
51
+ # Testing
52
+ # ==========================================================
53
+
54
+ desc 'Run unit tests'
55
+ task 'test:unit' => [:build_ext] do |t|
56
+ sh 'testrb test/moredown_test.rb test/markdown_test.rb test/rdiscount_test.rb'
57
+ end
58
+
59
+ desc 'Run conformance tests (MARKDOWN_TEST_VER=1.0)'
60
+ task 'test:conformance' => [:build_ext] do |t|
61
+ script = "#{pwd}/bin/rdiscount"
62
+ test_version = ENV['MARKDOWN_TEST_VER'] || '1.0.3'
63
+ chdir("test/MarkdownTest_#{test_version}") do
64
+ sh "./MarkdownTest.pl --script='#{script}' --tidy"
65
+ end
66
+ end
67
+
68
+ desc 'Run version 1.0 conformance suite'
69
+ task 'test:conformance:1.0' => [:build_ext] do |t|
70
+ ENV['MARKDOWN_TEST_VER'] = '1.0'
71
+ Rake::Task['test:conformance'].invoke
72
+ end
73
+
74
+ desc 'Run 1.0.3 conformance suite'
75
+ task 'test:conformance:1.0.3' => [:build_ext] do |t|
76
+ ENV['MARKDOWN_TEST_VER'] = '1.0.3'
77
+ Rake::Task['test:conformance'].invoke
78
+ end
79
+
80
+ desc 'Run unit and conformance tests'
81
+ task :test => %w[test:unit test:conformance]
82
+
83
+ desc 'Run benchmarks'
84
+ task :benchmark => :build_ext do |t|
85
+ $:.unshift 'lib'
86
+ load 'test/benchmark.rb'
87
+ end
88
+
89
+ # ==========================================================
90
+ # Update package's Discount sources
91
+ # ==========================================================
92
+
93
+ desc 'Gather required discount sources into extension directory'
94
+ task :gather => 'discount' do |t|
95
+ files =
96
+ FileList[
97
+ 'discount/{markdown,mkdio,amalloc,cstring}.h',
98
+ 'discount/{markdown,docheader,dumptree,generate,mkdio,resource,toc,Csio}.c'
99
+ ]
100
+ cp files, 'ext/',
101
+ :preserve => true,
102
+ :verbose => true
103
+ end
104
+
105
+ # best. task. ever.
106
+ file 'discount' do |f|
107
+ STDERR.puts((<<-TEXT).gsub(/^ +/, ''))
108
+ Sorry, this operation requires a human. Tell your human to:
109
+
110
+ Grab a discount tarball from:
111
+ http://www.pell.portland.or.us/~orc/Code/discount/
112
+
113
+ Extract here with something like:
114
+ tar xvzf discount-1.2.9.tar.gz
115
+
116
+ Create a discount symlink pointing at the version directory:
117
+ ln -hsf discount-1.2.9 discount
118
+
119
+ TEXT
120
+ fail "discount sources required."
121
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path(File.dirname(__FILE__) + "/../lib")
4
+ require 'rdiscount'
5
+ STDOUT.write(RDiscount.new(ARGF.read).to_html)
@@ -0,0 +1,49 @@
1
+ #include <stdio.h>
2
+ #include <string.h>
3
+ #include <stdarg.h>
4
+ #include "cstring.h"
5
+ #include "markdown.h"
6
+ #include "amalloc.h"
7
+
8
+
9
+ /* putc() into a cstring
10
+ */
11
+ void
12
+ Csputc(int c, Cstring *iot)
13
+ {
14
+ EXPAND(*iot) = c;
15
+ }
16
+
17
+
18
+ /* printf() into a cstring
19
+ */
20
+ int
21
+ Csprintf(Cstring *iot, char *fmt, ...)
22
+ {
23
+ va_list ptr;
24
+ int siz=100;
25
+
26
+ do {
27
+ RESERVE(*iot, siz);
28
+ va_start(ptr, fmt);
29
+ siz = vsnprintf(T(*iot)+S(*iot), ALL(*iot)-S(*iot), fmt, ptr);
30
+ va_end(ptr);
31
+ } while ( siz > (ALL(*iot)-S(*iot)) );
32
+
33
+ S(*iot) += siz;
34
+ return siz;
35
+ }
36
+
37
+
38
+ /* reparse() into a cstring
39
+ */
40
+ void
41
+ Csreparse(Cstring *iot, char *buf, int size, int flags)
42
+ {
43
+ MMIOT f;
44
+ ___mkd_initmmiot(&f, 0);
45
+ ___mkd_reparse(buf, size, 0, &f);
46
+ ___mkd_emblock(&f);
47
+ SUFFIX(*iot, T(f.out), S(f.out));
48
+ ___mkd_freemmiot(&f, 0);
49
+ }
@@ -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*/
@@ -0,0 +1,9 @@
1
+
2
+ /* rdiscount extension configuration */
3
+
4
+ #undef USE_AMALLOC
5
+
6
+ #define TABSTOP 4
7
+ #define COINTOSS() (random()&1)
8
+ #define INITRNG(x) srandom((unsigned int)x)
9
+ #define RELAXED_EMPHASIS 1
@@ -0,0 +1,73 @@
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
+ #define ALL(x) (x).alloc
54
+
55
+ /* abstract anchor type that defines a list base
56
+ * with a function that attaches an element to
57
+ * the end of the list.
58
+ *
59
+ * the list base field is named .text so that the T()
60
+ * macro will work with it.
61
+ */
62
+ #define ANCHOR(t) struct { t *text, *end; }
63
+
64
+ #define ATTACH(t, p) ( (t).text ?( ((t).end->next = (p)), ((t).end = (p)) ) \
65
+ :( ((t).text = (t).end = (p)) ) )
66
+
67
+ typedef STRING(char) Cstring;
68
+
69
+ extern void Csputc(int, Cstring *);
70
+ extern int Csprintf(Cstring *, char *, ...);
71
+ extern void Csreparse(Cstring *, char *, int, int);
72
+
73
+ #endif/*_CSTRING_D*/