Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Upcast valign attribute.
Browse files Browse the repository at this point in the history
  • Loading branch information
jodator committed Feb 13, 2020
1 parent f166ba4 commit c3a5fa8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/tablecellproperties/tablecellpropertiesediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import TableCellBorderStyleCommand from './commands/tablecellborderstylecommand'
import TableCellBorderColorCommand from './commands/tablecellbordercolorcommand';
import TableCellBorderWidthCommand from './commands/tablecellborderwidthcommand';

const VALIGN_VALUES_REG_EXP = /^(top|bottom)$/;

/**
* The table cell properties editing feature.
*
Expand Down Expand Up @@ -180,6 +182,21 @@ function enableVerticalAlignmentProperty( schema, conversion ) {
}
}
} );

conversion.for( 'upcast' )
// Support for backwards compatibility and pasting from other sources.
.attributeToAttribute( {
view: {
attributes: {
valign: VALIGN_VALUES_REG_EXP
}
},
model: {
name: 'tableCell',
key: 'verticalAlignment',
value: viewElement => viewElement.getAttribute( 'valign' )
}
} );
}

// Enables conversion for an attribute for simple view-model mappings.
Expand Down
21 changes: 21 additions & 0 deletions tests/tablecellproperties/tablecellpropertiesediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,27 @@ describe( 'table cell properties', () => {

expect( tableCell.getAttribute( 'verticalAlignment' ) ).to.be.undefined;
} );

it( 'should upcast "top" valign attribute', () => {
editor.setData( '<table><tr><td valign="top">foo</td></tr></table>' );
const tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] );

expect( tableCell.getAttribute( 'verticalAlignment' ) ).to.equal( 'top' );
} );

it( 'should upcast "bottom" valign attribute', () => {
editor.setData( '<table><tr><td valign="bottom">foo</td></tr></table>' );
const tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] );

expect( tableCell.getAttribute( 'verticalAlignment' ) ).to.equal( 'bottom' );
} );

it( 'should not upcast "middle" valign attribute', () => {
editor.setData( '<table><tr><td valign="middle">foo</td></tr></table>' );
const tableCell = model.document.getRoot().getNodeByPath( [ 0, 0, 0 ] );

expect( tableCell.getAttribute( 'verticalAlignment' ) ).to.be.undefined;
} );
} );

describe( 'downcast conversion', () => {
Expand Down

0 comments on commit c3a5fa8

Please sign in to comment.