From 481e08b904313b768305d82b67f5f8602713b329 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 8 May 2024 15:41:54 +0000 Subject: remove p tags from li. otherwise we will get unwanted new lines in the list. add test. --- include/html2bbcode.php | 5 +++++ tests/unit/includes/BBCodeTest.php | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/include/html2bbcode.php b/include/html2bbcode.php index db8f3a8e0..8c35cdf03 100644 --- a/include/html2bbcode.php +++ b/include/html2bbcode.php @@ -126,8 +126,13 @@ function html2bbcode($message) //$message = mb_convert_encoding($message, 'HTML-ENTITIES', "UTF-8"); $message = mb_encode_numericentity($message, [0x80, 0x10FFFF, 0, ~0], 'UTF-8'); + // TODO: It would be better to do the list parsing with node2bbcode() but it has serious issues when + // parsing nested lists. Especially if the li tag has no closing tag (which is valid). + $message = preg_replace('/\/', '[list]', $message); $message = preg_replace('/\/', '[list=1]', $message); + + $message = str_replace(['
  • ', '

  • '], ['
  • ', '
  • '], $message); $message = preg_replace('/\/', '[*]', $message); $message = str_replace(['', ''], '[/list]', $message); $message = str_replace('', '', $message); diff --git a/tests/unit/includes/BBCodeTest.php b/tests/unit/includes/BBCodeTest.php index 887374c13..94cad1367 100644 --- a/tests/unit/includes/BBCodeTest.php +++ b/tests/unit/includes/BBCodeTest.php @@ -239,6 +239,10 @@ class BBCodeTest extends UnitTestCase { '
    • list 1
    • list 2
    • list 3
    ', '[list][*]list 1[*]list 2[*]list 3[/list]' ], + 'list with paragraph' => [ + '
    • list 1

    • list 2

    • list 3

    ', + '[list][*]list 1[*]list 2[*]list 3[/list]' + ], 'nested list' => [ '
    • list 1
    • list 2
    • list 3
      • list 1
      • list 2
      • list 3
    ', '[list][*]list 1[*]list 2[*]list 3[list][*]list 1[*]list 2[*]list 3[/list][/list]' -- cgit v1.2.3