CKEditor 5 – Help preserving styles on list

I am implementing CKEditor 5 into a website I am developing. I have some existing content which contains some styles that I would like the editor to preserve. I have read up on quite a few tutorials and posts and can't seem to get it working. Hoping someone can push me in the right direction.

The HTML I am editing contains the following:

<li style="list-style-type:none;">No number</li>

Below is the function I am calling. This was modified from one that preserved font sizes.

        function TestListStyle( editor ) {
            editor.conversion.for( 'upcast' ).elementToAttribute( {
                view: {
                    name: 'li',
                    styles: {
                        'list-style-type': /[\s\S]+/
                    }
                },
                model: {
                    key: 'listStyleType',
                    value: viewElement => {
                        const value = viewElement.getStyle( 'list-style-type' );
                        return value;
                    }
                },
                converterPriority: 'high'
            } );

            editor.conversion.for( 'downcast' ).attributeToElement( {
                model: {
                    key: 'listStyleType'
                },
                view: ( modelValue, { writer: viewWriter } ) => {
                    return viewWriter.createAttributeElement( 'li', {
                        style: `list-style-type:${ modelValue }`
                    } );
                },
                converterPriority: 'high'
            } );
        }

When I attempt to run this I get JavaScript TypeError Cannot read 'start' of null I can't seem to figure out such a simple thing. Any help is appreciated.



Read more here: https://stackoverflow.com/questions/67386706/ckeditor-5-help-preserving-styles-on-list

Content Attribution

This content was originally published by MPIIIMan at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: