Skip to content

Commit

Permalink
Merge branch 'hotfix-0.20.2' of git://github.com/evo42/Aloha-Editor i…
Browse files Browse the repository at this point in the history
…nto hotfix

Conflicts:
	CHANGELOG.md
  • Loading branch information
Johannes Schüth committed Feb 9, 2012
2 parents 42b4e8e + 3cd9ba0 commit ebc8436
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -14,6 +14,7 @@ All changes are categorized into one of the following keywords:

## 0.20.5 - SNAPSHOT

- **ENHANCEMENT** word contenthandler: cleanup for pasted word documents with table of contents
- **BUG** paste plugin: removed trim of pasted contents -- test[ text] + 2x c&p results now in test text text instead of testtexttext
- **BUG** format/table plugin: added a workaround in the format plugin to enable formating of selected cells
- **ENHANCEMENT** cite plugin: config option if sidebar should auto open or not (Aloha.settings.plugins.cite.sidebar.open: true|false)
Expand Down
88 changes: 71 additions & 17 deletions src/plugins/common/contenthandler/lib/wordcontenthandler.js
Expand Up @@ -15,6 +15,7 @@ function( Aloha, jQuery, ContentHandlerManager ) {
* @param content
*/
handleContent: function( content ) {

if ( typeof content === 'string' ){
content = jQuery( '<div>' + content + '</div>' );
} else if ( content instanceof jQuery ) {
Expand Down Expand Up @@ -120,7 +121,7 @@ function( Aloha, jQuery, ContentHandlerManager ) {
var jqElem = jQuery(this),
innerText = jqElem.text().trim().replace(/&nbsp;/g, ''),
outerText;

if (innerText.length === 0) {
// check whether the outermost of the three spans contains nothing more than numbering
outerText = jqElem.parent().parent().text().trim().replace(/&nbsp;/g, '');
Expand Down Expand Up @@ -268,13 +269,30 @@ function( Aloha, jQuery, ContentHandlerManager ) {
*/
cleanHtml: function ( content ) {

// unwrap empty tags
// do not remove them here because of eg. spaces wrapped in spans which are needed
content.find('*').filter( function() {
return jQuery.trim(jQuery(this).text()) == '';
}).contents().unwrap();

// unwrap all spans
content.find('span').contents().unwrap();

// when href starts with #, it's the link to an anchor. remove it.
content.find('a').each(function() {
if ( jQuery(this).attr('href') && jQuery(this).attr('href').trim().match(/^#(.*)$/) ) {
jQuery(this).contents().unwrap();
}
});

// eg. footnotes are wrapped in divs. unwrap them.
content.find('div').contents().unwrap();

// remove empty tags
content.find('*').filter( function() {
return jQuery.trim(jQuery(this).html()) == '';
return jQuery.trim(jQuery(this).text()) == '';
}).remove();

// http://stackoverflow.com/questions/4232961/jquery-remove-a-tag-but-keep-innerhtml
content.find('span').contents().unwrap();
},

/**
Expand All @@ -285,43 +303,79 @@ function( Aloha, jQuery, ContentHandlerManager ) {
var detectionFilter = 'h1,h2,h3,h4,h5,h6',
paragraphs = content.find(detectionFilter);

if (paragraphs.length > 0) {
paragraphs.each(function() {
var jqElem = jQuery(this),
spans = jqElem.find('span'),
links = jqElem.find('a');

// remove TOC numbering
spans.each(function() {
if ( jQuery(this).text().trim().match(/^([\.\(]?[\d\D][\.\(]?){1,4}$/) ) {
jQuery(this).remove();
}
})

// remove TOC anchor links
links.each(function() {
// no href, so it's an anchor
if ( typeof jQuery(this).attr('href') === 'undefined' ) {
jQuery(this).contents().unwrap();
}
});

});
}
},


/**
* Transform TOC
* @param content
*/
transformToc: function( content ) {
var detectionFilter = '[class*=MsoToc]',
paragraphs = content.find(detectionFilter);

paragraphs.each(function() {
var jqElem = jQuery(this),
spans = jqElem.find('span'),
links = jqElem.find('a');

// remove TOC numbering

// a table of contents entry looks like
// 1. Title text ... 5
// we get rid of the "... 5" part which repesents the page number
spans.each(function() {
if (jQuery(this).text().trim().match(/^([0-9]{1,3}\.)|([0-9]{1,3}\))|([a-zA-Z]{1,5}\.)|([a-zA-Z]{1,5}\))$/)) {
if ( jQuery(this).attr('style') && jQuery(this).attr('style').search('mso-hide') > -1 ) {
jQuery(this).remove();
}
})

// remove TOC anchor links
jQuery(this).contents().unwrap();
});

// remove the anchor link of the toc item
links.each(function() {
if ( typeof jQuery(this).attr('href') === 'undefined' ) {
jQuery(this).contents().unwrap();
}
jQuery(this).contents().unwrap();
});

});

},

/**
* This is the main transformation method
* @param content
*/
transformWordContent: function( content ) {
// transform table of contents
this.transformToc( content );

// remove paragraph numbering
this.removeParagraphNumbering( content );

// transform lists
this.transformListsFromWord( content );

// transform titles
this.transformTitles( content );

// clean html
this.cleanHtml( content );
}
Expand Down

0 comments on commit ebc8436

Please sign in to comment.