diff options
author | Andres Rey <[email protected]> | 2017-11-06 18:03:27 +0000 |
---|---|---|
committer | Andres Rey <[email protected]> | 2017-11-06 18:03:27 +0000 |
commit | 056921e2450de888a18313610a5303e3edbb2ed4 (patch) | |
tree | d1decedb579a50ec446928bcc837bdddb7772a31 /src | |
parent | c1cf2c1a2ea5424797a7d2afe9defdc9c1e6d917 (diff) |
Get the article direction
TODO: Make the metadata array an object with getters and setters
Diffstat (limited to 'src')
-rw-r--r-- | src/HTMLParser.php | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/HTMLParser.php b/src/HTMLParser.php index f8d2342..fa8a609 100644 --- a/src/HTMLParser.php +++ b/src/HTMLParser.php @@ -17,6 +17,7 @@ class HTMLParser private $dom = null; /** + * TODO Make this an object? Instead of a dumb array * @var array */ private $metadata = []; @@ -969,6 +970,16 @@ class HTMLParser $articleContent = $this->prepArticle($articleContent); if ($hasContent) { + // Find out text direction from ancestors of final top candidate. + $ancestors = array_merge([$parentOfTopCandidate, $topCandidate], $parentOfTopCandidate->getNodeAncestors()); + foreach ($ancestors as $ancestor) { + $articleDir = $ancestor->getAttribute('dir'); + if ($articleDir) { + $this->metadata['articleDir'] = $articleDir; + break; + } + } + return $articleContent; } else { return false; |