function processImages($page)
{
    foreach (nodes($page, 'img') as $img) {
        $show = false;
        // $img->getAttribute('class') == '' is used for images inside text with formulas
        if ($img->getAttribute('class') == '') {
            $show = true;
        } elseif (starts(IMAGES, 'explain') && !hasClass($img, 'explanation')) {
            $show = false;
        } elseif (starts(IMAGES, 'all')) {
            $show = true;
        }
        if (!$show) {
            remove($img);
            continue;
        }
        $imageSrc = $img->getAttribute('src');
        $imgName = pathinfo(parse_url($imageSrc, PHP_URL_PATH), PATHINFO_BASENAME);
        download($imageSrc, BUILD_DIR . '/images/' . $imgName);
        $imageSrc = str_replace('http://learnyousomeerlang.com/static/img', '../images', $imageSrc);
        $img->setAttribute('src', $imageSrc);
        if ($img->getAttribute('class') == '') {
            continue;
        }
        $parent = $img->parentNode;
        if (strtolower($parent->nodeName) == 'p') {
            $img = $parent->removeChild($img);
            $img = appendSibling($img, $parent);
        } else {
            if ($img->nextSibling && strtolower($img->nextSibling->nodeName) == 'h3') {
                $h3 = $img->nextSibling;
                $img = $parent->removeChild($img);
                $img = appendSibling($img, $h3);
            }
        }
        centerImage($img);
    }
}
function remove_node($domElement)
{
    if ($domElement->hasChildNodes()) {
        $children = $domElement->childNodes;
        $toAppend = array();
        foreach ($children as $child) {
            array_unshift($toAppend, $child);
        }
        foreach ($toAppend as $child) {
            appendSibling($child, $domElement);
        }
    }
    //  $domElement->parentNode->removeChild($domElement);
}