Loading src/html.cpp +18 −3 Original line number Diff line number Diff line Loading @@ -45,6 +45,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace libhtmlpp { const char *ContainerTypes[]={ "div", "script", "span", nullptr }; class DocElements { public: libhtmlpp::Element* element; Loading Loading @@ -1256,6 +1263,14 @@ void libhtmlpp::HtmlPage::_CheckHeader(const HtmlString &page){ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { auto isContainer = [](const char *tagname) { for(int i=0; ContainerTypes[i]; ++i){ if(strcmp(ContainerTypes[i],tagname)==0) return true; } return false; }; std::stack<libhtmlpp::Element*> cpylist; int lvl=0; Loading Loading @@ -1294,7 +1309,7 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { } //Container must be always terminated fuck html5 if(strcmp(((HtmlElement*) el)->getTagname(),"div")==0){ if(isContainer(((HtmlElement*) el)->getTagname())){ output.append("</"); output.append(((HtmlElement*) el)->_TagName.data(),((HtmlElement*) el)->_TagName.size()); output.append(">"); Loading Loading @@ -1341,6 +1356,8 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { while(!cpylist.empty()){ el=cpylist.top(); --lvl; if(formated){ for(int i=0; i<lvl; ++i){ output.append(" "); Loading @@ -1354,8 +1371,6 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { if(formated) output.append("\r\n"); --lvl; cpylist.pop(); if (el->_nextElement) { el=el->_nextElement; Loading test/htmlcopytest.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -71,7 +71,7 @@ int main(int arc,char *argv[]){ libhtmlpp::HtmlString html; std::cout << "Orginal html:" << std::endl; libhtmlpp::print(&index,html); libhtmlpp::print(&index,html,true); std::cout << html.c_str() << std::endl; std::cout << "Modified html:" << std::endl; Loading test/htmlpagetest.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -40,7 +40,7 @@ int main(int arc,char *argv[]){ libhtmlpp::HtmlElement index; page.loadFile(index,argv[1]); libhtmlpp::HtmlString html; libhtmlpp::print(&index,html); libhtmlpp::print(&index,html,true); std::cout << html.c_str() << std::endl; std::cout << Green << "Test Passed!" << NOCOLOR << std::endl; }catch(libhtmlpp::HTMLException &exp){ Loading Loading
src/html.cpp +18 −3 Original line number Diff line number Diff line Loading @@ -45,6 +45,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace libhtmlpp { const char *ContainerTypes[]={ "div", "script", "span", nullptr }; class DocElements { public: libhtmlpp::Element* element; Loading Loading @@ -1256,6 +1263,14 @@ void libhtmlpp::HtmlPage::_CheckHeader(const HtmlString &page){ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { auto isContainer = [](const char *tagname) { for(int i=0; ContainerTypes[i]; ++i){ if(strcmp(ContainerTypes[i],tagname)==0) return true; } return false; }; std::stack<libhtmlpp::Element*> cpylist; int lvl=0; Loading Loading @@ -1294,7 +1309,7 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { } //Container must be always terminated fuck html5 if(strcmp(((HtmlElement*) el)->getTagname(),"div")==0){ if(isContainer(((HtmlElement*) el)->getTagname())){ output.append("</"); output.append(((HtmlElement*) el)->_TagName.data(),((HtmlElement*) el)->_TagName.size()); output.append(">"); Loading Loading @@ -1341,6 +1356,8 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { while(!cpylist.empty()){ el=cpylist.top(); --lvl; if(formated){ for(int i=0; i<lvl; ++i){ output.append(" "); Loading @@ -1354,8 +1371,6 @@ void libhtmlpp::print(Element* el, HtmlString &output,bool formated) { if(formated) output.append("\r\n"); --lvl; cpylist.pop(); if (el->_nextElement) { el=el->_nextElement; Loading
test/htmlcopytest.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -71,7 +71,7 @@ int main(int arc,char *argv[]){ libhtmlpp::HtmlString html; std::cout << "Orginal html:" << std::endl; libhtmlpp::print(&index,html); libhtmlpp::print(&index,html,true); std::cout << html.c_str() << std::endl; std::cout << "Modified html:" << std::endl; Loading
test/htmlpagetest.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -40,7 +40,7 @@ int main(int arc,char *argv[]){ libhtmlpp::HtmlElement index; page.loadFile(index,argv[1]); libhtmlpp::HtmlString html; libhtmlpp::print(&index,html); libhtmlpp::print(&index,html,true); std::cout << html.c_str() << std::endl; std::cout << Green << "Test Passed!" << NOCOLOR << std::endl; }catch(libhtmlpp::HTMLException &exp){ Loading