HubSpot / draft-convert

Extensibly serialize & deserialize Draft.js ContentState with HTML.
Apache License 2.0
484 stars 94 forks source link

Match ordered list styling from draft-js editor when converting to HTML #170

Closed maxwellskala closed 4 years ago

maxwellskala commented 4 years ago

draft-js strips standard ordered list styling using CSS and applies its own list indices using :before pseudo-elements. These indices match type attributes that can be applied to <ol /> elements, but convertToHTML does not currently apply these type attributes when converting nested ordered lists.

This PR applies the type attribute based on list depth so that HTML-serialized Draft content more closely matches what the editor renders.

dav-sap commented 4 years ago

Any reason why this is not working for me? I updated the package and see the updated code, but i don't get a type on the <ol> at all. this is my blockToHTML code

blockToHTML: (block) => {
            if (block.type.includes('unstyled') && block.text === '') {
                return <br />;
            }
            if (block.type.includes('align')) {
                return alignToElement[block.type];
            }
            return undefined;
        },

it falls on the undefined meaning convertToHTML will take care of it, but i only get new <ol> no type in them.