dont double escape certain entities/character references, fix encoding test
This commit is contained in:
parent
9ab262b2cd
commit
b702e91a10
@ -332,7 +332,7 @@ inline.lexer = function(str) {
|
|||||||
if (cap = inline.code.exec(str)) {
|
if (cap = inline.code.exec(str)) {
|
||||||
str = str.substring(cap[0].length);
|
str = str.substring(cap[0].length);
|
||||||
out += '<code>'
|
out += '<code>'
|
||||||
+ escape(cap[2] || cap[1])
|
+ escape(cap[2] || cap[1], true)
|
||||||
+ '</code>';
|
+ '</code>';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -413,7 +413,7 @@ var tok = function() {
|
|||||||
}
|
}
|
||||||
case 'code': {
|
case 'code': {
|
||||||
return '<pre><code>'
|
return '<pre><code>'
|
||||||
+ escape(token.text)
|
+ escape(token.text, true)
|
||||||
+ '</code></pre>';
|
+ '</code></pre>';
|
||||||
}
|
}
|
||||||
case 'blockquote_start': {
|
case 'blockquote_start': {
|
||||||
@ -508,9 +508,11 @@ var parse = function(src) {
|
|||||||
* Helpers
|
* Helpers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var escape = function(html) {
|
var escape = function(html, dbl) {
|
||||||
return html
|
return html
|
||||||
.replace(/&/g, '&')
|
.replace(!dbl
|
||||||
|
? /&(?!#?\w+;)/g
|
||||||
|
: /&/g, '&')
|
||||||
.replace(/</g, '<')
|
.replace(/</g, '<')
|
||||||
.replace(/>/g, '>')
|
.replace(/>/g, '>')
|
||||||
.replace(/"/g, '"')
|
.replace(/"/g, '"')
|
||||||
|
17
test/fix.js
17
test/fix.js
@ -51,16 +51,11 @@ fs.readdirSync(dir).forEach(function(file) {
|
|||||||
fs.writeFileSync(file, text);
|
fs.writeFileSync(file, text);
|
||||||
});
|
});
|
||||||
|
|
||||||
// markdown avoids double encoding half of the time
|
// markdown is weird with encoding
|
||||||
// and does it the other half. this behavior will be
|
|
||||||
// implemented eventually, but for now, this needs to
|
|
||||||
// be changed, because i want to see if the other tests
|
|
||||||
// included in this file pass.
|
|
||||||
(function() {
|
(function() {
|
||||||
var file = dir + '/amps_and_angles_encoding.html';
|
var file = dir + '/amps_and_angles_encoding.html';
|
||||||
var html = fs.readFileSync(file, 'utf8')
|
var html = fs.readFileSync(file, 'utf8')
|
||||||
.replace('6 > 5.', '6 > 5.')
|
.replace('6 > 5.', '6 > 5.')
|
||||||
.replace('AT&T is another', 'AT&amp;T is another');
|
|
||||||
|
|
||||||
fs.writeFileSync(file, html);
|
fs.writeFileSync(file, html);
|
||||||
})();
|
})();
|
||||||
@ -73,7 +68,7 @@ fs.readdirSync(dir).forEach(function(file) {
|
|||||||
fs.writeFileSync(file, text);
|
fs.writeFileSync(file, text);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// fix strange markup that isnt likely
|
// fix strange markup that isnt likely
|
||||||
// to exist in the reality
|
// to exist in the reality
|
||||||
(function _(ext) {
|
(function _(ext) {
|
||||||
var file = dir + '/inline_html_advanced.' + ext;
|
var file = dir + '/inline_html_advanced.' + ext;
|
||||||
@ -86,17 +81,17 @@ fs.readdirSync(dir).forEach(function(file) {
|
|||||||
('html');
|
('html');
|
||||||
|
|
||||||
// markdown parses backslashes in a very primitive
|
// markdown parses backslashes in a very primitive
|
||||||
// way because it's not a real parser. i cannot
|
// way because it's not a real parser. i cannot
|
||||||
// include this test, because marked parses backslashes
|
// include this test, because marked parses backslashes
|
||||||
// in a very different way.
|
// in a very different way.
|
||||||
(function(ext) {
|
(function(ext) {
|
||||||
fs.writeFileSync(dir + '/backslash_escapes.text',
|
fs.writeFileSync(dir + '/backslash_escapes.text',
|
||||||
'hello world \\[how](are you) today');
|
'hello world \\[how](are you) today');
|
||||||
fs.writeFileSync(dir + '/backslash_escapes.html',
|
fs.writeFileSync(dir + '/backslash_escapes.html',
|
||||||
'<p>hello world [how](are you) today</p>');
|
'<p>hello world [how](are you) today</p>');
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// can't do this for performance reasons
|
// can't do this for performance reasons
|
||||||
// right now
|
// right now
|
||||||
(function _(name) {
|
(function _(name) {
|
||||||
fs.unlinkSync(dir + '/' + name + '.text');
|
fs.unlinkSync(dir + '/' + name + '.text');
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<p>AT&T has an ampersand in their name.</p>
|
<p>AT&T has an ampersand in their name.</p>
|
||||||
|
|
||||||
<p>AT&amp;T is another way to write it.</p>
|
<p>AT&T is another way to write it.</p>
|
||||||
|
|
||||||
<p>This & that.</p>
|
<p>This & that.</p>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user