|
| 1 | +/*\ |
| 2 | + * 20150206 - Test app for Issue #71 |
| 3 | + * |
| 4 | + * A simple API example of getting the body text, first as html, |
| 5 | + * and then as a raw stream. |
| 6 | + * |
| 7 | + * Note: This simple test app has no error checking |
| 8 | + * |
| 9 | +\*/ |
| 10 | + |
| 11 | +#include <stdio.h> |
| 12 | +#include "buffio.h" |
| 13 | +#include "tidy.h" |
| 14 | + |
| 15 | +static const char *sample = |
| 16 | + "<!DOCTYPE html>\n" |
| 17 | + "<head>\n" |
| 18 | + "<meta charset=utf-8>\n" |
| 19 | + "<title>Test app for Issue #71</title>\n" |
| 20 | + "<body>something & escaped</body>\n" |
| 21 | + "</html>"; |
| 22 | + |
| 23 | +int main() { |
| 24 | + printf("\nSimple example of HTML Tidy API use.\n"); |
| 25 | + TidyDoc tdoc = tidyCreate(); |
| 26 | + TidyBuffer buff; |
| 27 | + tidyBufInit(&buff); |
| 28 | + tidyBufAppend(&buff, (void *)sample, strlen(sample)); |
| 29 | + tidyParseBuffer(tdoc, &buff); |
| 30 | + TidyNode body = tidyGetBody(tdoc); |
| 31 | + TidyNode text_node = tidyGetChild(body); |
| 32 | + TidyBuffer buff2; |
| 33 | + tidyBufInit(&buff2); |
| 34 | + printf("This is the 'escaped' text, from tidyNodeGetText(...), suitable for html use...\n"); |
| 35 | + tidyNodeGetText(tdoc, text_node, &buff2); |
| 36 | + fwrite(buff2.bp, buff2.size, 1, stdout); |
| 37 | + printf("This is the 'raw' lexer values, from tidyNodeGetValue(...).\n"); |
| 38 | + tidyNodeGetValue(tdoc, text_node, &buff2); |
| 39 | + fwrite(buff2.bp, buff2.size, 1, stdout); |
| 40 | + printf("\n"); |
| 41 | + return 0; |
| 42 | +} |
| 43 | + |
| 44 | +// eof |
0 commit comments