fix gfm extended autolinking requiring multiple backpedals

Add a test and fix that trailing punctuation is omitted in link URLs for
markdown like this:

    (See https://www.example.com/fhqwhgads.)

The trailing period and closing parenthesis should not be part of the
link URL.
This commit is contained in:
Rich Trott 2018-06-22 13:51:48 -07:00
parent 666e4558b0
commit a3cddeeae6
3 changed files with 27 additions and 2 deletions

View File

@ -655,7 +655,8 @@ InlineLexer.prototype.output = function(src) {
text,
href,
title,
cap;
cap,
prevCapZero;
while (src) {
// escape
@ -681,7 +682,10 @@ InlineLexer.prototype.output = function(src) {
// url (gfm)
if (!this.inLink && (cap = this.rules.url.exec(src))) {
cap[0] = this.rules._backpedal.exec(cap[0])[0];
do {
prevCapZero = cap[0];
cap[0] = this.rules._backpedal.exec(cap[0])[0];
} while (prevCapZero !== cap[0]);
src = src.substring(cap[0].length);
if (cap[2] === '@') {
text = escape(cap[0]);

View File

@ -32,6 +32,21 @@ Messenger.prototype.test = function(spec, section, ignore) {
var messenger = new Messenger();
describe('Marked Autolinks', function() {
var section = 'Autolinks';
// var shouldPassButFails = [];
var shouldPassButFails = [];
var willNotBeAttemptedByCoreTeam = [];
var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam);
markedSpec.forEach(function(spec) {
messenger.test(spec, section, ignore);
});
});
describe('Marked Code spans', function() {
var section = 'Code spans';

View File

@ -1,4 +1,10 @@
[
{
"section": "Autolinks",
"markdown": "(See https://www.example.com/fhqwhgads.)",
"html": "<p>(See <a href=\"https://www.example.com/fhqwhgads\">https://www.example.com/fhqwhgads</a>.)</p>",
"example": 10
},
{
"section": "Code spans",
"markdown": "`someone@example.com`",