Commit 4e521015 authored by jan.koester's avatar jan.koester
Browse files

now detects more html container

parent 956cf910
Loading
Loading
Loading
Loading
+18 −3
Original line number Diff line number Diff line
@@ -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;
@@ -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;
@@ -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(">");
@@ -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("    ");
@@ -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;
+1 −1
Original line number Diff line number Diff line
@@ -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;
+1 −1
Original line number Diff line number Diff line
@@ -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){