Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions datamodel.combodo-webhook-integration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1749,26 +1749,22 @@ protected function ApplyParamsToJson(array $aContextArgs, string $sInputAsJson)
}

$aReplacementsMatrix = array(
array( array('<br />', '<br/>', '<br>'), "\n" ),
array( array('<h1>', '</h1>'), array('*', '*') ),
array( array('<h2>', '</h2>'), array('*', '*') ),
array( array('<h3>', '</h3>'), array('*', '*') ),
array( array('<strong>', '</strong>'), array('*', '*') ),
array( array('<b>', '</b>'), array('*', '*') ),
array( array('<em>', '</em>'), array('_', '_') ),
array( array('<i>', '</i>'), array('_', '_') ),
array( array('<del>', '</del>'), array('~', '~') ),
array( array('<s>', '</s>'), array('~', '~') ),
array( array('<li>', '</li>'), array('• ', '') ),
array( array('<code>', '</code>'), array('`', '`') ),
array( array('<pre>', '</pre>'), array('```', '```') ),
[ '#<br(\s*/)?>#i', "\n" ],
[ ['#<p>#i', '#</p>#i'], ['', "\n"] ],
[ ['#<h[1,2,3]>#i', '#</h[1,2,3]>#i'], ['*', "*\n"] ],
[ ['#<(strong|b)>#i', '#</(strong|b)>#i'], '*' ],
[ ['#<(em|i)>#i', '#</(em|i)>#i'], '_' ],
[ ['#<(del|s)>#i', '#</(del|s)>#i'], '~' ],
[ ['#<li>#i', '#</li>#i'], ['• ', "\n"] ],
[ ['#<pre>(<code[^>]*>)?#i', '#(</code>)?</pre>#i'], ['```', "```\n"] ],
[ ['#<(mark[^>]*|code)>#i', '#</(mark|code)>#i'], '`' ],
);

// Replace HTML tags (list must contain at least tags from the $aReplacementsMatrix)
$sContent = strip_tags($sContent, '<h1><h2><h3><br><strong><b><em><i><del><s><li><code><pre><a>');
$sContent = strip_tags($sContent, '<br><p><h1><h2><h3><strong><b><em><i><del><s><li><pre><code><mark><a>');
foreach($aReplacementsMatrix as $aReplacements)
{
$sContent = str_replace($aReplacements[0], $aReplacements[1], $sContent);
$sContent = preg_replace($aReplacements[0], $aReplacements[1], $sContent);
}

// Replace hyperlinks
Expand Down
24 changes: 24 additions & 0 deletions tests/php-unit-tests/ActionSlackNotificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,30 @@ public function TransformHTMLToSlackMarkupProvider(): array
HTML,
"expected" => "<!SomeGroup>",
],
"Simple p tags on different lines" => [
"input" => <<<HTML
<p>hello</p><p>hi</p>
HTML,
"expected" => "hello\nhi\n",
],
"Different tags on different lines" => [
"input" => <<<HTML
<h2>hello</h2><p><strong>hi</strong></p>
HTML,
"expected" => "*hello*\n*hi*\n",
],
"Nested tags" => [
"input" => <<<HTML
<p><strong>I'm bold and</strong></p><p><i><strong>I'm bold and italic</strong></i></p>
HTML,
"expected" => "*I'm bold and*\n_*I'm bold and italic*_\n",
],
"Large text with different tags" => [
"input" => <<<HTML
<h1>Heading 1</h1><h2>Heading 2</h2><h3>Heading 3</h3><p><strong>Strong Text</strong><br><b>Bold Text</b><br><em>Emphasized Text</em><br><i>Italic Text</i><br><del>Deleted Text</del><br><s>Strikethrough Text</s><br><mark class="marker-yellow">Marked Text</mark><br><code>Inline Code</code></p><ul><li>List Item 1</li><li>List Item 2</li></ul><pre><code class="language-plaintext">Block of Code\r\nLine 1\r\nLine 2\r\n</code></pre>
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",
],
];
}
}