diff --git a/datamodel.combodo-webhook-integration.xml b/datamodel.combodo-webhook-integration.xml index 43f4fff..7f28b42 100644 --- a/datamodel.combodo-webhook-integration.xml +++ b/datamodel.combodo-webhook-integration.xml @@ -1749,26 +1749,22 @@ protected function ApplyParamsToJson(array $aContextArgs, string $sInputAsJson) } $aReplacementsMatrix = array( - array( array('
', '
', '
'), "\n" ), - array( array('

', '

'), array('*', '*') ), - array( array('

', '

'), array('*', '*') ), - array( array('

', '

'), array('*', '*') ), - array( array('', ''), array('*', '*') ), - array( array('', ''), array('*', '*') ), - array( array('', ''), array('_', '_') ), - array( array('', ''), array('_', '_') ), - array( array('', ''), array('~', '~') ), - array( array('', ''), array('~', '~') ), - array( array('
  • ', '
  • '), array('• ', '') ), - array( array('', ''), array('`', '`') ), - array( array('
    ', '
    '), array('```', '```') ), + [ '##i', "\n" ], + [ ['#

    #i', '#

    #i'], ['', "\n"] ], + [ ['##i', '##i'], ['*', "*\n"] ], + [ ['#<(strong|b)>#i', '##i'], '*' ], + [ ['#<(em|i)>#i', '##i'], '_' ], + [ ['#<(del|s)>#i', '##i'], '~' ], + [ ['#
  • #i', '#
  • #i'], ['• ', "\n"] ], + [ ['#
    (]*>)?#i', '#()?
    #i'], ['```', "```\n"] ], + [ ['#<(mark[^>]*|code)>#i', '##i'], '`' ], ); // Replace HTML tags (list must contain at least tags from the $aReplacementsMatrix) - $sContent = strip_tags($sContent, '


  • ');
    +		$sContent = strip_tags($sContent, '

  • ');
     		foreach($aReplacementsMatrix as $aReplacements)
     		{
    -			$sContent = str_replace($aReplacements[0], $aReplacements[1], $sContent);
    +			$sContent = preg_replace($aReplacements[0], $aReplacements[1], $sContent);
     		}
     
     		// Replace hyperlinks
    diff --git a/tests/php-unit-tests/ActionSlackNotificationTest.php b/tests/php-unit-tests/ActionSlackNotificationTest.php
    index e4f1bc4..04110df 100644
    --- a/tests/php-unit-tests/ActionSlackNotificationTest.php
    +++ b/tests/php-unit-tests/ActionSlackNotificationTest.php
    @@ -53,6 +53,30 @@ public function TransformHTMLToSlackMarkupProvider(): array
     HTML,
     				"expected" => "",
     			],
    +			"Simple p tags on different lines" => [
    +				"input" => <<hello

    hi

    +HTML, + "expected" => "hello\nhi\n", + ], + "Different tags on different lines" => [ + "input" => <<hello
  • hi

    +HTML, + "expected" => "*hello*\n*hi*\n", + ], + "Nested tags" => [ + "input" => <<I'm bold and

    I'm bold and italic

    +HTML, + "expected" => "*I'm bold and*\n_*I'm bold and italic*_\n", + ], + "Large text with different tags" => [ + "input" => <<Heading 1
  • Heading 2

    Heading 3

    Strong Text
    Bold Text
    Emphasized Text
    Italic Text
    Deleted Text
    Strikethrough Text
    Marked Text
    Inline Code

    Block of Code\r\nLine 1\r\nLine 2\r\n
    +HTML, + "expected" => "*Heading 1*\n*Heading 2*\n*Heading 3*\n*Strong Text*\n*Bold Text*\n_Emphasized Text_\n_Italic Text_\n~Deleted Text~\n~Strikethrough Text~\n`Marked Text`\n`Inline Code`\n• List Item 1\n• List Item 2\n```Block of Code\r\nLine 1\r\nLine 2\r\n```\n", + ], ]; } }