assertEquals($expected, markdown_to_bb($src, true, ['preserve_lf' => true]));
}
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 is not as expected in markdown, but may be needed
// for compatibility with bbcode behaviour.
"This text is\ntext wrapped\nover multiple\nlines.",
"This text is\ntext wrapped\nover multiple\nlines."
],
'text with hard linebreak' => [
// An extra line break is inserted here...
"Line one\n\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' => [
// Not sure if the newline should be preseved here?
"[code]some code\nunwrapped[/code]",
"`some code\n unwrapped`"
],
'code block no language' => [
"[code]some code\nover multiple lines\n[/code]",
"```\nsome code\nover multiple lines\n```"
],
'code block no language indented' => [
// For some reason one space char is eaten on indented lines.
"[code]some code\n over multiple lines\n with indentation\n[/code]",
"```\nsome code\n over multiple lines\n with indentation\n```"
],
'code block with language' => [
"[code=php]<?php\necho phpinfo();\n[/code]",
"```php\n [
"[code]an example url https://example.com\n[/code]",
"```\nan example url https://example.com\n```"
],
'bbcode code block with URL' => [
"[code]\nproxy_pass http://example.com;\n[/code]",
"[code]\nproxy_pass http://example.com;\n[/code]"
],
'naked url followed by newline' => [
"https://example.com\nhave a great day.",
"https://example.com\nhave a great day.",
],
'inline naked url' => [
'This is a link https://example.com/some/path more info.',
'This is a link https://example.com/some/path more info.',
],
];
}
/**
* @covers ::html2markdown
* @dataProvider html2markdownProvider
*/
public function testHtml2markdown(string $html, string $markdown): void {
$this->assertEquals($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' => [
'
somethingblah', "> something\n\nblah" ], 'code' => [ '
<p>HTML text</p>
',
'`HTML text
`' ], 'pre' => [ 'one line with spaces', "```\n one line with spaces \n```" ], 'div p' => [ '
p