Commit efa528c1 authored by jan.koester's avatar jan.koester
Browse files

print is now recusirve

parent 3d9c94da
Loading
Loading
Loading
Loading
+23 −23
Changes for src/html.cpp: 23 added lines, 23 removed lines.
Original line number Diff line number Diff line
@@ -508,39 +508,39 @@ void libhtmlpp::HtmlPage::loadFile(const char* path){
    _RootNode=tmp.parse();
}

void libhtmlpp::HtmlElement::_print(HtmlElement* child) {
    for (HtmlElement* cur = child; cur; cur = cur->_nextElement) {
        if (!cur->_TagName.empty()) {
            _Cstr.append("<");
            _Cstr.append(cur->_TagName.c_str());
            for (HtmlElement::Attributes* curattr = cur->_firstAttr; curattr; curattr = curattr->_nextAttr) {
                _Cstr.append(" ");
                _Cstr.append(curattr->_Key.c_str());
                _Cstr.append("=\"");
                _Cstr.append(curattr->_Value.c_str());
                _Cstr.append("\"");
void libhtmlpp::HtmlElement::_print(HtmlElement* el, HtmlElement* parent,sys::array<char>& output) {
    if (!el->_TagName.empty()) {
        output.append("<");
        output.append(el->_TagName.c_str());
		for (HtmlElement::Attributes* curattr = el->_firstAttr; curattr; curattr = curattr->_nextAttr) {
            output.append(" ");
            output.append(curattr->_Key.c_str());
            output.append("=\"");
            output.append(curattr->_Value.c_str());
            output.append("\"");
		}
            _Cstr.append(">");
        output.append(">");

            if (cur->_childElement) {
                _print(cur->_childElement);
		if (el->_childElement) {
			_print(el->_childElement, el, output);
		}

            if (cur->_childElement) {
                _Cstr.append("</");
                _Cstr.append(cur->_TagName.c_str());
                _Cstr.append(">");
            }
        } else if (!cur->_Text.empty()) {
            _Cstr.append(cur->_Text.c_str());
	} else if (!el->_Text.empty()) {
        output.append(el->_Text.c_str());
	}

	if (el->_nextElement) {
        _print(el->_nextElement,parent,output);
    }else if(parent){
        output.append("</");
        output.append(parent->_TagName.c_str());
        output.append(">");
    }
}


const char* libhtmlpp::HtmlElement::printHtmlElement() {
    _Cstr.clear();
    _print(this);
    _print(this,nullptr,_Cstr);
    return _Cstr.c_str();
}

+1 −1
Changes for src/html.h: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ namespace libhtmlpp {

    protected:

        void              _print(HtmlElement* child);
        static void       _print(HtmlElement* el, HtmlElement* parent,sys::array<char> &output);
        HtmlElement*      _prevElement;
        HtmlElement*      _nextElement;
        HtmlElement*      _childElement;
+1 −1

File changed.

Contains only whitespace changes.