HTML-Tidy5

 view release on metacpan or  search on metacpan

Tidy5.xs  view on Meta::CPAN

        }

        if ( rc >= 0 ) {
            /* Parse the input */
            rc = tidyParseString( tdoc, input );
        }

        if ( rc >= 0 && errbuf.bp) {
            XPUSHs( sv_2mortal(newSVpvn((char *)errbuf.bp, errbuf.size)) );

            /* TODO: Make this a function */
            switch ( tidyOptGetInt(tdoc,TidyNewline) ) {
                case TidyLF:
                    newline = "\n";
                    break;
                case TidyCR:
                    newline = "\r";
                    break;
                default:
                    newline = "\r\n";
                    break;
            }
            XPUSHs( sv_2mortal(newSVpv(newline, 0)) );
        }
        else {
            rc = -1;
        }

        if ( errbuf.bp )
            tidyBufFree( &errbuf );
        tidyRelease( tdoc );

        if ( rc < 0 ) {
            XSRETURN_UNDEF;
        }


void
_tidy_clean(input, configfile, tidy_options)
    INPUT:
        const char *input
        const char *configfile
        HV *tidy_options
    PREINIT:
        TidyBuffer errbuf = {0};
        TidyBuffer output = {0};
        TidyDoc tdoc = tidyCreate(); /* Initialize "document" */
        const char* newline;
        int rc = 0;
    PPCODE:
        tidyBufInit(&output);
        tidyBufInit(&errbuf);
        /* Set our default first. */
        /* Don't word-wrap */
        rc = ( tidyOptSetInt( tdoc, TidyWrapLen, 0 ) ? rc : -1 );

        if ( (rc >= 0 ) && configfile && *configfile ) {
            rc = tidyLoadConfig( tdoc, configfile );
        }

        /* XXX I think this cascade is a bug waiting to happen */

        if ( rc >= 0 ) {
            rc = ( tidyOptSetValue( tdoc, TidyCharEncoding, "utf8" ) ? rc : -1 );
        }

        if ( rc >= 0 ) {
            _load_config_hash( tdoc, tidy_options );
        }

        if ( rc >= 0 ) {
            rc = tidySetErrorBuffer( tdoc, &errbuf );  /* Capture diagnostics */
        }

        if ( rc >= 0 ) {
            rc = tidyParseString( tdoc, input );   /* Parse the input */
        }

        if ( rc >= 0 ) {
            rc = tidyCleanAndRepair(tdoc);
        }

        if ( rc > 1 ) {
            rc = ( tidyOptSetBool( tdoc, TidyForceOutput, yes ) ? rc : -1 );
        }

        if ( rc >= 0) {
            rc = tidySaveBuffer( tdoc, &output );
        }

        if ( rc >= 0) {
            rc = tidyRunDiagnostics( tdoc );
        }

        if ( rc >= 0 && output.bp && errbuf.bp ) {
            XPUSHs( sv_2mortal(newSVpvn((char *)output.bp, output.size)) );
            XPUSHs( sv_2mortal(newSVpvn((char *)errbuf.bp, errbuf.size)) );

            /* TODO: Hoist this into a function */
            switch ( tidyOptGetInt(tdoc,TidyNewline) ) {
                case TidyLF:
                    newline = "\n";
                    break;
                case TidyCR:
                    newline = "\r";
                    break;
                default: 
                    newline = "\r\n";
                    break;
            }
            XPUSHs( sv_2mortal(newSVpv(newline, 0)) );
        }
        else {
            rc = -1;
        }

        tidyBufFree( &output );
        tidyBufFree( &errbuf );
        tidyRelease( tdoc );

        if ( rc < 0 ) {



( run in 0.968 second using v1.01-cache-2.11-cpan-39bf76dae61 )