Fix addition of dividers, do general refactoring

This commit is contained in:
Tautvidas Sipavičius
2015-09-18 19:01:34 +03:00
parent 6a6d2391c1
commit be76e016b3
5 changed files with 61 additions and 49 deletions

View File

@ -45,18 +45,17 @@ class StructureTransformer {
* turns other root children into text blocks
*/
private function transformTagsToBlocks($root, $image_padded) {
$structure = array();
foreach ($root->children as $item) {
return array_map(function($item) use ($image_padded) {
if ($item->tag === 'img' || $item->tag === 'a' && $item->query('img')) {
$link = '';
$image = $item;
if ($item->tag === 'a') {
$link = $item->getAttribute('href');
$image = $item->children[0];
} else {
$link = '';
$image = $item;
}
$structure[] = array(
return array(
'type' => 'image',
'link' => $link,
'src' => $image->getAttribute('src'),
@ -71,14 +70,13 @@ class StructureTransformer {
),
);
} else {
$structure[] = array(
return array(
'type' => 'text',
'text' => $item->toString(),
);
}
}
return $structure;
}, $root->children);
}
/**