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

Commit 07bcc70

Browse files
author
Piotr Jasiun
authored
Merge pull request #1094 from ckeditor/t/1092
Other: HighlightDescriptor can contain an array of CSS classes. Closes #1092.
2 parents 1c3510a + a44061b commit 07bcc70

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/conversion/buildmodelconverter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ export default function buildModelConverter() {
439439
* can handle displaying highlight separately by providing `addHighlight` and `removeHighlight` custom
440440
* properties.
441441
*
442-
* @property {String} class CSS class that will be added to `span`
442+
* @property {String|Array<String>} class CSS class or array of classes that will be added to `span`
443443
* {@link module:engine/view/attributeelement~AttributeElement} wrapping each text node in the highlighted content.
444444
* @property {Number} [priority] {@link module:engine/view/attributeelement~AttributeElement#priority} of the `span`
445445
* wrapping each text node in the highlighted content. If not provided, default 10 priority will be used.

src/conversion/model-to-view-converters.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,8 @@ export function highlightDescriptorToAttributeElement( descriptor ) {
569569
const attributeElement = new ViewAttributeElement( 'span', descriptor.attributes );
570570

571571
if ( descriptor.class ) {
572-
attributeElement.addClass( descriptor.class );
572+
const cssClasses = Array.isArray( descriptor.class ) ? descriptor.class : [ descriptor.class ];
573+
attributeElement.addClass( ...cssClasses );
573574
}
574575

575576
if ( descriptor.priority ) {

tests/conversion/model-to-view-converters.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,25 @@ describe( 'model-to-view-converters', () => {
12111211
}
12121212
} );
12131213

1214+
it( 'should return attribute element from descriptor object - array with classes', () => {
1215+
const descriptor = {
1216+
class: [ 'foo-class', 'bar-class' ],
1217+
attributes: { one: 1, two: 2 },
1218+
priority: 7,
1219+
};
1220+
const element = highlightDescriptorToAttributeElement( descriptor );
1221+
1222+
expect( element.is( 'attributeElement' ) ).to.be.true;
1223+
expect( element.name ).to.equal( 'span' );
1224+
expect( element.priority ).to.equal( 7 );
1225+
expect( element.hasClass( 'foo-class' ) ).to.be.true;
1226+
expect( element.hasClass( 'bar-class' ) ).to.be.true;
1227+
1228+
for ( const key of Object.keys( descriptor.attributes ) ) {
1229+
expect( element.getAttribute( key ) ).to.equal( descriptor.attributes[ key ] );
1230+
}
1231+
} );
1232+
12141233
it( 'should create element without class', () => {
12151234
const descriptor = {
12161235
attributes: { one: 1, two: 2 },

0 commit comments

Comments
 (0)