assertEquals($expected, markdown_to_bb($src)); } public static function markdown_to_bbcode_provider(): array { return [ 'empty text' => [ '', '' ], 'plain text' => [ 'This is a test', 'This is a test' ], 'bold and italic' => [ 'This is a test of [b]bold text[/b], [i]italic text[/i] and [b][i]bold and italic text[/i][/b]', 'This is a test of **bold text**, *italic text* and ***bold and italic text***' ], 'multiline text' => [ 'This text is text wrapped over multiple lines.', "This text is\ntext wrapped\nover multiple\nlines." ], 'text with hard linebreak' => [ "Line one\nLine two", "Line one \nLine two" ], 'paragraphs' => [ "Paragraph one\n\nParagraph two", "Paragraph one\n\nParagraph two", ], 'inline image' => [ '[img=https://example.com/image.jpg]https://example.com/image.jpg[/img]', '![](https://example.com/image.jpg)' ], 'inline image with alt text' => [ '[img=https://example.com/image.jpg]Alt text[/img]', '![Alt text](https://example.com/image.jpg)' ], 'inline code' => [ '[code]some code[/code]', '`some code`' ], 'inline code with wrapped text' => [ '[code]some code unwrapped[/code]', "`some code\n unwrapped`" ], 'code block no language' => [ "[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```" ], 'code block with language' => [ "[code=php]<?php\necho phpinfo();[/code]", "```php\nassertEquals($markdown, html2markdown($html)); } public static function html2markdownProvider(): array { return [ 'empty text' => [ '', '' ], 'space and nbsp only' => [ '  ', '' ], 'strong, b, em, i, bib' => [ 'strong bold em italic boitalicld', '**strong** **bold** *em* *italic* **bo*italic*ld**' ], 'empty tags' => [ 'text1 text2 ', 'text1 text2' ], 'HTML entities' => [ '& gt > lt <', '& gt > lt <' ], 'escaped HTML entities' => [ '& lt < gt >', '& lt < gt >' ], 'linebreak' => [ "line1
line2\nline3", "line1 \nline2 line3" ], 'headlines' => [ '

header1

Header 3

', "header1\n=======\n\n### Header 3" ], 'unordered list' => [ '', "- Item 1\n- Item 2\n- Item **3**" ], 'ordered list' => [ '
  1. Item 1
  2. Item 2
  3. Item 3
', "1. Item 1\n2. Item 2\n3. Item **3**" ], 'nested lists' => [ '', "- Item A\n- Item B\n - Nested A\n - Nested B\n- Item C" ], 'img' => [ 'alt text', '![alt text](/path/to/img.png "title text")' ], 'link' => [ 'link', '[link](http://hubzilla.org "Hubzilla")' ], 'img link' => [ 'alt img text', '[![alt img text](/img/hubzilla.png "img title")](http://hubzilla.org "Hubzilla")' ], 'script' => [ "", "" ], 'blockquote, issue #793' => [ '
something
blah', "> something\n\nblah" ], 'code' => [ '<p>HTML text</p>', '`

HTML text

`' ], 'pre' => [ '
  one line with spaces  
', "```\n one line with spaces \n```" ], 'div p' => [ '
div

p

', "
div
p\n\n
" ] ]; } public function test_bb_to_markdown(): void { $input = "test[b]bold[/b]\n[i]i[/i][ul][li]li1[/li][li]li2[/li][/ul]\n"; $expected = "test**bold** \n*i*\n\n- li1\n- li2"; $this->assertEquals($expected, bb_to_markdown($input)); } }