From 78a27adb9440730990d9710a04950b72a73c7df1 Mon Sep 17 00:00:00 2001
From: Cerdic <cedric@yterium.com>
Date: Sat, 10 Jun 2023 11:37:22 +0200
Subject: [PATCH] =?UTF-8?q?fix:=20calculer=20correctement=20les=20num?=
 =?UTF-8?q?=C3=A9ros=20de=20ligne=20des=20champs,=20y=20compris=20quand=20?=
 =?UTF-8?q?ils=20contiennent=20d'autres=20champs=20(ou=20boucles),=20ce=20?=
 =?UTF-8?q?qui=20n'=C3=A9tait=20pas=20le=20cas=20jusqu'ici=20(particuli?=
 =?UTF-8?q?=C3=A8rement=20probl=C3=A9matique=20en=20cas=20de=20champ=20#RE?=
 =?UTF-8?q?M=20long,=20mais=20aussi=20en=20cas=20de=20boucle=20imbriqu?=
 =?UTF-8?q?=C3=A9e=20dans=20une=20balise=20depuis=20SPIP=204)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 ecrire/public/phraser_html.php | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/ecrire/public/phraser_html.php b/ecrire/public/phraser_html.php
index c074c236b9..0f8f913aff 100644
--- a/ecrire/public/phraser_html.php
+++ b/ecrire/public/phraser_html.php
@@ -453,7 +453,7 @@ function phraser_arg(&$texte, $sep, $result, &$pointeur_champ) {
 function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) {
 	$res = [];
 	while (($p = strpos((string) $texte, (string) "%$sep")) !== false) {
-		if (!preg_match(',^%' . preg_quote((string) $sep, ',') . '([0-9]+)@,', substr((string) $texte, $p), $m)) {
+		if (!preg_match(',^%' . preg_quote((string) $sep, ',') . '([0-9]+)\n*@,', substr((string) $texte, $p), $m)) {
 			break;
 		}
 		$debut = substr((string) $texte, 0, $p);
@@ -522,7 +522,8 @@ function phraser_champs_interieurs(string $texte, int $no_ligne, string $sep) {
 			$champs_trouves[] = $champ;
 			$j = count($champs_trouves)-1;
 			// on remplace ce champ par un placeholder
-			$parties[] = "%$sep$j@"; // TODO : ajouter $nbl_champ retour ligne pour que la partie conserve le nombre de lignes
+			// ajouter $nbl_champ retour ligne pour que la partie conserve le nombre de lignes lors des itérations suivantes
+			$parties[] = ($t="%{$sep}{$j}" . str_repeat("\n", $nbl_champ). "@");
 			$nbl += $nbl_champ;
 
 			$texte = substr($texte, $poss[0] + strlen($match[0]));
-- 
GitLab