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

Commit

Permalink
Merge 1720dbc into 250f8f2
Browse files Browse the repository at this point in the history
  • Loading branch information
jodator committed Oct 22, 2019
2 parents 250f8f2 + 1720dbc commit 3d24d01
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/conversion/downcasthelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,19 @@ export default class DowncastHelpers extends ConversionHelpers {
* view: modelAttributeValue => ( { key: 'class', value: 'styled-' + modelAttributeValue } )
* } );
*
* *Note:* Downcasting to a style properties requires providing a style object as a `value`:
*
* editor.conversion.for( 'downcast' ).attributeToAttribute( {
* model: 'lineHeight',
* view: modelAttributeValue => ( {
* key: 'style',
* value: {
* 'line-height': modelAttributeValue,
* 'border-bottom': '1px dotted #ba2'
* }
* } )
* } );
*
* See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
* to the conversion process.
*
Expand Down
27 changes: 27 additions & 0 deletions src/conversion/upcasthelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,33 @@ export default class UpcastHelpers extends ConversionHelpers {
* }
* } );
*
* Converting styles is a bit different as it requires an object to be set as a `value` and by default
* a model attribute's value will be set to `true`. You can set any value by providing a `value` callback
* that returns a desired value.
*
* // Default conversion of font-weight style will result in setting bold attribute to true.
* editor.conversion.for( 'upcast' ).attributeToAttribute( {
* view: {
* styles: {
* 'font-weight': 'bold'
* }
* },
* model: 'bold'
* } );
*
* // This converter will pass any value of a style property define a callback.
* editor.conversion.for( 'upcast' ).attributeToAttribute( {
* view: {
* styles: {
* 'line-height': /[\s\S]+/
* }
* },
* model: {
* key: 'lineHeight',
* value: viewElement => viewElement.getStyle( 'line-height' )
* }
* } );
*
* See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
* to the conversion process.
*
Expand Down

0 comments on commit 3d24d01

Please sign in to comment.