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

Non-deterministic order of formats applied results in inconsistent HTML #260

Closed
thomsbg opened this issue Nov 25, 2014 · 2 comments
Closed

Comments

@thomsbg
Copy link
Contributor

thomsbg commented Nov 25, 2014

Adding multiple formats to a range of text requires looping through the attributes object. The order of key/value pairs yielded from a for in loop is not defined, which means that the resulting HTML can have different nesting of tags.

e.g. quill.setContents([ insert: 'abc', attributes: { bold: true, italic: true } })

can result in: <b><i>abc</i></b> or <i><b>abc</b></i>, depending on the weather.

This inconsistent behavior can also be observed by just using the toolbar or hotkeys. Select a range of text, and then apply 'bold', then 'italic'. You will see <b><i>abc</i></b>. Then, select a different range, and apply 'italic', then 'bold'. You will see <i><b>def</b></i>.

Ideally, the order in which you apply formats should not affect the resulting HTML. This is not such a big deal when it's just bold and italic, but I would always like the link format applied last, so that a document like

[
{ insert: 'abc', attributes: { link: 'x' } },
{ insert: 'def', attributes: { link: 'x', bold: true } },
{ insert: 'xyz', attributes: { link: 'x' } }
]

always results in HTML like: <a href="x">abc<b>def</b>xyz</a>,
instead of <a href="x">abc</a><b><a href="x">def</a></b><a href="x">xyz</a>.

The normalizer should be able to rearrange the resulting HTML to nest tags in a specific order.

@jhchen
Copy link
Member

jhchen commented Nov 26, 2014

Related #61

@jhchen
Copy link
Member

jhchen commented May 15, 2016

This has been fixed in the 1.0 beta release.

@jhchen jhchen closed this as completed May 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants