Files
wekan/models/lib/descriptionListItems.js
T
Lauri Ojansivu 3cb089b8ca Checklist from description, action items, and search phrases.
The last three of the features other kanban apps call AI, done with plain
code (docs/Features/General/Assistants/Assistants.md):

- Checklists -> From description: the list lines of a card's description
  ("- ", "* ", "1. ", task boxes; never inside code blocks) previewed, then
  made into a checklist - ticked where the line was [x] - or into subtasks
  through addSubtaskCard.
- Create cards from action items, on a comment and in the card menu for its
  description: "TODO: ...", "- [ ] ..." and "@user ..." lines become cards
  at the top of the card's list, linking back to it, with the mentioned
  user as member when they are an active board member.
- Global search understands plain phrases in the reader's language - "my
  overdue cards", "due this week", "unassigned cards" and seven more - and
  runs them as its operators, saying which; a query with an operator in it
  is never rewritten.

Checklist from description and Action items are Show on Card rows of Board
Settings / Card and of the Admin Panel's Card fields; Search phrases is an
Admin Panel / Settings / Visibility / Features tick. Translated in every
language.

Thanks to xet7 !
2026-10-17 16:25:51 +03:00

38 lines
1.3 KiB
JavaScript

'use strict';
// Checklist or subtasks from a card's description
// (docs/Features/Cards/Checklist-From-Description.md): the list lines of the
// Markdown - Trello's "generate checklist" and Jira's "break down", here the
// lines the author already wrote as a list.
//
// Pure, no Meteor. Tests: tests/descriptionListItems.test.cjs.
const MAX_ITEMS = 100;
const MAX_TITLE = 500;
const FENCE = /^\s*(```|~~~)/;
// "- item", "* item", "+ item", "1. item", "1) item", each optionally with a
// task box, or a bare task box "[ ] item".
const ITEM = /^\s*(?:[-*+]|\d{1,4}[.)])\s+(?:\[([ xX])\]\s+)?(.+?)\s*$/;
const BOX = /^\s*\[([ xX])\]\s+(.+?)\s*$/;
// [{ title, checked }] in the order written.
function descriptionListItems(markdown) {
const out = [];
let inFence = false;
for (const line of String(markdown || '').split(/\r?\n/)) {
if (FENCE.test(line)) { inFence = !inFence; continue; }
if (inFence) continue;
const m = ITEM.exec(line) || BOX.exec(line);
if (!m) continue;
const [, box, text] = m;
const title = text.trim().slice(0, MAX_TITLE);
if (!title) continue;
out.push({ title, checked: box === 'x' || box === 'X' });
if (out.length >= MAX_ITEMS) break;
}
return out;
}
module.exports = { MAX_ITEMS, descriptionListItems };