From e6ce2885c0b4586a270e0ace79598a92365df56f Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Tue, 6 Feb 2024 21:23:51 +0100 Subject: Fix: Keep indentation in html and md code blocks. Moves the logic for unwrapping broken lines in html (and Markdown) to the node processing, instead of doing it over the full html content. This allows us to skip if for code blocks (aka `` elements within `
` elements).
---
 tests/unit/includes/BBCodeTest.php   | 8 ++++++++
 tests/unit/includes/MarkdownTest.php | 4 ++++
 2 files changed, 12 insertions(+)

(limited to 'tests')

diff --git a/tests/unit/includes/BBCodeTest.php b/tests/unit/includes/BBCodeTest.php
index 54c35e67d..035bcbdc7 100644
--- a/tests/unit/includes/BBCodeTest.php
+++ b/tests/unit/includes/BBCodeTest.php
@@ -37,6 +37,10 @@ class BBCodeTest extends UnitTestCase {
 
 	private function html2bbcode_provider(): array {
 		return [
+			'paragraph over multiple lines' => [
+				"

A paragraph over\nmultiple lines\nshould be unwrapped

", + 'A paragraph over multiple lines should be unwrapped' + ], 'image with alt text' => [ 'Alt text', '[img=https://example.com/image.jpg]Alt text[/img]' @@ -45,6 +49,10 @@ class BBCodeTest extends UnitTestCase { "
some\ncode
", "[code]some\ncode[/code]" ], + 'code block with indentation' => [ + "
some\n    indented\ncode
", + "[code]some\n indented\ncode[/code]" + ], ]; } } diff --git a/tests/unit/includes/MarkdownTest.php b/tests/unit/includes/MarkdownTest.php index 8025e8efa..c51fbfe16 100644 --- a/tests/unit/includes/MarkdownTest.php +++ b/tests/unit/includes/MarkdownTest.php @@ -77,6 +77,10 @@ class MarkdownTest extends UnitTestCase { "[code]some code\nover multiple lines[/code]", "```\nsome code\nover multiple lines\n```" ], + 'code block no language indented' => [ + "[code]some code\n over multiple lines\n with indentation[/code]", + "```\nsome code\n over multiple lines\n with indentation\n```" + ], ]; } -- cgit v1.2.3