【问题标题】:Libtidy HTML to XHTML and save in string CLibtidy HTML 到 XHTML 并保存在字符串 C
【发布时间】:2015-02-06 12:18:22
【问题描述】:

我有这个函数可以将输入的html转换为xhtml:

char* cleanhtml(char* localhtml)
{
char *buffer_;
static char *cleansed_buffer;


// uses Libtidy to convert the buffer to XML
TidyBuffer output = {0};
TidyBuffer errbuf = {0};
int rc = -1;
bool ok;

TidyDoc tdoc;
tdoc = tidyCreate();                     // Initialize "document"

ok = tidyOptSetBool( tdoc, TidyXhtmlOut, yes );  // Convert to XHTML
    rc = tidySetErrorBuffer( tdoc, &errbuf );      // Capture diagnostics
    rc = tidyParseString(tdoc, localhtml);           // Parse the input
    rc = tidyCleanAndRepair( tdoc );               // Tidy it up!
    rc = tidyRunDiagnostics( tdoc );               // Kvetch// If error, force output.
    rc = ( tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1 );
    rc = tidySaveBuffer( tdoc, &output );          // Pretty Print
    cleansed_buffer = (char*) malloc(output.size + 1);
    memcpy (cleansed_buffer, (char*)output.bp,output.size);
    tidyBufFree( &output );
    tidyBufFree( &errbuf );
    tidyRelease( tdoc );
    return cleansed_buffer;
}

但问题是它不能正常工作......由于某种原因,给出的 xhtml 无法解析,并且格式错误。那么如何使用 libtidy 将给定的字符串(巨大的字符串)以正确的格式转换为 xhtml。

有人可以给我链接到 C 的最新 libtidy (dlls,includes)。我在任何地方都找不到它...甚至在那里的网站上也找不到..

【问题讨论】:

    标签: c htmltidy


    【解决方案1】:
    int TIDY_CALL tidySaveString(TidyDoc tdoc,tmbstr buffer, uint * buflen)
    

    您可以简单地使用此功能将整洁的输出保存为字符串。

    You can follow the instructions from the this link

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-06
      • 1970-01-01
      • 2020-06-24
      • 1970-01-01
      • 2018-02-16
      • 2014-03-21
      • 2023-03-22
      • 2011-10-21
      相关资源
      最近更新 更多