tight-redcarpet 3.2.0 → 3.3.2t
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/COPYING +17 -11
- data/Gemfile +2 -2
- data/README.markdown +21 -15
- data/bin/redcarpet +4 -40
- data/ext/redcarpet/autolink.c +17 -11
- data/ext/redcarpet/autolink.h +17 -11
- data/ext/redcarpet/buffer.c +22 -16
- data/ext/redcarpet/buffer.h +17 -11
- data/ext/redcarpet/houdini.h +22 -0
- data/ext/redcarpet/houdini_href_e.c +22 -0
- data/ext/redcarpet/houdini_html_e.c +22 -0
- data/ext/redcarpet/html.c +54 -55
- data/ext/redcarpet/html.h +17 -17
- data/ext/redcarpet/html_smartypants.c +27 -15
- data/ext/redcarpet/markdown.c +25 -17
- data/ext/redcarpet/markdown.h +17 -12
- data/ext/redcarpet/rc_markdown.c +18 -11
- data/ext/redcarpet/rc_render.c +23 -12
- data/ext/redcarpet/redcarpet.h +22 -0
- data/ext/redcarpet/stack.c +22 -0
- data/ext/redcarpet/stack.h +22 -0
- data/lib/redcarpet.rb +2 -2
- data/lib/redcarpet/cli.rb +86 -0
- data/lib/redcarpet/render_strip.rb +13 -1
- data/redcarpet.gemspec +7 -5
- data/test/custom_render_test.rb +1 -1
- data/test/fixtures/benchmark.md +232 -0
- data/test/html_render_test.rb +5 -5
- data/test/html_toc_render_test.rb +2 -3
- data/test/markdown_test.rb +60 -26
- data/test/redcarpet_bin_test.rb +80 -0
- data/test/redcarpet_compat_test.rb +6 -6
- data/test/safe_render_test.rb +5 -6
- data/test/smarty_html_test.rb +8 -8
- data/test/smarty_pants_test.rb +5 -0
- data/test/stripdown_render_test.rb +26 -5
- data/test/test_helper.rb +9 -11
- metadata +14 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf3dc5590d70a25ee9b132d657ea5eaa8969dad9
|
4
|
+
data.tar.gz: fb3042ee7c682ba2cbe002fc98e5f212486e126e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8097f93b8ef15d63dbdb6949f92e5b152352837370e180767b3db3de3713018b3beb65b50626dff2c11b71c7cf6b39dbd196420f723252f64badfe919ae1f073
|
7
|
+
data.tar.gz: 7895715b616d1c825155073acdcc2783e80fb0b1e9d95d36f86d72c93855d8cf84730e9282293d9251195768c29dd13564c71e1165ee337deea7e8fa2013e8a6
|
data/COPYING
CHANGED
@@ -1,14 +1,20 @@
|
|
1
1
|
Copyright (c) 2009, Natacha Porté
|
2
|
-
Copyright (c)
|
2
|
+
Copyright (c) 2015, Vicent Marti
|
3
3
|
|
4
|
-
Permission
|
5
|
-
|
6
|
-
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
6
|
+
in the Software without restriction, including without limitation the rights
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
9
|
+
furnished to do so, subject to the following conditions:
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
OR
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
12
|
+
all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
THE SOFTWARE.
|
data/Gemfile
CHANGED
data/README.markdown
CHANGED
@@ -83,7 +83,7 @@ but starting with `www` are also handled.
|
|
83
83
|
|
84
84
|
* `:disable_indented_code_blocks`: do not parse usual markdown
|
85
85
|
code blocks. Markdown converts text with four spaces at
|
86
|
-
the front of each line to code blocks. This
|
86
|
+
the front of each line to code blocks. This option
|
87
87
|
prevents it from doing so. Recommended to use
|
88
88
|
with `fenced_code_blocks: true`.
|
89
89
|
|
@@ -159,7 +159,7 @@ safe.
|
|
159
159
|
* `:with_toc_data`: add HTML anchors to each header in the output HTML,
|
160
160
|
to allow linking to each section.
|
161
161
|
|
162
|
-
* `:hard_wrap`: insert HTML `<br>` tags inside
|
162
|
+
* `:hard_wrap`: insert HTML `<br>` tags inside paragraphs where the original
|
163
163
|
Markdown document had newlines (by default, Markdown ignores these newlines).
|
164
164
|
|
165
165
|
* `:xhtml`: output XHTML-conformant tags. This option is always enabled in the
|
@@ -372,16 +372,22 @@ monkeypatches the Markdown class, you're a terrible human being. Just saying.
|
|
372
372
|
Boring legal stuff
|
373
373
|
------------------
|
374
374
|
|
375
|
-
Copyright (c) 2011-
|
376
|
-
|
377
|
-
Permission
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
375
|
+
Copyright (c) 2011-2015, Vicent Martí
|
376
|
+
|
377
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
378
|
+
of this software and associated documentation files (the "Software"), to deal
|
379
|
+
in the Software without restriction, including without limitation the rights
|
380
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
381
|
+
copies of the Software, and to permit persons to whom the Software is
|
382
|
+
furnished to do so, subject to the following conditions:
|
383
|
+
|
384
|
+
The above copyright notice and this permission notice shall be included in
|
385
|
+
all copies or substantial portions of the Software.
|
386
|
+
|
387
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
388
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
389
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
390
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
391
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
392
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
393
|
+
THE SOFTWARE.
|
data/bin/redcarpet
CHANGED
@@ -1,43 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
|
4
|
-
# no <file> or when <file> is '-', read Markdown source text from standard input.
|
5
|
-
# With <extension>s, perform additional Markdown processing before writing output.
|
6
|
-
# With --smarty, use the SmartyHTML renderer
|
7
|
-
if ARGV.include?('--help') or ARGV.include?('-h')
|
8
|
-
File.read(__FILE__).split("\n").grep(/^# /).each do |line|
|
9
|
-
puts line[2..-1]
|
10
|
-
end
|
11
|
-
exit 0
|
12
|
-
end
|
2
|
+
lib_path = File.expand_path('../../lib', __FILE__)
|
3
|
+
$:.unshift(lib_path)
|
13
4
|
|
14
|
-
require 'redcarpet'
|
5
|
+
require 'redcarpet/cli'
|
15
6
|
|
16
|
-
|
17
|
-
puts "Redcarpet #{Redcarpet::VERSION}"
|
18
|
-
exit 0
|
19
|
-
end
|
20
|
-
|
21
|
-
root = File.expand_path('../../', __FILE__)
|
22
|
-
$:.unshift File.expand_path('lib', root)
|
23
|
-
|
24
|
-
render_extensions = {}
|
25
|
-
parse_extensions = {}
|
26
|
-
renderer = Redcarpet::Render::HTML
|
27
|
-
|
28
|
-
ARGV.delete_if do |arg|
|
29
|
-
if arg =~ /^--render-([\w-]+)$/
|
30
|
-
arg = $1.gsub('-', '_')
|
31
|
-
render_extensions[arg.to_sym] = true
|
32
|
-
elsif arg =~ /^--parse-([\w-]+)$/
|
33
|
-
arg = $1.gsub('-', '_')
|
34
|
-
parse_extensions[arg.to_sym] = true
|
35
|
-
elsif arg == '--smarty'
|
36
|
-
renderer = Redcarpet::Render::SmartyHTML
|
37
|
-
else
|
38
|
-
false
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
render = renderer.new(render_extensions)
|
43
|
-
STDOUT.write(Redcarpet::Markdown.new(render, parse_extensions).render(ARGF.read))
|
7
|
+
Redcarpet::CLI.process(ARGV)
|
data/ext/redcarpet/autolink.c
CHANGED
@@ -1,17 +1,23 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) 2015, Vicent Marti
|
3
3
|
*
|
4
|
-
* Permission
|
5
|
-
*
|
6
|
-
*
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
9
|
+
* furnished to do so, subject to the following conditions:
|
7
10
|
*
|
8
|
-
*
|
9
|
-
*
|
10
|
-
*
|
11
|
-
*
|
12
|
-
*
|
13
|
-
*
|
14
|
-
* OR
|
11
|
+
* The above copyright notice and this permission notice shall be included in
|
12
|
+
* all copies or substantial portions of the Software.
|
13
|
+
*
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
* THE SOFTWARE.
|
15
21
|
*/
|
16
22
|
|
17
23
|
#include "buffer.h"
|
data/ext/redcarpet/autolink.h
CHANGED
@@ -1,17 +1,23 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) 2015, Vicent Marti
|
3
3
|
*
|
4
|
-
* Permission
|
5
|
-
*
|
6
|
-
*
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
9
|
+
* furnished to do so, subject to the following conditions:
|
7
10
|
*
|
8
|
-
*
|
9
|
-
*
|
10
|
-
*
|
11
|
-
*
|
12
|
-
*
|
13
|
-
*
|
14
|
-
* OR
|
11
|
+
* The above copyright notice and this permission notice shall be included in
|
12
|
+
* all copies or substantial portions of the Software.
|
13
|
+
*
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
* THE SOFTWARE.
|
15
21
|
*/
|
16
22
|
|
17
23
|
#ifndef AUTOLINK_H__
|
data/ext/redcarpet/buffer.c
CHANGED
@@ -1,18 +1,24 @@
|
|
1
1
|
/*
|
2
2
|
* Copyright (c) 2008, Natacha Porté
|
3
|
-
* Copyright (c)
|
3
|
+
* Copyright (c) 2015, Vicent Marti
|
4
4
|
*
|
5
|
-
* Permission
|
6
|
-
*
|
7
|
-
*
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
10
|
+
* furnished to do so, subject to the following conditions:
|
8
11
|
*
|
9
|
-
*
|
10
|
-
*
|
11
|
-
*
|
12
|
-
*
|
13
|
-
*
|
14
|
-
*
|
15
|
-
* OR
|
12
|
+
* The above copyright notice and this permission notice shall be included in
|
13
|
+
* all copies or substantial portions of the Software.
|
14
|
+
*
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
* THE SOFTWARE.
|
16
22
|
*/
|
17
23
|
|
18
24
|
#define BUFFER_MAX_ALLOC_SIZE (1024 * 1024 * 16) //16mb
|
@@ -101,7 +107,7 @@ bufcstr(const struct buf *buf)
|
|
101
107
|
if (buf->size < buf->asize && buf->data[buf->size] == 0)
|
102
108
|
return (char *)buf->data;
|
103
109
|
|
104
|
-
if (buf->size + 1 <= buf->asize || bufgrow(buf, buf->size + 1) ==
|
110
|
+
if (buf->size + 1 <= buf->asize || bufgrow(buf, buf->size + 1) == BUF_OK) {
|
105
111
|
buf->data[buf->size] = 0;
|
106
112
|
return (char *)buf->data;
|
107
113
|
}
|
@@ -118,7 +124,7 @@ bufprintf(struct buf *buf, const char *fmt, ...)
|
|
118
124
|
|
119
125
|
assert(buf && buf->unit);
|
120
126
|
|
121
|
-
if (buf->size >= buf->asize && bufgrow(buf, buf->size + 1) <
|
127
|
+
if (buf->size >= buf->asize && bufgrow(buf, buf->size + 1) < BUF_OK)
|
122
128
|
return;
|
123
129
|
|
124
130
|
va_start(ap, fmt);
|
@@ -136,7 +142,7 @@ bufprintf(struct buf *buf, const char *fmt, ...)
|
|
136
142
|
}
|
137
143
|
|
138
144
|
if ((size_t)n >= buf->asize - buf->size) {
|
139
|
-
if (bufgrow(buf, buf->size + n + 1) <
|
145
|
+
if (bufgrow(buf, buf->size + n + 1) < BUF_OK)
|
140
146
|
return;
|
141
147
|
|
142
148
|
va_start(ap, fmt);
|
@@ -156,7 +162,7 @@ bufput(struct buf *buf, const void *data, size_t len)
|
|
156
162
|
{
|
157
163
|
assert(buf && buf->unit);
|
158
164
|
|
159
|
-
if (buf->size + len > buf->asize && bufgrow(buf, buf->size + len) <
|
165
|
+
if (buf->size + len > buf->asize && bufgrow(buf, buf->size + len) < BUF_OK)
|
160
166
|
return;
|
161
167
|
|
162
168
|
memcpy(buf->data + buf->size, data, len);
|
@@ -177,7 +183,7 @@ bufputc(struct buf *buf, int c)
|
|
177
183
|
{
|
178
184
|
assert(buf && buf->unit);
|
179
185
|
|
180
|
-
if (buf->size + 1 > buf->asize && bufgrow(buf, buf->size + 1) <
|
186
|
+
if (buf->size + 1 > buf->asize && bufgrow(buf, buf->size + 1) < BUF_OK)
|
181
187
|
return;
|
182
188
|
|
183
189
|
buf->data[buf->size] = c;
|
data/ext/redcarpet/buffer.h
CHANGED
@@ -1,18 +1,24 @@
|
|
1
1
|
/*
|
2
2
|
* Copyright (c) 2008, Natacha Porté
|
3
|
-
* Copyright (c)
|
3
|
+
* Copyright (c) 2015, Vicent Marti
|
4
4
|
*
|
5
|
-
* Permission
|
6
|
-
*
|
7
|
-
*
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
10
|
+
* furnished to do so, subject to the following conditions:
|
8
11
|
*
|
9
|
-
*
|
10
|
-
*
|
11
|
-
*
|
12
|
-
*
|
13
|
-
*
|
14
|
-
*
|
15
|
-
* OR
|
12
|
+
* The above copyright notice and this permission notice shall be included in
|
13
|
+
* all copies or substantial portions of the Software.
|
14
|
+
*
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
* THE SOFTWARE.
|
16
22
|
*/
|
17
23
|
|
18
24
|
#ifndef BUFFER_H__
|
data/ext/redcarpet/houdini.h
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2015, Vicent Marti
|
3
|
+
*
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
9
|
+
* furnished to do so, subject to the following conditions:
|
10
|
+
*
|
11
|
+
* The above copyright notice and this permission notice shall be included in
|
12
|
+
* all copies or substantial portions of the Software.
|
13
|
+
*
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
* THE SOFTWARE.
|
21
|
+
*/
|
22
|
+
|
1
23
|
#ifndef HOUDINI_H__
|
2
24
|
#define HOUDINI_H__
|
3
25
|
|
@@ -1,3 +1,25 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2015, Vicent Marti
|
3
|
+
*
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
9
|
+
* furnished to do so, subject to the following conditions:
|
10
|
+
*
|
11
|
+
* The above copyright notice and this permission notice shall be included in
|
12
|
+
* all copies or substantial portions of the Software.
|
13
|
+
*
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
* THE SOFTWARE.
|
21
|
+
*/
|
22
|
+
|
1
23
|
#include <assert.h>
|
2
24
|
#include <stdio.h>
|
3
25
|
#include <string.h>
|
@@ -1,3 +1,25 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2015, Vicent Marti
|
3
|
+
*
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
9
|
+
* furnished to do so, subject to the following conditions:
|
10
|
+
*
|
11
|
+
* The above copyright notice and this permission notice shall be included in
|
12
|
+
* all copies or substantial portions of the Software.
|
13
|
+
*
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
* THE SOFTWARE.
|
21
|
+
*/
|
22
|
+
|
1
23
|
#include <assert.h>
|
2
24
|
#include <stdio.h>
|
3
25
|
#include <string.h>
|
data/ext/redcarpet/html.c
CHANGED
@@ -1,18 +1,24 @@
|
|
1
1
|
/*
|
2
2
|
* Copyright (c) 2009, Natacha Porté
|
3
|
-
* Copyright (c)
|
3
|
+
* Copyright (c) 2015, Vicent Marti
|
4
4
|
*
|
5
|
-
* Permission
|
6
|
-
*
|
7
|
-
*
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
10
|
+
* furnished to do so, subject to the following conditions:
|
8
11
|
*
|
9
|
-
*
|
10
|
-
*
|
11
|
-
*
|
12
|
-
*
|
13
|
-
*
|
14
|
-
*
|
15
|
-
* OR
|
12
|
+
* The above copyright notice and this permission notice shall be included in
|
13
|
+
* all copies or substantial portions of the Software.
|
14
|
+
*
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
* THE SOFTWARE.
|
16
22
|
*/
|
17
23
|
|
18
24
|
#include "markdown.h"
|
@@ -264,51 +270,35 @@ rndr_linebreak(struct buf *ob, void *opaque)
|
|
264
270
|
return 1;
|
265
271
|
}
|
266
272
|
|
267
|
-
|
273
|
+
static void
|
274
|
+
rndr_header_anchor(struct buf *out, const struct buf *anchor)
|
268
275
|
{
|
269
|
-
|
270
|
-
|
271
|
-
char text[size];
|
272
|
-
strcpy(text, bufcstr(buffer));
|
273
|
-
|
274
|
-
char raw_string[size];
|
276
|
+
static const char *STRIPPED = " -&+$,/:;=?@\"#{}|^~[]`\\*()%.!'";
|
275
277
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
/* Once every two times, the yielded token is the
|
281
|
-
content of a HTML tag so we don't need to copy it */
|
282
|
-
for (k = 0; part != NULL; k++) {
|
283
|
-
if (k == 0)
|
284
|
-
strcpy(raw_string, part);
|
285
|
-
else if (k % 2 == 0)
|
286
|
-
strcat(raw_string, part);
|
278
|
+
const uint8_t *a = anchor->data;
|
279
|
+
const size_t size = anchor->size;
|
280
|
+
size_t i = 0;
|
281
|
+
int stripped = 0, inserted = 0;
|
287
282
|
|
288
|
-
|
283
|
+
for (; i < size; ++i) {
|
284
|
+
if (a[i] == '<') {
|
285
|
+
while (i < size && a[i] != '>')
|
286
|
+
i++;
|
287
|
+
}
|
288
|
+
else if (strchr(STRIPPED, a[i])) {
|
289
|
+
if (inserted && !stripped)
|
290
|
+
bufputc(out, '-');
|
291
|
+
stripped = 1;
|
292
|
+
}
|
293
|
+
else {
|
294
|
+
bufputc(out, tolower(a[i]));
|
295
|
+
stripped = 0;
|
296
|
+
inserted++;
|
289
297
|
}
|
290
|
-
|
291
|
-
size = strlen(raw_string);
|
292
|
-
} else {
|
293
|
-
strcpy(raw_string, text);
|
294
|
-
}
|
295
|
-
|
296
|
-
char* heading = malloc(size * sizeof(char));
|
297
|
-
|
298
|
-
/* Dasherize the string removing extra white spaces
|
299
|
-
and stripped chars */
|
300
|
-
for (i = 0, j = 0; i < size; ++i, ++j) {
|
301
|
-
while (STRIPPED_CHAR(raw_string[i]) && STRIPPED_CHAR(raw_string[i+1]))
|
302
|
-
i++;
|
303
|
-
|
304
|
-
if (STRIPPED_CHAR(raw_string[i]))
|
305
|
-
heading[j] = '-';
|
306
|
-
else
|
307
|
-
heading[j] = tolower(raw_string[i]);
|
308
298
|
}
|
309
299
|
|
310
|
-
|
311
|
-
|
300
|
+
if (stripped)
|
301
|
+
out->size--;
|
312
302
|
}
|
313
303
|
|
314
304
|
static void
|
@@ -319,8 +309,11 @@ rndr_header(struct buf *ob, const struct buf *text, int level, void *opaque)
|
|
319
309
|
if (ob->size)
|
320
310
|
bufputc(ob, '\n');
|
321
311
|
|
322
|
-
if ((options->flags & HTML_TOC) && (level <= options->toc_data.nesting_level))
|
323
|
-
bufprintf(ob, "<h%d id=\"
|
312
|
+
if ((options->flags & HTML_TOC) && (level <= options->toc_data.nesting_level)) {
|
313
|
+
bufprintf(ob, "<h%d id=\"", level);
|
314
|
+
rndr_header_anchor(ob, text);
|
315
|
+
BUFPUTSL(ob, "\">");
|
316
|
+
}
|
324
317
|
else
|
325
318
|
bufprintf(ob, "<h%d>", level);
|
326
319
|
|
@@ -482,7 +475,10 @@ rndr_image(struct buf *ob, const struct buf *link, const struct buf *title, cons
|
|
482
475
|
return 0;
|
483
476
|
|
484
477
|
BUFPUTSL(ob, "<img src=\"");
|
485
|
-
|
478
|
+
|
479
|
+
if (link && link->size)
|
480
|
+
escape_href(ob, link->data, link->size);
|
481
|
+
|
486
482
|
BUFPUTSL(ob, "\" alt=\"");
|
487
483
|
|
488
484
|
if (alt && alt->size)
|
@@ -490,7 +486,8 @@ rndr_image(struct buf *ob, const struct buf *link, const struct buf *title, cons
|
|
490
486
|
|
491
487
|
if (title && title->size) {
|
492
488
|
BUFPUTSL(ob, "\" title=\"");
|
493
|
-
escape_html(ob, title->data, title->size);
|
489
|
+
escape_html(ob, title->data, title->size);
|
490
|
+
}
|
494
491
|
|
495
492
|
bufputs(ob, USE_XHTML(options) ? "\"/>" : "\">");
|
496
493
|
return 1;
|
@@ -685,7 +682,9 @@ toc_header(struct buf *ob, const struct buf *text, int level, void *opaque)
|
|
685
682
|
BUFPUTSL(ob,"</li>\n<li>\n");
|
686
683
|
}
|
687
684
|
|
688
|
-
bufprintf(ob, "<a href=\"
|
685
|
+
bufprintf(ob, "<a href=\"#");
|
686
|
+
rndr_header_anchor(ob, text);
|
687
|
+
BUFPUTSL(ob, "\">");
|
689
688
|
|
690
689
|
if (text) {
|
691
690
|
if (options->flags & HTML_ESCAPE)
|