-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
List nesting/indent HTML is not semantic #979
Comments
I would also really like to have @jhchen’s thoughts on this. The Cloning Medium with Parchment guide states the following:
I assume due the lack of support for Block blots nesting, nested lists (as well as nested blockquotes) cannot currently be implemented even with custom Parchment blots, is that correct? |
Here's what puzzles me - List actually inherits from Container, rather than from Block - I assume that's how Lists can contain ListItems. I have tried and tried to create a CustomList that includes CustomList in its allowedChildren, but I haven't been able to get it to work :( In other words, I want this: <ul class="nugget" nuggetid="1">
<li>An item in the outer list</li>
<ul class="nugget" nuggetid="2">
<li>An item in the inner list</li>
</ul>
</ul> But no matter how hard I try, Quill ends up modifying that to: <ul class="nugget" nuggetid="1">
<li>An item in the outer list</li>
</ul>
<ul class="nugget" nuggetid="1">
<li>An item in the inner list</li>
</ul> [Note that it also mangles the second For reference, this is the javascript behind that: 'use strict';
import Quill from 'quill';
let Parchment = Quill.import ('parchment');
let List = Parchment.query('list');
let NuggetidAttributor = new Parchment.Attributor.Attribute('nuggetid', 'nuggetid', {
});
class NuggetList extends List {
format(name, value) {
this.domNode.setAttribute('nuggetid', value);
}
}
NuggetList.tagName = 'UL';
NuggetList.className = 'nugget';
NuggetList.allowedChildren.push(NuggetList);
Quill.register(NuggetidAttributor);
Quill.register(NuggetList, true); If anybody has got this to work, I would love to hear from them. |
@rafbm Yes the Blocks are a challenge but using Containers might be a solution but I have not thought about this rigourously. @JoshuaDoshua By export do you mean paste into other applications? |
@jhchen Yessir. Essentially just using the Containers does seem promising. But this is definitely a complicated topic. Indenting needs to be aware of above list elements. An interesting note though: The core currently recognizes if you try to apply a list to a new line directly after a list. |
I also think the output of nested lists is less than ideal, but if we could have a css file with listing styles to make lists look the same as in the editor, maybe it would help initially. |
Is there some news about this enhancement? |
Using pseudo classes to accomplish nested lists prevents using Quill as a composer for anything that will be sent in email (as email clients do not allow the use of pseudo classes). |
@parterburn This is exactly my problem as well, forcing me to pre-parse content and adding actual numbering, which is very inconvenient |
@AnrichVS What is your strategy for getting the code back into the editor? Rewriting back to the ql-indent class structure? I'm currently exploring this, as like you and @parterburn, we use the output in html emails and other places. CSS isn't really a solution. I'm considering writing up a parser that translates the ql-indent li tags into nested uls/ols, etc. Unfortunately, it looks like I'd also have to write the reverse, as pasting nested lists into the editor gives me a flat list every time. So I'd have to rewrite the correct nest back into ql-indented code. Not something I'm really looking forward to, as it addresses a bit of an edge case, but does look noticeably wrong when a nested ol with numbers and letters gets flattened into one long ol. |
We ended up preventing ordered lists from indenting more than once and set the margin-left on unordered lists according the different indent-classes using a premailer stylesheet (https://rubygems.org/gems/premailer-rails). |
Haha, pretty much what I'm in the process of doing now. Except I think we are nixing the ordered lists instead of trying to limit them to the parent level. Thanks for the feedback! |
Here's our code, if it's helpful: var bindings = {
"indent": {
key: "tab",
format: ["list"],
handler: function(range, context) {
if(context.format.list == "ordered") {
return false;
} else {
if (context.collapsed && context.offset !== 0) return true;
this.quill.format('indent', '+1', Quill.sources.USER);
}
}
}
};
var emailBodyQuill = new Quill($(".email-body-quill"), {
theme: 'snow',
modules: {
keyboard: {
bindings: bindings
},
toolbar: {
container: [
[{ 'size': ['small', false, 'large', 'huge'] }],
['bold', 'italic', 'underline', 'link'],
[{ 'list': 'ordered' }, { 'list': 'bullet' }, 'blockquote'],
['clean', 'image']
]
}
}
}); |
I've just come across this problem too. I'm trying to create PDFs of the editor contents using mPDF, which doesn't support the CSS needed on li's to do it the current Quill.js way. This means that all nested lists have the same level of indentation as the parent, and the numbering on ordered lists is not reset for nested lists (i.e. the numbering continues sequentially for every li in the group of lists). mPDF does allow setting these on ul's/ol's, so if the indented lists were wrapped in ol or ul, then all would work properly. Instead I need to write a parser to manually identify and wrap each level (a job I think I'll put off until tomorrow!). |
@arist0tl3 I had to put this on hold for quite some time as you can see. My main problem is that I send emails containing Quill created content. On the web side of things all is well, but for emails I use premailer-rails to convert all CSS to inline (to support as many mail clients as possible). And you can't have pseudo selectors ( Thus my plan was, and probably still is, to parse the mails with an interceptor and add actual numbers into the HTML. The indentation CSS works fine inline so I don't have a problem with that, it's just the numbering. I guess if I don't want multiple levels of numbering (1.1, 1.1.1 etc.), converting the I was really hoping some progress has been made on this since my last struggle... |
@AnrichVS Agreed. We still haven't figured out a way to handle the numbering in a consistent manner. Currently, we are just restricting the usage of lists to a single level. Not a great user experience, but we still prefer it to nested lists with broken styles and numbering in our emails. I toyed with the idea of hooking into the indent code above to write the structure of the current node into an html attribute that could be parsed later to re-write the innerHTML and css, but just couldn't justify putting too much time towards it. I do think that leveraging the indent function to add some useful data to the element is a viable strategy, but again, just can't justify the cost/benefit right now. |
Well if I paste from Google Docs to Quill, pretty much everything in a "normal and simple" document is conserved, except the nesting of lists, as requested in this old feature request: "Add support for nested lists/bullets and indents #118" dating back to May 2014. It's right now the only lack of feature that prevents me from using Quill in production. A list element is relative to a The actual fix of using "ql-indent" class isn't fixing anything but the visual. But html is more than a visual, have you every though about how blind people see your documents? You can't remove nesting, it's removing meaning, so it can't be allowed. |
I'm fairly new to Quill. But I saw there are a couple tickets that point here, some with discussion whether this is a personal preference or a technical requirement. My statements below support technical requirement and present supporting W3 materials. In Ontario, a province in Canada, there is legislation for all public institutions and private companies with 50+ employees to have websites and web products be WCAG 2.0 level A compliant today, and by 2021 level AA compliant. There are many other jurisdictions around the world with similar laws and deadlines Eg. US DoJ section 508 law. Jurisdiction laws aside, we should want to remove barriers to participation online for screenreader and keyboard navigation users, and nested lists are interpreted and navigated differently. eg. skip list or sublist/next. As @thomasgodart pointed out, in v1.3.5 of Quill, ql-indent-* classes do not provide the content structure needed for accessibility users. That said, here are technical references by W3 about nested lists: |
The following is the code I came up with the convert the quill style lists into "proper" ol/ul nested lists. Note that this is very hacky code, and will be brittle if quill changes its html rendering. It works on the HTML that Quill currently renders in most browsers (grabbed by .innerHTML or similar). It (obviously) won't work on documents stored as deltas, and may fail if any other processing has altered the structure of the HTML. I use this only when rendering to another format (pdf via MPDF, or non-interactive HTML), storing the unchanged quill document as normal for future editing. That said, it seem reliable in my use case, an electron app. It uses jquery on a hidden div (to map the html to a dom), you can probably get it to work in node using jsdom or similar. It works on ul, li and mixed combinations. It deals with edge cases like starting a list indented beyond level 0. I hope this helps someone.
|
@RobAley, thanks so much for your solution, I found it very helpful. For anyone else who needs this and is not using jQuery, here's my ES6 version of Rob's code with a few minor tweaks (all of Rob's caveats apply to this code as well):
Cheers,
|
Here is what is expected when handling lists: https://codepen.io/jasonrundell/pen/zjZrjq Right now, Quill's lists are not expected behaviour in terms on DOM markup and this creates issues with accessibility and end users who are making lists and not seeing nested lists. Right now my workaround is a CSS hack with ql-indent-X which is creating a dependency on the Editor when the markup needs to be decoupled from Quill logic. Also, I can't hack around the fact that the index of the list items won't be correct as I won't be able to modify publisher content every time they add a new list. |
Hi, anyone making progress on this? It's too bad there's this discussion because I strongly believe the output of a WYSIWYG editor should be semantically correct (same goes for soft enters). We use Quill for editing emails, which means the ability to style elements is limited. |
I think the 'bug' label should be added to this issue. This is a matter of 'semantically correctness', but also of WYSIWYG. |
Ping @jhchen. Please mark this issue as a bug. |
I am new to use quill editor and facing issue while copying nested bullets content from MS word doc. Content loses nested bullets and indentation. Can any one help on this? |
I just started adding Quill to a project expecting it was the most used/best editor to use. Then I quickly ran into this issue. Now given how long this issue has been open I'm wondering if I should just switch to something else before it's too late. |
@JurajKavka @Daenero what is the status of this ticket? |
I implemented the fix by @Daenero but I experience the problem of users double indenting list items, which didn't get decoded right. To prevent the double tabbing I limited the indenting of list items with a custom handler for the Tab event in the Quill options. Might be handy for someone else :) keyboard: {
bindings: {
indent: {
key: 9,
format: ['blockquote', 'indent', 'list'],
handler: function (this: any, range: any) {
// We want to disable the indentation if:
// - (1) The current line is the first line and the indent level is 0 (not indented)
// - (2) The current line is a list and the previous line is not a list
// - (3) The current line is a list and the previous line too, but the previous lines indentation level is already one level lower
const currentLineFormats = this.quill.getFormat(
range.index
)
const previousLineFormats =
this.quill.getFormat(range.index - 1)
const currentLineIsTheFirstLine =
range.index === 0
const currentLineIsAList =
currentLineFormats.list !== undefined
const previousLineIsAList =
previousLineFormats.list !== undefined
const currentLineIndent =
currentLineFormats.indent || 0
const previousLineIndent =
previousLineFormats.indent || 0
if (
(currentLineIsTheFirstLine &&
currentLineIndent === 0) ||
(currentLineIsAList &&
!previousLineIsAList) ||
(currentLineIsAList &&
previousLineIsAList &&
previousLineIndent ===
currentLineIndent - 1)
) {
return
}
this.quill.format(
'indent',
'+1',
Quill.sources.USER
)
},
},
},
}, |
you saved a lot of debuggin time. Thanks @Daenero |
3 more year and we're at a decade. |
Damn, Quill's inability to handle bulleted lists properly is a major flaw. |
Will Quill 2 solve the problem of nested lists? https://github.com/quilljs/quill/releases/tag/v2.0.0-beta.0 |
I've just replaced my google editor with Quill. It was looking good however I've just come across this issue in testing, unfortunately not being able to have true nested lists is a deal breaker for me. Its back to google or find a better alternative. Please fix this in release 2.0. |
Here is a good workaround: https://github.com/nozer/quill-delta-to-html |
This custom clipboard matchers fixed the issue on my side. Thanks to Subtletree on this issue: #1225 const Delta = Quill.import('delta');
function matchMsWordList(node, delta) {
// Clone the operations
let ops = delta.ops.map((op) => Object.assign({}, op));
// Trim the front of the first op to remove the bullet/number
let bulletOp = ops.find((op) => op.insert && op.insert.trim().length);
if (!bulletOp) { return delta }
bulletOp.insert = bulletOp.insert.trimLeft();
let listPrefix = bulletOp.insert.match(/^.*?(^·|\.)/) || bulletOp.insert[0];
bulletOp.insert = bulletOp.insert.substring(listPrefix[0].length, bulletOp.insert.length).trimLeft();
// Trim the newline off the last op
let last = ops[ops.length-1];
last.insert = last.insert.substring(0, last.insert.length - 1);
// Determine the list type
let listType = listPrefix[0].length === 1 ? 'bullet' : 'ordered';
// Determine the list indent
let style = node.getAttribute('style').replace(/\n+/g, '');
let levelMatch = style.match(/level(\d+)/);
let indent = levelMatch ? levelMatch[1] - 1 : 0;
// Add the list attribute
ops.push({insert: '\n', attributes: {list: listType, indent}})
return new Delta(ops);
}
function maybeMatchMsWordList(node, delta) {
if (delta.ops[0].insert.trimLeft()[0] === '·') {
return matchMsWordList(node, delta);
}
return delta;
}
const MSWORD_MATCHERS = [
['p.MsoListParagraphCxSpFirst', matchMsWordList],
['p.MsoListParagraphCxSpMiddle', matchMsWordList],
['p.MsoListParagraphCxSpLast', matchMsWordList],
['p.MsoListParagraph', matchMsWordList],
['p.msolistparagraph', matchMsWordList],
['p.MsoNormal', maybeMatchMsWordList]
];
// When instantiating a quill editor
let quill = new Quill('#editor', {
modules: {
clipboard: { matchers: MSWORD_MATCHERS }
},
placeholder: 'Compose an epic...',
theme: 'snow'
}); |
@luin Do you know whether there is any progress being made on this issue? It the second highest upvoted issue on this repo after all. |
It's worth noting that you can use |
Upgrading to Quill v2.0.0-rc.2 fixed the issue on my side. |
@timotheedorand Did you add some config to get the proper lists in this version? I've just upgraded to version Quill v2.0.0-rc.3, but no changes, still getting flat lists. |
Nothing specific, I've took the React Code they provide on the playground: https://quilljs.com/playground/react |
Yes, if you paste from Word it works well, but it works bad when pasting to word, or trying to use Quill's html in other pages/emails. |
@ivanShagarov indeed, from Quill to Word doesn't work natively. I fixed this by using // Editor.js
quill.on(Quill.events.TEXT_CHANGE, () => {
onTextChangeRef.current?.(quill.getSemanticHTML());
}); |
When you copy content from Quill, semantic HTML is copied instead of just the innerHTML of the editor. Actually Quill internally calls the |
@timotheedorand @luin Thank you guys! quill.getSemanticHTML() did the job :) |
Indent behavior could be improved.
Indenting a list item should wrap the current list item in a new
<ul><li>
or<ol><li>
and nest it in the closest<li>
tag (or do nothing if you are at the highest level or there is only one item in the list)The current indent button simply adds a class to the
<li>
, which looks great but outputs bad HTML. The generated content would not be exportable to other platforms.v1.0.3
This seems a bit more complicated than a simple fix. If I have time I'll try to get a PR in, but wanted to get the topic open for discussion
The text was updated successfully, but these errors were encountered: