示例#1
0
    return Cell::unit('a', $content, $attr, $indent);
});
// `<img>`
Cell::add('img', function ($src = null, $alt = null, $attr = array(), $indent = 0) {
    $attr['src'] = Converter::url($src);
    $attr['alt'] = Cell::protect($alt);
    return Cell::unit('img', false, $attr, $indent);
});
// `<(ol|ul)>`
foreach (array('ol', 'ul') as $unit) {
    Cell::add($unit, function ($list = array(), $attr = array(), $indent = 0) use($unit) {
        $html = Cell::begin($unit, $attr, $indent) . NL;
        foreach ($list as $k => $v) {
            if (is_array($v)) {
                $html .= Cell::begin('li', array(), $indent + 1) . $k . NL;
                $html .= call_user_func('Cell::' . $unit, $v, $attr, $indent + 2) . NL;
                $html .= Cell::end('li', $indent + 1) . NL;
            } else {
                $html .= Cell::unit('li', $v, array(), $indent + 1) . NL;
            }
        }
        return $html . Cell::end($unit, $indent);
    });
}
// `<(hr|br)>`
foreach (array('hr', 'br') as $unit) {
    Cell::add($unit, function ($repeat = 1, $attr = array(), $indent = 0) use($unit) {
        $indent = $indent ? str_repeat(TAB, $indent) : "";
        return $indent . str_repeat(Cell::unit($unit, false, $attr), $repeat);
    });
}
示例#2
0
    }
    return Cell::unit('script', $content, $attr, $indent);
});
// `<a>`
Cell::add('a', function ($href = null, $content = "", $target = null, $attr = array(), $indent = 0) {
    $attr['href'] = Converter::url($href);
    $attr['target'] = $target;
    return Cell::unit('a', $content, $attr, $indent);
});
// `<img>`
Cell::add('img', function ($src = null, $alt = null, $attr = array(), $indent = 0) {
    $attr['src'] = Converter::url($src);
    $attr['alt'] = Cell::protect($alt);
    return Cell::unit('img', false, $attr, $indent);
});
// `<(ol|ul)>`
foreach (array('ol', 'ul') as $unit) {
    Cell::add($unit, function ($list = array(), $attr = array(), $indent = 0) use($unit) {
        $html = Cell::begin($unit, $attr, $indent) . NL;
        foreach ($list as $k => $v) {
            if (is_array($v)) {
                $html .= Cell::begin('li', array(), $indent + 1) . $k . NL;
                $html .= call_user_func('Cell::' . $unit, $v, $attr, $indent + 2) . NL;
                $html .= Cell::end('li', $indent + 1) . NL;
            } else {
                $html .= Cell::unit('li', $v, array(), $indent + 1) . NL;
            }
        }
        return $html . Cell::end($unit, $indent);
    });
}