Fix round-tripping of invalid external links somewhat

* Don't consider them for auto-numbered links
* Don't insert a trailing space if the content is empty

These links are still wrapped in nowiki on round-tripping since the
valid/invalid url determination is done in the LinkHandler and not the
Tokenizer as it is configuration-dependent. Not incorrect for rendering (and
perhaps easier to understand for humans too), but might still introduce a
dirty diff. We'll still need reconciliation / damage tracking in the end ;)

Change-Id: I959ebc1b7f81d110a1141bb38ba5ee97f52ebf96
This commit is contained in:
Gabriel Wicke 2012-06-28 16:12:23 +02:00
parent 198e55a32b
commit e1a7d10063
2 changed files with 12 additions and 6 deletions

View file

@ -412,11 +412,11 @@ ExternalLinkHandler.prototype.onExtLink = function ( token, manager, cb ) {
//console.warn('extlink href: ' + href );
//console.warn( 'content: ' + JSON.stringify( content, null, 2 ) );
// validate the href
if ( ! content.length ) {
content = ['[' + this.linkCount + ']'];
this.linkCount++;
}
if ( this.imageParser.tokenizeURL( href ) ) {
if ( ! content.length ) {
content = ['[' + this.linkCount + ']'];
this.linkCount++;
}
if ( content.length === 1 &&
content[0].constructor === String &&
this.imageParser.tokenizeURL( content[0] ) &&
@ -446,8 +446,14 @@ ExternalLinkHandler.prototype.onExtLink = function ( token, manager, cb ) {
].concat( content, [ new EndTagTk( 'a' )])
} );
} else {
var tokens = ['[', href ];
if ( content.length ) {
tokens = tokens.concat( [' '], content );
}
tokens.push(']');
cb( {
tokens: ['[', href, ' ' ].concat( content, [']'] )
tokens: tokens
} );
}
};

View file

@ -1548,7 +1548,7 @@ table_data_tags
td:table_data_tag
tagEndPos:({return pos})
tds:( pipe_pipe tdt:table_data_tag { tdt[0].dataAttribs.stx_v = 'row'; return tdt } )* {
td[0].dataAttribs.tsr = [pos0, tagEndPos];
td[0].dataAttribs.tsr[0] = pos0;
return td.concat(tds);
}