summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/Readability.php22
-rw-r--r--test/ReadabilityTest.php2
3 files changed, 17 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d4d56dd..e0ceea1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
- Added a safe check to avoid sending the DOMDocument as a node when scanning for node ancestors.
- Fix issue #45: Small mistake in documentation
- Fix issue #46: Added `data-src` as a image source path
+- Fixed bug when extracting all the image of the article (Was extracting images from the original DOM instead of the parsed one)
## [v1.1.0](https://github.com/andreskrey/readability.php/releases/tag/v1.1.0)
diff --git a/src/Readability.php b/src/Readability.php
index 4695244..fc3eda6 100644
--- a/src/Readability.php
+++ b/src/Readability.php
@@ -29,9 +29,9 @@ class Readability
protected $title = null;
/**
- * HTML content article.
+ * Final DOMDocument with the fully parsed HTML.
*
- * @var string|null
+ * @var DOMDocument|null
*/
protected $content = null;
@@ -198,7 +198,7 @@ class Readability
}
}
- $this->setContent($result->C14N());
+ $this->setContent($result);
$this->logger->info('*** Parse successful :)');
@@ -348,11 +348,11 @@ class Readability
$result[] = $this->getImage();
}
- if (null == $this->dom) {
+ if (null == $this->getContentObject()) {
return $result;
}
- foreach ($this->dom->getElementsByTagName('img') as $img) {
+ foreach ($this->getContentObject()->getElementsByTagName('img') as $img) {
if ($src = $img->getAttribute('src')) {
$result[] = $src;
}
@@ -1564,13 +1564,21 @@ class Readability
*/
public function getContent()
{
+ return $this->content->C14N();
+ }
+
+ /**
+ * @return DOMDocument|null
+ */
+ public function getContentObject()
+ {
return $this->content;
}
/**
- * @param string $content
+ * @param DOMDocument $content
*/
- protected function setContent($content)
+ protected function setContent(DOMDocument $content)
{
$this->content = $content;
}
diff --git a/test/ReadabilityTest.php b/test/ReadabilityTest.php
index d4c0a18..fe17b23 100644
--- a/test/ReadabilityTest.php
+++ b/test/ReadabilityTest.php
@@ -41,7 +41,7 @@ class ReadabilityTest extends \PHPUnit_Framework_TestCase
foreach ($expectedMetadata as $key => $metadata) {
$function = 'get' . $key;
- $this->assertEquals($metadata, $readability->$function());
+ $this->assertEquals($metadata, $readability->$function(), sprintf('Failed asserting %s metadata', $key));
}
}