parkdown 1.4.28
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/LICENSE +68 -0
- data/README.markdown +86 -0
- data/Rakefile +170 -0
- data/bin/parkdown +13 -0
- data/ext/extconf.h +3 -0
- data/ext/extconf.rb +15 -0
- data/ext/markdown.c +104 -0
- data/ext/markdown_lib.c +186 -0
- data/ext/markdown_lib.h +44 -0
- data/ext/markdown_output.c +1275 -0
- data/ext/markdown_parser.c +7275 -0
- data/ext/markdown_peg.h +90 -0
- data/ext/parsing_functions.c +128 -0
- data/ext/utility_functions.c +217 -0
- data/lib/markdown.rb +1 -0
- data/lib/peg_markdown.rb +104 -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
- 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/benchmark.rb +49 -0
- data/test/markdown_test.rb +84 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 93f0d59c055327369415594462a78eb9c530ac1cb53d584c3cb2cc643022a64b
|
4
|
+
data.tar.gz: d0abf40bc764cae07358cabe567d2c6d9580fa263b46b47cccfabb56ede6ac05
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b6a6198c506213e9ce7cc205dbb8e29d8e1f43182bfc95d4cba53f67530856174ec356719ae5d9615f58da12ceb1f6b1d93bb7f7b0b90d650af8b1df41ef082d
|
7
|
+
data.tar.gz: f5ae8b63d80d32e27705c12cde4ee1981980f3ee20c2f6373c2c185cd7c1b89ae1fe48465c62a1f9a20d105f23fc46cf91b06d96a54624d7fad7ac28be82df66
|
data/LICENSE
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
Ruby Markdown Extension, implemented using peg-markdown
|
2
|
+
Copyright (c) 2011-2014 Ricardo Wurmus
|
3
|
+
Copyright (c) 2008 Ryan Tomayko
|
4
|
+
markdown in c, implemented using PEG grammar
|
5
|
+
Copyright (c) 2008 John MacFarlane
|
6
|
+
|
7
|
+
Parkdown is released under the GPL
|
8
|
+
|
9
|
+
The GPL
|
10
|
+
|
11
|
+
This program is free software; you can redistribute it and/or modify
|
12
|
+
it under the terms of the GNU General Public License as published by
|
13
|
+
the Free Software Foundation; either version 2 of the License, or
|
14
|
+
(at your option) any later version.
|
15
|
+
|
16
|
+
This program is distributed in the hope that it will be useful,
|
17
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19
|
+
GNU General Public License for more details.
|
20
|
+
|
21
|
+
You should have received a copy of the GNU General Public License
|
22
|
+
along with this program; if not, write to the Free Software
|
23
|
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
24
|
+
|
25
|
+
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
26
|
+
|
27
|
+
peg-0.1.4 (included for convenience - http://piumarta.com/software/peg/)
|
28
|
+
|
29
|
+
Copyright (c) 2007 by Ian Piumarta
|
30
|
+
All rights reserved.
|
31
|
+
|
32
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
33
|
+
copy of this software and associated documentation files (the 'Software'),
|
34
|
+
to deal in the Software without restriction, including without limitation
|
35
|
+
the rights to use, copy, modify, merge, publish, distribute, and/or sell
|
36
|
+
copies of the Software, and to permit persons to whom the Software is
|
37
|
+
furnished to do so, provided that the above copyright notice(s) and this
|
38
|
+
permission notice appear in all copies of the Software. Acknowledgement
|
39
|
+
of the use of this Software in supporting documentation would be
|
40
|
+
appreciated but is not required.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK.
|
43
|
+
|
44
|
+
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
45
|
+
|
46
|
+
my_getopt (included for convenience - http://www.geocities.com/bsittler/)
|
47
|
+
|
48
|
+
Copyright 1997, 2000, 2001, 2002, 2006, Benjamin Sittler
|
49
|
+
|
50
|
+
Permission is hereby granted, free of charge, to any person
|
51
|
+
obtaining a copy of this software and associated documentation
|
52
|
+
files (the "Software"), to deal in the Software without
|
53
|
+
restriction, including without limitation the rights to use, copy,
|
54
|
+
modify, merge, publish, distribute, sublicense, and/or sell copies
|
55
|
+
of the Software, and to permit persons to whom the Software is
|
56
|
+
furnished to do so, subject to the following conditions:
|
57
|
+
|
58
|
+
The above copyright notice and this permission notice shall be
|
59
|
+
included in all copies or substantial portions of the Software.
|
60
|
+
|
61
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
62
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
63
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
64
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
65
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
66
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
67
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
68
|
+
DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
Parkdown --- Ruby Markdown library
|
2
|
+
==================================
|
3
|
+
|
4
|
+
Parkdown is a Ruby extension library around [my fork][1] of
|
5
|
+
[John MacFarlane's fast implementation][2] of Markdown in C. This
|
6
|
+
extension library is a fork of Ryan Tomayko's [rpeg-markdown][3]
|
7
|
+
library. The main difference between Ryan's library and Parkdown is
|
8
|
+
the underlying parser. Ryan's library uses an outdated version of
|
9
|
+
John MacFarlane's peg-markdown, while Parkdown uses the parser
|
10
|
+
generated from [my heavily extended Markdown grammar][4].
|
11
|
+
|
12
|
+
[1]: https://github.com/rekado/peg-markdown/
|
13
|
+
[2]: https://github.com/jgm/peg-markdown/
|
14
|
+
[3]: https://github.com/rtomayko/rpeg-markdown
|
15
|
+
[4]: https://github.com/rekado/peg-markdown/blob/master/markdown_parser.leg
|
16
|
+
|
17
|
+
Synopsis
|
18
|
+
--------
|
19
|
+
|
20
|
+
>> require 'markdown'
|
21
|
+
>> puts Markdown.new('Hello, world.').to_html
|
22
|
+
<p>Hello, world.</p>
|
23
|
+
|
24
|
+
>> puts Markdown.new('_Hello World!_', :smart, :filter_html).to_html
|
25
|
+
<p><em>Hello World!</em></p>
|
26
|
+
|
27
|
+
>> puts Markdown.new('_Hello World!_').to_latex
|
28
|
+
\emph{Hello World!}
|
29
|
+
|
30
|
+
>> puts Markdown.new('_Hello World!_').to_groff_mm
|
31
|
+
.P
|
32
|
+
\fIHello world!\fR
|
33
|
+
|
34
|
+
|
35
|
+
Extensions
|
36
|
+
----------
|
37
|
+
|
38
|
+
Parkdown comes with the following non-standard extensions that are not
|
39
|
+
found in the libraries its originally based on:
|
40
|
+
|
41
|
+
- HTML5 video embedding: `%[caption](file-url.ogv alternative.mp4)`
|
42
|
+
- HTML5 audio embedding: `~[title](file-url.ogg alternative.mp3)`
|
43
|
+
- autolink: turns plain URLs (not wrapped in angled brackets) into
|
44
|
+
clickable links
|
45
|
+
- strike-through: `I owe you ~~ten~~ twenty coins.`
|
46
|
+
- image filtering: renders images as regular links
|
47
|
+
- hard wrap: translate simple line breaks into HTML line breaks
|
48
|
+
- code blocks: wrap a block in `~~~` to render it as a code block
|
49
|
+
- hashtags: wraps any term starting with `#` in `<span rel="hashtag">...</span>`
|
50
|
+
- usernames: wraps any name starting with `@` in `<span rel="username">...</span>`
|
51
|
+
- spoilers: a block prefixed with `?>` will be wrapped in a `<div class="spoilers">`.
|
52
|
+
Use CSS and JS to hide and show the block as needed.
|
53
|
+
|
54
|
+
|
55
|
+
Hacking
|
56
|
+
-------
|
57
|
+
|
58
|
+
The hard work of rendering some plain text syntax to
|
59
|
+
HTML/LaTeX/ODF/etc. is done by the parser that is generated from the
|
60
|
+
grammar in peg-markdown. To implement custom extensions, fork
|
61
|
+
peg-markdown and extend the grammar. Then update the peg-markdown
|
62
|
+
submodule in your fork of parkdown and expose the extension in the
|
63
|
+
Ruby library. Use the rake task `rake gather` to build the parser
|
64
|
+
from the grammar in the `peg-markdown/` directory and collect the
|
65
|
+
files in `ext/`. Then build the extension with `rake build`.
|
66
|
+
|
67
|
+
Patches are happily accepted via pull requests or email.
|
68
|
+
|
69
|
+
|
70
|
+
Installation
|
71
|
+
------------
|
72
|
+
|
73
|
+
This library requires a recent version of glib2. All modern GNU
|
74
|
+
userland systems should be fine.
|
75
|
+
|
76
|
+
Install from GEM:
|
77
|
+
|
78
|
+
$ sudo gem install parkdown
|
79
|
+
|
80
|
+
|
81
|
+
COPYING
|
82
|
+
-------
|
83
|
+
|
84
|
+
The peg-markdown sources are licensed under the GPL and Parkdown
|
85
|
+
adopts this license (just as the original rpeg-markdown did). See the
|
86
|
+
file LICENSE included with this distribution for more information.
|
data/Rakefile
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
require 'rake/clean'
|
2
|
+
require 'rake/packagetask'
|
3
|
+
require 'rubygems/package_task'
|
4
|
+
|
5
|
+
task :default => :test
|
6
|
+
|
7
|
+
DLEXT = RbConfig::CONFIG['DLEXT']
|
8
|
+
VERS = '1.4.26'
|
9
|
+
|
10
|
+
spec =
|
11
|
+
Gem::Specification.new do |s|
|
12
|
+
s.name = "parkdown"
|
13
|
+
s.version = VERS
|
14
|
+
s.summary = "Fast Markdown implementation"
|
15
|
+
s.files = FileList[
|
16
|
+
'README.markdown','LICENSE','Rakefile',
|
17
|
+
'{lib,ext,test}/**.rb','ext/*.{c,h}',
|
18
|
+
'test/MarkdownTest*/**/*',
|
19
|
+
'bin/parkdown'
|
20
|
+
]
|
21
|
+
s.bindir = 'bin'
|
22
|
+
s.executables << 'parkdown'
|
23
|
+
s.require_path = 'lib'
|
24
|
+
s.has_rdoc = true
|
25
|
+
s.extra_rdoc_files = ['LICENSE']
|
26
|
+
s.test_files = FileList['test/markdown_test.rb']
|
27
|
+
s.extensions = ['ext/extconf.rb']
|
28
|
+
|
29
|
+
s.author = 'rekado'
|
30
|
+
s.email = 'spam@elephly.net'
|
31
|
+
s.homepage = 'http://github.com/rekado/parkdown'
|
32
|
+
s.rubyforge_project = 'wink'
|
33
|
+
end
|
34
|
+
|
35
|
+
Gem::PackageTask.new(spec) do |p|
|
36
|
+
p.gem_spec = spec
|
37
|
+
p.need_tar_gz = true
|
38
|
+
p.need_tar = false
|
39
|
+
p.need_zip = false
|
40
|
+
end
|
41
|
+
|
42
|
+
namespace :submodule do
|
43
|
+
desc 'Init the peg-markdown submodule'
|
44
|
+
task :init do |t|
|
45
|
+
unless File.exist? 'peg-markdown/markdown.c'
|
46
|
+
rm_rf 'peg-markdown'
|
47
|
+
sh 'git submodule init peg-markdown'
|
48
|
+
sh 'git submodule update peg-markdown'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
desc 'Update the peg-markdown submodule'
|
53
|
+
task :update => :init do
|
54
|
+
sh 'git submodule update peg-markdown' unless File.symlink?('peg-markdown')
|
55
|
+
end
|
56
|
+
|
57
|
+
file 'peg-markdown/markdown.c' do
|
58
|
+
Rake::Task['submodule:init'].invoke
|
59
|
+
end
|
60
|
+
task :exist => 'peg-markdown/markdown.c'
|
61
|
+
end
|
62
|
+
|
63
|
+
desc 'Gather required peg-markdown sources into extension directory'
|
64
|
+
task :gather => 'submodule:exist' do |t|
|
65
|
+
sh 'cd peg-markdown && make markdown_parser.c'
|
66
|
+
files =
|
67
|
+
FileList[
|
68
|
+
'peg-markdown/markdown_{peg.h,parser.c,output.c,lib.c,lib.h}',
|
69
|
+
'peg-markdown/{utility,parsing}_functions.c',
|
70
|
+
'peg-markdown/{utility,parsing}_functions.h'
|
71
|
+
]
|
72
|
+
cp files, 'ext/',
|
73
|
+
:preserve => true,
|
74
|
+
:verbose => true
|
75
|
+
end
|
76
|
+
|
77
|
+
file 'ext/Makefile' => FileList['ext/{extconf.rb,*.c,*.h,*.rb}'] do
|
78
|
+
chdir('ext') { ruby 'extconf.rb' }
|
79
|
+
end
|
80
|
+
CLEAN.include 'ext/Makefile'
|
81
|
+
|
82
|
+
file "ext/peg_markdown.#{DLEXT}" => FileList['ext/Makefile', 'ext/*.{c,h,rb}'] do |f|
|
83
|
+
sh 'cd ext && make'
|
84
|
+
end
|
85
|
+
CLEAN.include 'ext/*.{o,bundle,so}'
|
86
|
+
|
87
|
+
file "lib/peg_markdown.#{DLEXT}" => "ext/peg_markdown.#{DLEXT}" do |f|
|
88
|
+
cp f.prerequisites, "lib/", :preserve => true
|
89
|
+
end
|
90
|
+
CLEAN.include "lib/*.{so,bundle}"
|
91
|
+
|
92
|
+
desc 'Build the peg_markdown extension'
|
93
|
+
task :build => "lib/peg_markdown.#{DLEXT}"
|
94
|
+
|
95
|
+
desc 'Run unit and conformance tests'
|
96
|
+
task :test => [ 'test:unit', 'test:conformance' ]
|
97
|
+
|
98
|
+
desc 'Run unit tests'
|
99
|
+
task 'test:unit' => [:build] do |t|
|
100
|
+
ruby 'test/markdown_test.rb'
|
101
|
+
end
|
102
|
+
|
103
|
+
desc "Run conformance tests (MARKDOWN_TEST_VER=#{ENV['MARKDOWN_TEST_VER'] ||= '1.0.3'})"
|
104
|
+
task 'test:conformance' => [:build] do |t|
|
105
|
+
script = "#{pwd}/bin/parkdown"
|
106
|
+
test_version = ENV['MARKDOWN_TEST_VER']
|
107
|
+
chdir("test/MarkdownTest_#{test_version}") do
|
108
|
+
sh "./MarkdownTest.pl --script='#{script}' --tidy"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
desc 'Run version 1.0 conformance suite'
|
113
|
+
task 'test:conformance:1.0' => [:build] do
|
114
|
+
ENV['MARKDOWN_TEST_VER'] = '1.0'
|
115
|
+
Rake::Task['test:conformance'].invoke
|
116
|
+
end
|
117
|
+
|
118
|
+
desc 'Run 1.0.3 conformance suite'
|
119
|
+
task 'test:conformance:1.0.3' => [:build] do |t|
|
120
|
+
ENV['MARKDOWN_TEST_VER'] = '1.0.3'
|
121
|
+
Rake::Task['test:conformance'].invoke
|
122
|
+
end
|
123
|
+
|
124
|
+
desc 'Run unit and conformance tests'
|
125
|
+
task :test => %w[test:unit test:conformance]
|
126
|
+
|
127
|
+
desc 'Run benchmarks'
|
128
|
+
task :benchmark => :build do |t|
|
129
|
+
$:.unshift 'lib'
|
130
|
+
load 'test/benchmark.rb'
|
131
|
+
end
|
132
|
+
|
133
|
+
desc "See how much memory we're losing"
|
134
|
+
task 'test:mem' => %w[submodule:exist build] do |t|
|
135
|
+
$: << File.join(File.dirname(__FILE__), "lib")
|
136
|
+
require 'markdown'
|
137
|
+
FileList['test/mem.txt', 'peg-markdown/MarkdownTest_1.0.3/Tests/*.text'].each do |file|
|
138
|
+
printf "%s: \n", file
|
139
|
+
markdown = Markdown.new(File.read(file))
|
140
|
+
iterations = (ENV['N'] || 100).to_i
|
141
|
+
total, growth = [], []
|
142
|
+
iterations.times do |i|
|
143
|
+
start = Time.now
|
144
|
+
GC.start
|
145
|
+
markdown.to_html
|
146
|
+
duration = Time.now - start
|
147
|
+
GC.start
|
148
|
+
total << `ps -o rss= -p #{Process.pid}`.to_i
|
149
|
+
next if i == 0
|
150
|
+
growth << (total.last - (total[-2] || 0))
|
151
|
+
# puts "%03d: %06.02f ms / %dK used / %dK growth" % [ i, duration, total.last, growth.last ]
|
152
|
+
end
|
153
|
+
average = growth.inject(0) { |sum,x| sum + x } / growth.length
|
154
|
+
printf " %dK avg growth (per run) / %dK used (after %d runs)\n", average, total.last, iterations
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
# ==========================================================
|
159
|
+
# Rubyforge
|
160
|
+
# ==========================================================
|
161
|
+
|
162
|
+
PKGNAME = "pkg/parkdown-#{VERS}"
|
163
|
+
|
164
|
+
desc 'Publish new release to rubyforge'
|
165
|
+
task :release => [ "#{PKGNAME}.gem", "#{PKGNAME}.tar.gz" ] do |t|
|
166
|
+
sh <<-end
|
167
|
+
rubyforge add_release wink parkdown #{VERS} #{PKGNAME}.gem &&
|
168
|
+
rubyforge add_file wink parkdown #{VERS} #{PKGNAME}.tar.gz
|
169
|
+
end
|
170
|
+
end
|
data/bin/parkdown
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'markdown'
|
5
|
+
rescue LoadError => boom
|
6
|
+
local_path = File.expand_path(File.dirname(__FILE__))
|
7
|
+
$: << "#{local_path}/../lib"
|
8
|
+
require 'markdown'
|
9
|
+
end
|
10
|
+
|
11
|
+
STDIN.reopen(ARGV[0], 'rb') if ARGV.any?
|
12
|
+
markdown = Markdown.new(STDIN.read)
|
13
|
+
STDOUT.write(markdown.to_html)
|
data/ext/extconf.h
ADDED
data/ext/extconf.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
dir_config('peg_markdown')
|
4
|
+
|
5
|
+
$objs = %w[markdown.o markdown_lib.o markdown_output.o markdown_parser.o parsing_functions.o utility_functions.o]
|
6
|
+
|
7
|
+
if pkg_config = find_executable('pkg-config')
|
8
|
+
$CFLAGS = `#{pkg_config} --cflags glib-2.0`
|
9
|
+
$LDFLAGS = `#{pkg_config} --libs glib-2.0`
|
10
|
+
else
|
11
|
+
fail "glib2 not found"
|
12
|
+
end
|
13
|
+
|
14
|
+
create_header
|
15
|
+
create_makefile('peg_markdown')
|
data/ext/markdown.c
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
#include "markdown_lib.h"
|
3
|
+
|
4
|
+
static VALUE rb_cMarkdown;
|
5
|
+
|
6
|
+
static VALUE
|
7
|
+
rb_markdown_to_html(int argc, VALUE *argv, VALUE self)
|
8
|
+
{
|
9
|
+
/* grab char pointer to markdown input text */
|
10
|
+
VALUE text = rb_funcall(self, rb_intern("text"), 0);
|
11
|
+
Check_Type(text, T_STRING);
|
12
|
+
char * ptext = StringValuePtr(text);
|
13
|
+
|
14
|
+
/* flip extension bits */
|
15
|
+
int extensions = 0;
|
16
|
+
if ( rb_funcall(self, rb_intern("smart"), 0) == Qtrue )
|
17
|
+
extensions = extensions | EXT_SMART ;
|
18
|
+
if ( rb_funcall(self, rb_intern("notes"), 0) == Qtrue )
|
19
|
+
extensions = extensions | EXT_NOTES ;
|
20
|
+
if ( rb_funcall(self, rb_intern("filter_html"), 0) == Qtrue )
|
21
|
+
extensions = extensions | EXT_FILTER_HTML ;
|
22
|
+
if ( rb_funcall(self, rb_intern("filter_styles"), 0) == Qtrue )
|
23
|
+
extensions = extensions | EXT_FILTER_STYLES ;
|
24
|
+
if ( rb_funcall(self, rb_intern("strike"), 0) == Qtrue )
|
25
|
+
extensions = extensions | EXT_STRIKE ;
|
26
|
+
if ( rb_funcall(self, rb_intern("autolink"), 0) == Qtrue )
|
27
|
+
extensions = extensions | EXT_AUTOLINK ;
|
28
|
+
if ( rb_funcall(self, rb_intern("hard_wrap"), 0) == Qtrue )
|
29
|
+
extensions = extensions | EXT_HARD_WRAP ;
|
30
|
+
if ( rb_funcall(self, rb_intern("no_images"), 0) == Qtrue )
|
31
|
+
extensions = extensions | EXT_NO_IMAGES ;
|
32
|
+
if ( rb_funcall(self, rb_intern("media"), 0) == Qtrue )
|
33
|
+
extensions = extensions | EXT_MEDIA ;
|
34
|
+
if ( rb_funcall(self, rb_intern("codeblock"), 0) == Qtrue )
|
35
|
+
extensions = extensions | EXT_CODEBLOCK ;
|
36
|
+
if ( rb_funcall(self, rb_intern("hashtags"), 0) == Qtrue )
|
37
|
+
extensions = extensions | EXT_HASHTAGS ;
|
38
|
+
if ( rb_funcall(self, rb_intern("usernames"), 0) == Qtrue )
|
39
|
+
extensions = extensions | EXT_USERNAMES ;
|
40
|
+
if ( rb_funcall(self, rb_intern("spoilerblock"), 0) == Qtrue )
|
41
|
+
extensions = extensions | EXT_SPOILERBLOCK ;
|
42
|
+
|
43
|
+
char *html = markdown_to_string(ptext, extensions, HTML_FORMAT);
|
44
|
+
VALUE result = rb_str_new2(html);
|
45
|
+
free(html);
|
46
|
+
|
47
|
+
return result;
|
48
|
+
}
|
49
|
+
|
50
|
+
static VALUE
|
51
|
+
rb_markdown_to_latex(int argc, VALUE *argv, VALUE self)
|
52
|
+
{
|
53
|
+
/* grab char pointer to markdown input text */
|
54
|
+
VALUE text = rb_funcall(self, rb_intern("text"), 0);
|
55
|
+
Check_Type(text, T_STRING);
|
56
|
+
char * ptext = StringValuePtr(text);
|
57
|
+
|
58
|
+
/* flip extension bits - note that defaults are different than
|
59
|
+
* for HTML */
|
60
|
+
int extensions = EXT_SMART | EXT_NOTES | EXT_FILTER_HTML | EXT_FILTER_STYLES;
|
61
|
+
if ( rb_funcall(self, rb_intern("smart"), 0) == Qfalse )
|
62
|
+
extensions = extensions & ~ EXT_SMART ;
|
63
|
+
if ( rb_funcall(self, rb_intern("notes"), 0) == Qfalse )
|
64
|
+
extensions = extensions & ~ EXT_NOTES ;
|
65
|
+
|
66
|
+
char *latex = markdown_to_string(ptext, extensions, LATEX_FORMAT);
|
67
|
+
VALUE result = rb_str_new2(latex);
|
68
|
+
free(latex);
|
69
|
+
|
70
|
+
return result;
|
71
|
+
}
|
72
|
+
|
73
|
+
static VALUE
|
74
|
+
rb_markdown_to_groff_mm(int argc, VALUE *argv, VALUE self)
|
75
|
+
{
|
76
|
+
/* grab char pointer to markdown input text */
|
77
|
+
VALUE text = rb_funcall(self, rb_intern("text"), 0);
|
78
|
+
Check_Type(text, T_STRING);
|
79
|
+
char * ptext = StringValuePtr(text);
|
80
|
+
|
81
|
+
/* flip extension bits - note that defaults are different than
|
82
|
+
* for HTML */
|
83
|
+
int extensions = EXT_SMART | EXT_NOTES | EXT_FILTER_HTML | EXT_FILTER_STYLES;
|
84
|
+
if ( rb_funcall(self, rb_intern("smart"), 0) == Qfalse )
|
85
|
+
extensions = extensions & ~ EXT_SMART ;
|
86
|
+
if ( rb_funcall(self, rb_intern("notes"), 0) == Qfalse )
|
87
|
+
extensions = extensions & ~ EXT_NOTES ;
|
88
|
+
|
89
|
+
char *groff = markdown_to_string(ptext, extensions, GROFF_MM_FORMAT);
|
90
|
+
VALUE result = rb_str_new2(groff);
|
91
|
+
free(groff);
|
92
|
+
|
93
|
+
return result;
|
94
|
+
}
|
95
|
+
|
96
|
+
void Init_peg_markdown()
|
97
|
+
{
|
98
|
+
rb_cMarkdown = rb_define_class("PEGMarkdown", rb_cObject);
|
99
|
+
rb_define_method(rb_cMarkdown, "to_html", rb_markdown_to_html, -1);
|
100
|
+
rb_define_method(rb_cMarkdown, "to_latex", rb_markdown_to_latex, -1);
|
101
|
+
rb_define_method(rb_cMarkdown, "to_groff_mm", rb_markdown_to_groff_mm, -1);
|
102
|
+
}
|
103
|
+
|
104
|
+
// vim: ts=4 sw=4
|
data/ext/markdown_lib.c
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
/**********************************************************************
|
2
|
+
|
3
|
+
markdown_lib.c - markdown in C using a PEG grammar.
|
4
|
+
(c) 2008 John MacFarlane (jgm at berkeley dot edu).
|
5
|
+
|
6
|
+
This program is free software; you can redistribute it and/or modify
|
7
|
+
it under the terms of the GNU General Public License or the MIT
|
8
|
+
license. See LICENSE for details.
|
9
|
+
|
10
|
+
This program is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
GNU General Public License for more details.
|
14
|
+
|
15
|
+
***********************************************************************/
|
16
|
+
|
17
|
+
#include <stdio.h>
|
18
|
+
#include <stdlib.h>
|
19
|
+
#include <string.h>
|
20
|
+
#include "markdown_peg.h"
|
21
|
+
|
22
|
+
#define TABSTOP 4
|
23
|
+
|
24
|
+
/* preformat_text - allocate and copy text buffer while
|
25
|
+
* performing tab expansion. */
|
26
|
+
static GString *preformat_text(char *text) {
|
27
|
+
GString *buf;
|
28
|
+
char next_char;
|
29
|
+
int charstotab;
|
30
|
+
|
31
|
+
int len = 0;
|
32
|
+
|
33
|
+
buf = g_string_new("");
|
34
|
+
|
35
|
+
charstotab = TABSTOP;
|
36
|
+
while ((next_char = *text++) != '\0') {
|
37
|
+
switch (next_char) {
|
38
|
+
case '\t':
|
39
|
+
while (charstotab > 0)
|
40
|
+
g_string_append_c(buf, ' '), len++, charstotab--;
|
41
|
+
break;
|
42
|
+
case '\n':
|
43
|
+
g_string_append_c(buf, '\n'), len++, charstotab = TABSTOP;
|
44
|
+
break;
|
45
|
+
default:
|
46
|
+
g_string_append_c(buf, next_char), len++, charstotab--;
|
47
|
+
}
|
48
|
+
if (charstotab == 0)
|
49
|
+
charstotab = TABSTOP;
|
50
|
+
}
|
51
|
+
g_string_append(buf, "\n\n");
|
52
|
+
return(buf);
|
53
|
+
}
|
54
|
+
|
55
|
+
/* print_tree - print tree of elements, for debugging only. */
|
56
|
+
static void print_tree(element * elt, int indent) {
|
57
|
+
int i;
|
58
|
+
char * key;
|
59
|
+
while (elt != NULL) {
|
60
|
+
for (i = 0; i < indent; i++)
|
61
|
+
fputc(' ', stderr);
|
62
|
+
switch (elt->key) {
|
63
|
+
case LIST: key = "LIST"; break;
|
64
|
+
case RAW: key = "RAW"; break;
|
65
|
+
case SPACE: key = "SPACE"; break;
|
66
|
+
case LINEBREAK: key = "LINEBREAK"; break;
|
67
|
+
case ELLIPSIS: key = "ELLIPSIS"; break;
|
68
|
+
case EMDASH: key = "EMDASH"; break;
|
69
|
+
case ENDASH: key = "ENDASH"; break;
|
70
|
+
case APOSTROPHE: key = "APOSTROPHE"; break;
|
71
|
+
case SINGLEQUOTED: key = "SINGLEQUOTED"; break;
|
72
|
+
case DOUBLEQUOTED: key = "DOUBLEQUOTED"; break;
|
73
|
+
case STR: key = "STR"; break;
|
74
|
+
case LINK: key = "LINK"; break;
|
75
|
+
case IMAGE: key = "IMAGE"; break;
|
76
|
+
case AUDIO: key = "AUDIO"; break;
|
77
|
+
case VIDEO: key = "VIDEO"; break;
|
78
|
+
case CODE: key = "CODE"; break;
|
79
|
+
case HTML: key = "HTML"; break;
|
80
|
+
case EMPH: key = "EMPH"; break;
|
81
|
+
case STRONG: key = "STRONG"; break;
|
82
|
+
case PLAIN: key = "PLAIN"; break;
|
83
|
+
case PARA: key = "PARA"; break;
|
84
|
+
case LISTITEM: key = "LISTITEM"; break;
|
85
|
+
case BULLETLIST: key = "BULLETLIST"; break;
|
86
|
+
case ORDEREDLIST: key = "ORDEREDLIST"; break;
|
87
|
+
case H1: key = "H1"; break;
|
88
|
+
case H2: key = "H2"; break;
|
89
|
+
case H3: key = "H3"; break;
|
90
|
+
case H4: key = "H4"; break;
|
91
|
+
case H5: key = "H5"; break;
|
92
|
+
case H6: key = "H6"; break;
|
93
|
+
case BLOCKQUOTE: key = "BLOCKQUOTE"; break;
|
94
|
+
case SPOILERBLOCK: key = "SPOILERBLOCK"; break;
|
95
|
+
case VERBATIM: key = "VERBATIM"; break;
|
96
|
+
case HTMLBLOCK: key = "HTMLBLOCK"; break;
|
97
|
+
case HRULE: key = "HRULE"; break;
|
98
|
+
case REFERENCE: key = "REFERENCE"; break;
|
99
|
+
case NOTE: key = "NOTE"; break;
|
100
|
+
case HASHTAG: key = "HASHTAG"; break;
|
101
|
+
case USERNAME: key = "USERNAME"; break;
|
102
|
+
default: key = "?";
|
103
|
+
}
|
104
|
+
if ( elt->key == STR ) {
|
105
|
+
fprintf(stderr, "0x%p: %s '%s'\n", (void *)elt, key, elt->contents.str);
|
106
|
+
} else {
|
107
|
+
fprintf(stderr, "0x%p: %s\n", (void *)elt, key);
|
108
|
+
}
|
109
|
+
if (elt->children)
|
110
|
+
print_tree(elt->children, indent + 4);
|
111
|
+
elt = elt->next;
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
/* process_raw_blocks - traverses an element list, replacing any RAW elements with
|
116
|
+
* the result of parsing them as markdown text, and recursing into the children
|
117
|
+
* of parent elements. The result should be a tree of elements without any RAWs. */
|
118
|
+
static element * process_raw_blocks(element *input, int extensions, element *references, element *notes) {
|
119
|
+
element *current = NULL;
|
120
|
+
element *last_child = NULL;
|
121
|
+
char *contents;
|
122
|
+
current = input;
|
123
|
+
|
124
|
+
while (current != NULL) {
|
125
|
+
if (current->key == RAW) {
|
126
|
+
/* \001 is used to indicate boundaries between nested lists when there
|
127
|
+
* is no blank line. We split the string by \001 and parse
|
128
|
+
* each chunk separately. */
|
129
|
+
contents = strtok(current->contents.str, "\001");
|
130
|
+
current->key = LIST;
|
131
|
+
current->children = parse_markdown(contents, extensions, references, notes);
|
132
|
+
last_child = current->children;
|
133
|
+
while ((contents = strtok(NULL, "\001"))) {
|
134
|
+
while (last_child->next != NULL)
|
135
|
+
last_child = last_child->next;
|
136
|
+
last_child->next = parse_markdown(contents, extensions, references, notes);
|
137
|
+
}
|
138
|
+
free(current->contents.str);
|
139
|
+
current->contents.str = NULL;
|
140
|
+
}
|
141
|
+
if (current->children != NULL)
|
142
|
+
current->children = process_raw_blocks(current->children, extensions, references, notes);
|
143
|
+
current = current->next;
|
144
|
+
}
|
145
|
+
return input;
|
146
|
+
}
|
147
|
+
|
148
|
+
/* markdown_to_gstring - convert markdown text to the output format specified.
|
149
|
+
* Returns a GString, which must be freed after use using g_string_free(). */
|
150
|
+
GString * markdown_to_g_string(char *text, int extensions, int output_format) {
|
151
|
+
element *result;
|
152
|
+
element *references;
|
153
|
+
element *notes;
|
154
|
+
GString *formatted_text;
|
155
|
+
GString *out;
|
156
|
+
out = g_string_new("");
|
157
|
+
|
158
|
+
formatted_text = preformat_text(text);
|
159
|
+
|
160
|
+
references = parse_references(formatted_text->str, extensions);
|
161
|
+
notes = parse_notes(formatted_text->str, extensions, references);
|
162
|
+
result = parse_markdown(formatted_text->str, extensions, references, notes);
|
163
|
+
|
164
|
+
result = process_raw_blocks(result, extensions, references, notes);
|
165
|
+
|
166
|
+
g_string_free(formatted_text, TRUE);
|
167
|
+
|
168
|
+
print_element_list(out, result, output_format, extensions);
|
169
|
+
|
170
|
+
free_element_list(result);
|
171
|
+
free_element_list(references);
|
172
|
+
return out;
|
173
|
+
}
|
174
|
+
|
175
|
+
/* markdown_to_string - convert markdown text to the output format specified.
|
176
|
+
* Returns a null-terminated string, which must be freed after use. */
|
177
|
+
char * markdown_to_string(char *text, int extensions, int output_format) {
|
178
|
+
GString *out;
|
179
|
+
char *char_out;
|
180
|
+
out = markdown_to_g_string(text, extensions, output_format);
|
181
|
+
char_out = out->str;
|
182
|
+
g_string_free(out, FALSE);
|
183
|
+
return char_out;
|
184
|
+
}
|
185
|
+
|
186
|
+
/* vim:set ts=4 sw=4: */
|