Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it compatible with @editorjs/list #15

Open
taurenshaman opened this issue Mar 29, 2021 · 4 comments · May be fixed by #39
Open

Make it compatible with @editorjs/list #15

taurenshaman opened this issue Mar 29, 2021 · 4 comments · May be fixed by #39
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@taurenshaman
Copy link

update Line 106 in the constructor:

        //this.data = data && Object.keys(data).length ? data : initialData;
        this.data = initialData;
        if(data && data.items && data.items.length > 0){
            this.data.style = data.style;
            const item0 = data.items[0];
            if(typeof item0 === "object")
                this.data.items = data.items;
            else { // compatible with @editorjs/list
                const items = [];
                data.items.forEach(di => {
                    items.push({
                        content: di,
                        items: []
                    });
                });
                this.data.items = items;
            }
        }
@dfrankow
Copy link
Contributor

I'm not involved in development, but .. what is "compatible with"? You're suggesting a code change, but I don't understand the advantage of the code change.

@taurenshaman
Copy link
Author

I'm not involved in development, but .. what is "compatible with"? You're suggesting a code change, but I don't understand the advantage of the code change.

The key is the difference between @editorjs/list and editor-js/nested-list.
I have already used @editorjs/list in my website. So if I wanna support nested-list instead of @editorjs/list, I must make sure the editor can also display the old data (in @editorjs/list format) correctly.
The code above will upate the old data in @editorjs/list format to editor-js/nested-list format.

@dfrankow
Copy link
Contributor

Well that sounds pretty useful.

@cmeeren
Copy link

cmeeren commented Jul 31, 2024

As described in #75 (comment), I take issue with this approach, and would urge to keep in mind other usages of editor.js documents than just editor.js itself.

One clear advantage of a block-based format over plain (sanitized, white-listed) HTML, and indeed the reason we went for a block-based format, is that the data format is well-known and fairly limited, making it easier for other tools than editor.js itself to parse the content and format it for other contexts.

For example, our back-end converts editor.js documents for display in Excel cells (plain-text with simple "formatting" such as prepending bullet points with *), to extract the plain text only for search indexing, and render PDF files.

This parsing becomes much more difficult if, for any given type discriminator, different incompatible schema are used. While it is possible to work with, we then have to drop down from a nice, strongly-typed deserialization-based API to a much more verbose and bug-prone JSON-token based API.

My proposal would be to use another type value, such as list2, nested-list, or similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants