Help Wrapping HTMLTidy in LCB

Trevor DeVore lists at
Fri Nov 22 11:30:40 EST 2019


While looking at solutions for converting HTML into XHTML that can be
parsed by revXML I decided to test HTMLTidy which has an option to output
the input as XHTML. While I could bundle up the tidy command line tool and
include it with my app, I prefer to wrap things up in LCB if possible.

Unfortunately I haven't gotten very far with HTMLTidy and I'm
hoping someone else might be able to figure out what I'm doing wrong. If
you are up for loading up an LCB project in LC 9 on macOS and looking at
some C files then please read on:


- Github repo with LCB file, a test stack, and compiled HTMLTidy dylib for
testing on macOS:
- HTMLTidy github repo where source files are located:


In the htmltidy.lcb file I've wrapped some of the simple APIs that return
strings: tidyReleaseDate(), tidyLibraryVersion(), and tidyPlatform(). Those
all work.


tidyHTMLToXHTML() in the htmltidy.lcb file has some test code in it that
isn't working. As a test I want to call `tidyOptGetIdForName()` from the
htmltidy C library and get a valid value returned. I expect the following
code to log `0` but it is logging `104`. I don't think I am creating
the Ctmbstr pointer properly but I don't really know. Here is code from the
htmltidy.lcb file along with links to the ctmbstr definition in the
HTMLTidy source code:

variable tCStr as Pointer

-- Attempting to create a Ctmbstr from a LiveCode string
-- ctmbstr:
MCStringConvertToCString("TidyUnknownOption", tCStr)
-- The next handler is logging `104` which is N_TIDY_OPTIONS (error)
-- Appears that tCStr is not the right format.
log c_tidyOptGetIdForName(tCStr)

MCStringConvertToCString is defined as follows in the htmltidy.lcb file:

foreign handler MCStringConvertToCString(in pString as String, out rCString
as Pointer) returns CBool binds to "<builtin>"

If anyone can provide some pointers or a PR I would really appreciate it.

Trevor DeVore

More information about the use-livecode mailing list