From 056921e2450de888a18313610a5303e3edbb2ed4 Mon Sep 17 00:00:00 2001 From: Andres Rey Date: Mon, 6 Nov 2017 18:03:27 +0000 Subject: Get the article direction TODO: Make the metadata array an object with getters and setters --- src/HTMLParser.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') 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; -- cgit v1.2.3