fix(clipboard): add support for notion and github-flavored markdown checklist formats
- detect `to-do-list` (Notion) and `task-list` (GitHub MD) classes as checklist containers - handle notion `<div class="checkbox-on/off">` as checkbox indicator in list items - update README to document newly recognized HTML tags for checklist input
This commit is contained in:
@@ -244,7 +244,7 @@ Le presse-papier transporte deux MIME en parallèle : `text/html` (structure
|
||||
sélectionnés.
|
||||
|
||||
Tags HTML reconnus en entrée : `<h1>`–`<h6>`, `<p>`, `<ul>/<ol><li>`,
|
||||
`<ul data-checklist>` ou `<li>` contenant `<input type="checkbox">`,
|
||||
`<ul data-checklist>`, `<ul class="to-do-list">` (Notion), `<ul class="task-list">` (GitHub-flavored markdown), ou `<li>` contenant `<input type="checkbox">` ou `<div class="checkbox checkbox-on/off">` (Notion),
|
||||
`<blockquote>`, `<pre>`, `<code>`, `<hr>`, `<figure>`, `<img>`, plus
|
||||
toutes les marks de `domToInline` (`<strong>/<b>`, `<em>/<i>`, `<u>`,
|
||||
`<s>/<strike>/<del>`, `<code>`, `<a href>`, `<span data-color>` /
|
||||
|
||||
@@ -255,17 +255,28 @@ function hasBlockDescendant(el) {
|
||||
}
|
||||
|
||||
function parseList(listEl, ordered, out) {
|
||||
const isChecklist = listEl.hasAttribute('data-checklist');
|
||||
// Détection « liste de cases à cocher » : data-checklist (export interne),
|
||||
// ou class="to-do-list" (Notion), ou class contenant "task-list" (GitHub-flavored markdown).
|
||||
const listClass = listEl.getAttribute('class') || '';
|
||||
const isChecklist =
|
||||
listEl.hasAttribute('data-checklist') ||
|
||||
/\b(to-do-list|task-list|checklist)\b/i.test(listClass);
|
||||
for (const li of listEl.children) {
|
||||
if (li.tagName !== 'LI') continue;
|
||||
// Détection checkbox (héritée du data-checklist OU d'un <input type=checkbox>
|
||||
// dans le <li>, à la Markdown task list).
|
||||
const checkbox = li.querySelector(':scope > input[type="checkbox"]');
|
||||
// Détection checkbox au niveau item :
|
||||
// - <input type="checkbox"> direct child (GitHub task list, export interne)
|
||||
// - <div class="checkbox"> direct child (Notion : checkbox-on / checkbox-off)
|
||||
const inputCb = li.querySelector(':scope > input[type="checkbox"]');
|
||||
const divCb = li.querySelector(':scope > div.checkbox, :scope > div[class*="checkbox"]');
|
||||
const checkbox = inputCb || divCb;
|
||||
const isChecklistItem = isChecklist || !!checkbox;
|
||||
let checked = false;
|
||||
if (checkbox) {
|
||||
checked = checkbox.checked || checkbox.hasAttribute('checked');
|
||||
checkbox.remove();
|
||||
if (inputCb) {
|
||||
checked = inputCb.checked || inputCb.hasAttribute('checked');
|
||||
inputCb.remove();
|
||||
} else if (divCb) {
|
||||
checked = /checkbox-on/.test(divCb.getAttribute('class') || '');
|
||||
divCb.remove();
|
||||
}
|
||||
|
||||
// Si le <li> contient lui-même des sous-listes, on émet d'abord un
|
||||
|
||||
Reference in New Issue
Block a user