removing images and headings from the excerpt

This commit is contained in:
Amine Ben hammou
2018-06-01 11:21:59 +00:00
parent 8793d904fb
commit 67b66856f5
2 changed files with 10 additions and 11 deletions

View File

@@ -45,8 +45,8 @@ class PostContentManager {
// strip useless tags
$tags_not_being_stripped = array(
'<img>', '<p>', '<em>', '<span>', '<b>', '<strong>', '<i>', '<h1>',
'<h2>', '<h3>', '<a>', '<ul>', '<ol>', '<li>', '<br>', '<blockquote>'
'<p>', '<em>', '<span>', '<b>', '<strong>', '<i>',
'<a>', '<ul>', '<ol>', '<li>', '<br>', '<blockquote>'
);
$content = strip_tags($content, implode('', $tags_not_being_stripped));
if($with_post_class) {

View File

@@ -40,13 +40,16 @@ class PostContentManagerTest extends \MailPoetTest {
function testFilterContentRetainsHeadings() {
$html = '<h1>heading 1</h1>';
expect($this->post_content->filterContent($html))->equals($html);
expect($this->post_content->filterContent($html))
->equals('<p class="' . PostContentManager::WP_POST_CLASS . '">heading 1</p>');
$html = '<h2>heading 2</h2>';
expect($this->post_content->filterContent($html))->equals($html);
expect($this->post_content->filterContent($html))
->equals('<p class="' . PostContentManager::WP_POST_CLASS . '">heading 2</p>');
$html = '<h3>heading 3</h3>';
expect($this->post_content->filterContent($html))->equals($html);
expect($this->post_content->filterContent($html))
->equals('<p class="' . PostContentManager::WP_POST_CLASS . '">heading 3</p>');
}
function testFilterContentRetainsTextStyling() {
@@ -64,12 +67,7 @@ class PostContentManagerTest extends \MailPoetTest {
}
}
function testFilterContentRetainsImagesAndLinks() {
$html = '<img src="#" alt="some alt" />';
expect($this->post_content->filterContent($html))->equals(
'<p class="' . PostContentManager::WP_POST_CLASS . '"><img src="#" alt="some alt" /></p>'
);
function testFilterContentRetainsLinks() {
$html = '<a href="#" title="link title">some link</a>';
expect($this->post_content->filterContent($html))->equals(
'<p class="' . PostContentManager::WP_POST_CLASS . '">' . $html . '</p>'
@@ -88,6 +86,7 @@ class PostContentManagerTest extends \MailPoetTest {
'<table></table>',
'<tr></tr>',
'<td></td>',
'<img src="#" alt="some alt" />',
);
foreach($undesirable_tags as $html) {