--- break.js 2010-02-13 15:58:41.000000000 -0800 +++ break.js 2010-03-08 13:35:29.000000000 -0800 @@ -39,6 +39,13 @@ Drupal.wysiwyg.plugins['break'] = { * Replace all tags with images. */ attach: function(content, settings, instanceId) { + // Remove unnecessary paragraph. + content = content.replace(/
<\/p>/ig, this._getPlaceholder(settings)); + // Move breaks starting at the beginning of paragraphs to before them. + content = content.replace(/
(<[^p])/ig, this._getPlaceholder(settings) + '
$1'); + // Move breaks starting at the end of to after the paragraphs. + content = content.replace(/([^p]>)<\/p>/ig, '$1
' + this._getPlaceholder(settings)); + // Other breaks. content = content.replace(//g, this._getPlaceholder(settings)); return content; }, @@ -47,22 +54,33 @@ Drupal.wysiwyg.plugins['break'] = { * Replace images with tags in content upon detaching editor. */ detach: function(content, settings, instanceId) { - var $content = $(']*?>(?:\s*\s*)+<\/p>\s*/ig, ''); + // console.log('1\n'+newContent); + // Replace all other placeholders. + newContent = newContent.replace(//ig, ''); + // console.log('2\n'+newContent); + // Fix paragraphs opening just before breaks. + newContent = newContent.replace(/(?:)*(
]*?>\s*)/ig, '$1'); + // console.log('3\n'+newContent); + // Remove duplicate breaks and any preceding whitespaces. + newContent = newContent.replace(/(?:\s*){2,}/g, ''); + // console.log('4\n'+newContent); + // Fix paragraphs ending after breaks. + newContent = newContent.replace(/(\s*<\/p>)(?:)*/ig, '$1'); + // console.log('5\n'+newContent); + // Remove duplicate breaks with trailing whitespaces. + newContent = newContent.replace(/(?:\s*){2,}/g, ''); + // console.log('done\n'+newContent); + return newContent; }, /** * Helper function to return a HTML placeholder. */ _getPlaceholder: function (settings) { - return ''; + return ''; } };