How to use libtidy with tidyParseBuffer ()?

I am trying to clear HTML code using libtidy (C language), the problem is that:

I want to build a TidyDoc (tree structure) with tidyParseBuffer ().

I have no problem with tidyParseFile (); about tidyParseBuffer (): I am sure that I read the file correctly and that the TidyBuffer structure that I provide tidyParseBuffer () is correctly filled.

Any ideas?

here is the code:

    //declaration
 tidyInput = malloc(sizeof(TidyBuffer));
 tidyOutput = malloc(sizeof(TidyBuffer));
 do { 
      len = fread(pbInputData, 1, nInputData, h->file);
      tidyBufAttach(tidyInput, (void*)pbInputData, len);
      tidyParseBuffer(h->doc, tidyInput);  // doc is the TidyDoc 
 } while (len >= nInputData);
 tidyOptSetBool(h->doc, TidyForceOutput, yes);

 tidySaveFile(handler->doc, "C://test.xhtml");

I have simplified the code.

+3
source share
1 answer

The problem is that you are trying to parse the contents of the file into pieces, reading each fragment into a buffer and calling tidyParseBuffer()for each fragment.

tidyParseXxx() , , , TidyInputSource tidyParseSource().

+1

Source: https://habr.com/ru/post/1720466/


All Articles