From e1a7d10063192beae092649d6b2bf7eae43c58af Mon Sep 17 00:00:00 2001 From: Gabriel Wicke Date: Thu, 28 Jun 2012 16:12:23 +0200 Subject: [PATCH] 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 --- modules/parser/ext.core.LinkHandler.js | 16 +++++++++++----- modules/parser/pegTokenizer.pegjs.txt | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/modules/parser/ext.core.LinkHandler.js b/modules/parser/ext.core.LinkHandler.js index 5fbacdd12a..4eca5ba180 100644 --- a/modules/parser/ext.core.LinkHandler.js +++ b/modules/parser/ext.core.LinkHandler.js @@ -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 } ); } }; diff --git a/modules/parser/pegTokenizer.pegjs.txt b/modules/parser/pegTokenizer.pegjs.txt index 454c4cc924..8fea5dbf40 100644 --- a/modules/parser/pegTokenizer.pegjs.txt +++ b/modules/parser/pegTokenizer.pegjs.txt @@ -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); }