clean-css-cli Format media print code with clean-css-cli

95 views Asked by At

output program with clean-css-cli 1. program with python excute clancss cli I set level 2 and mergeMedia:off and the result is not well for me.

    try:
        #cmd = "cleancss -02 mergeMedia:off --compatibility ie8  -o {0} {1} ".format(dstFile, srcFile)
        cmd = "cleancss -O2 mergeMedia:off;removeDuplicateMediaBlocks:off -o {0} {1} ".format(dstFile, srcFile)
        os.system(cmd)
        print("cleancss - {} - ok !".format(srcFile))
        #os.remove(srcFile)
        #os.rename(dstFile, srcFile)
    except NameError as e:
        print(e)

2. css source code The style code like below.The first item "table" will be remove(see setp 3)

@media print {
    table {
        border: 1px solid black;
        border-collapse: collapse;
        table-layout: fixed;
    }

        table th {
            border: 1px solid black;
        }

        table td {
            border: 1px solid black;
        }

    .pageBreak {
        page-break-after: always;
    }

    .noPrint {
        display: none;
    }

    .borderable {
        border: 2px solid black;
        padding: 3px;
    }

    nav, aside {
        display: none;
    }

    table.posprint {
        border: 1px solid white;
        border-collapse: collapse;
        table-layout: fixed;
    }

        table.posprint th {
            border: 1px solid white;
        }

        table.posprint td {
            border: 1px solid white;
        }
}

3. clean css output The output of above setp 2 . The first element was be removed and less brackets in the end .

@media print{border-collapse:collapse;table-layout:fixed}table td,table th{border:1px solid #000}.pageBreak{page-break-after:always}.noPrint{display:none}.borderable{border:2px solid #000;padding:3px}aside,nav{display:none}table.posprint{border:1px solid #fff;border-collapse:collapse;table-layout:fixed}table.posprint td,table.posprint th{border:1px solid #fff}

How can i change my program code and get the right output.

Thank you .

0

There are 0 answers