From 92f753a3650332ee0cf8a1649b750993aaac800b Mon Sep 17 00:00:00 2001 From: Gabriel Wicke Date: Mon, 4 Jun 2012 14:03:05 +0200 Subject: [PATCH] Pre and link target improvements * Don't explicitly add the newline in the pre, as we preserve newline tokens now. This avoids doubling of newlines when round-tripping. * Use the sHref attribute even if the href contains spaces. Change-Id: I8bec8fbfd6a7836bf2e5eec20869a0edd95c93b6 --- modules/parser/mediawiki.WikitextSerializer.js | 8 ++++---- modules/parser/pegTokenizer.pegjs.txt | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/parser/mediawiki.WikitextSerializer.js b/modules/parser/mediawiki.WikitextSerializer.js index 6d2477cb15..ea3507994b 100644 --- a/modules/parser/mediawiki.WikitextSerializer.js +++ b/modules/parser/mediawiki.WikitextSerializer.js @@ -122,9 +122,7 @@ WSP._linkHandler = function( state, token ) { var attribDict = state.env.KVtoHash( token.attribs ); if ( attribDict.rel && attribDict.href !== undefined ) { var target = decodeURIComponent( - attribDict.href.substr( state.env.wgScriptPath.length + 1 ) - .replace( /_/g, ' ' ) - ); + attribDict.href.substr( state.env.wgScriptPath.length + 1 ) ); if ( token.dataAttribs.sHref ) { //console.warn( JSON.stringify( token.dataAttribs.sHref ) ); var normalizedOrigHref = state.env.resolveTitle( @@ -134,6 +132,8 @@ WSP._linkHandler = function( state, token ) { if ( normalizedOrigHref === target ) { target = token.dataAttribs.sHref; } + } else { + target = target.replace( /_/g, ' ' ) } if ( attribDict.rel === 'mw:wikiLink' ) { @@ -268,7 +268,7 @@ WSP.tagToWikitext = { // XXX: support indent variant instead by registering a newline handler? pre: { start: function( state, token ) { - state.textHandler = function( t ) { return t.replace( '\n', '\n ' ); }; + state.textHandler = function( t ) { return t.replace( /\n/g, '\n ' ); }; return ''; }, end: function( state, token) { state.textHandler = null; return ''; } diff --git a/modules/parser/pegTokenizer.pegjs.txt b/modules/parser/pegTokenizer.pegjs.txt index 3fe4761c8e..2cf607f54b 100644 --- a/modules/parser/pegTokenizer.pegjs.txt +++ b/modules/parser/pegTokenizer.pegjs.txt @@ -1107,7 +1107,7 @@ pre_indent_in_tags / & { return stops.dec('pre'); } pre_indent_line = space l:inlineline { - return [ '\n' ].concat(l); + return l; } /*