feat(notes): commandes sur plusieurs lignes recollees en une seule
Fin de ligne en \ (bash), ` (PowerShell) ou ^ (cmd) : la ligne suivante est rattachee, et la commande part sur une ligne - un retour a la ligne tape dans un terminal la lancerait a moitie ecrite. Teste. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4038,15 +4038,26 @@ const ENTRY_TEMPLATES = {
|
||||
// DECOUPE D'UNE NOTE DE COMMANDES. "# titre" ouvre un groupe, toute autre ligne
|
||||
// non vide est une commande, les lignes vides sont ignorees. Rend
|
||||
// [{group, cmd}] dans l'ordre du texte. Pur : tests/commands.test.js.
|
||||
// LIGNE CONTINUEE : une ligne finie par \ (bash), ` (PowerShell) ou ^ (cmd)
|
||||
// se recolle a la suivante, sans le caractere ni le retour a la ligne. Le
|
||||
// resultat tient sur UNE ligne : tapee dans un terminal, une fin de ligne vaut
|
||||
// Entree et lancerait une commande a moitie ecrite. Une ligne vide ou la fin du
|
||||
// texte termine la commande en cours.
|
||||
function parseCommandNote(text) {
|
||||
const out = [];
|
||||
let group = '';
|
||||
let pending = '';
|
||||
const flush = () => { if (pending) out.push({ group, cmd: pending }); pending = ''; };
|
||||
for (const raw of String(text || '').split(/\r?\n/)) {
|
||||
const line = raw.trim();
|
||||
if (!line) continue;
|
||||
if (line.startsWith('#')) { group = line.replace(/^#+\s*/, ''); continue; }
|
||||
out.push({ group, cmd: line });
|
||||
if (!line) { flush(); continue; }
|
||||
if (!pending && line.startsWith('#')) { group = line.replace(/^#+\s*/, ''); continue; }
|
||||
const cont = /[\\`^]$/.test(line);
|
||||
const part = cont ? line.slice(0, -1).trimEnd() : line;
|
||||
pending = pending ? pending + ' ' + part : part;
|
||||
if (!cont) flush();
|
||||
}
|
||||
flush();
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user