Skip to content

Commit 4bb9418

Browse files
author
Geoff McLane
committed
add small 'sample' API use, optional build
1 parent 53dda44 commit 4bb9418

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ list(GET VERSION_LIST 2 TIDY_POINT_VERSION)
1919
set( LIB_TYPE STATIC ) # set default static
2020
option( BUILD_SHARED_LIB "Set ON to build Shared (DLL) Library" OFF )
2121
option( BUILD_TAB2SPACE "Set ON to build utility app, tab2space" OFF )
22+
option( BUILD_SAMPLE_CODE "Set ON to build the sample code" OFF )
2223

2324
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
2425
message(STATUS "*** Have SIZEOF void * = 8, so 64-bit")
@@ -157,5 +158,16 @@ if (BUILD_TAB2SPACE)
157158
# no INSTALL of this 'local' tool
158159
endif ()
159160

161+
if (BUILD_SAMPLE_CODE)
162+
set(name test71)
163+
set(dir console)
164+
add_executable( ${name} ${dir}/${name}.cxx )
165+
if (MSVC)
166+
set_target_properties( ${name} PROPERTIES DEBUG_POSTFIX d )
167+
endif ()
168+
target_link_libraries( ${name} ${add_LIBS} )
169+
# no INSTALL of this 'local' sample
170+
endif ()
171+
160172
# eof
161173

console/test71.cxx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 &amp; 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

Comments
 (0)