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

Commit

Permalink
Merge 2dc61f2 into 0b9c20d
Browse files Browse the repository at this point in the history
  • Loading branch information
pomek committed Aug 27, 2019
2 parents 0b9c20d + 2dc61f2 commit cc94f56
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/bold/boldediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,24 @@ export default class BoldEditing extends Plugin {
} );

// Build converter from model to view for data and editing pipelines.

editor.conversion.attributeToElement( {
model: BOLD,
view: 'strong',
upcastAlso: [
'b',
{
styles: {
'font-weight': 'bold'
viewElement => {
const fontWeight = viewElement.getStyle( 'font-weight' );

if ( !fontWeight ) {
return null;
}

// Value of the `font-weight` attribute can be defined as a string or a number.
if ( fontWeight == 'bold' || Number( fontWeight ) >= 600 ) {
return {
name: true,
styles: [ 'font-weight' ]
};
}
}
]
Expand Down
27 changes: 27 additions & 0 deletions tests/bold/boldediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,33 @@ describe( 'BoldEditing', () => {
expect( editor.getData() ).to.equal( '<p><strong>foo</strong>bar</p>' );
} );

it( 'should convert font-weight defined as number to bold attribute (if the value is higher or equal to 600)', () => {
editor.setData( '<p><span style="font-weight: 600;">foo</span>bar</p>' );

expect( getModelData( model, { withoutSelection: true } ) )
.to.equal( '<paragraph><$text bold="true">foo</$text>bar</paragraph>' );

expect( editor.getData() ).to.equal( '<p><strong>foo</strong>bar</p>' );
} );

it( 'should not convert font-weight defined as number to bold attribute (if the value is lower than 600)', () => {
editor.setData( '<p><span style="font-weight: 500;">foo</span>bar</p>' );

expect( getModelData( model, { withoutSelection: true } ) )
.to.equal( '<paragraph>foobar</paragraph>' );

expect( editor.getData() ).to.equal( '<p>foobar</p>' );
} );

it( 'should not convert font-weight if the value is invalid', () => {
editor.setData( '<p><span style="font-weight: foo;">foo</span>bar</p>' );

expect( getModelData( model, { withoutSelection: true } ) )
.to.equal( '<paragraph>foobar</paragraph>' );

expect( editor.getData() ).to.equal( '<p>foobar</p>' );
} );

it( 'should be integrated with autoparagraphing', () => {
editor.setData( '<strong>foo</strong>bar' );

Expand Down
10 changes: 10 additions & 0 deletions tests/manual/basic-styles.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
<div id="editor">
<p><i>This</i> <s>is</s> <code>an</code> <strong>editor</strong> <u>instance</u>, X<sub>1</sub>, X<sup>2</sup>.</p>
<p>
The <code>font-weight</code> attribute check:
<span style="font-weight:bold">bold</span>,
<span style="font-weight:400">400</span>,
<span style="font-weight:500">500</span>,
<span style="font-weight:600">600</span>,
<span style="font-weight:700">700</span>,
<span style="font-weight:800">800</span>,
<span style="font-weight:900">900</span>.
</p>
</div>
3 changes: 2 additions & 1 deletion tests/manual/basic-styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
* code `"an"`,
* subscript X<sub>1</sub>,
* superscript X<sup>2</sup>.
2. Test the bold, italic, strikethrough, underline, code, subscript and superscript features live.
2. The second sentence should bold the following words: `bold`, `600`, `700`, `800`, `900`.
3. Test the bold, italic, strikethrough, underline, code, subscript and superscript features live.

0 comments on commit cc94f56

Please sign in to comment.