This is a simple tool to generate code syntax highlighting in HTML format.
- Syntax Highlighting: Supports C/C++ syntax highlighting.
- Keywords (Blue)
- Comments (Green)
- string/char literals (Gray)
- HTML Generation: Converts source code to HTML documents.
- Cross-Platform: Compiles on Linux and Windows.
- Wildcard Support: Built-in wildcard expansion for Windows.
The following table details the level of C++ support provided by this tool.
| Feature Category | Fully Supported | Not Supported (Rendered as plain text) |
|---|---|---|
| C++ Standard | C++98, C++03, C++11 |
C++14, C++17, C++20 |
| Keywords | All keywords from C++11 (e.g., constexpr, nullptr, decltype, final, override) |
Post-C++11 keywords |
| Types | int, char, float, double, void, bool, char16_t, char32_t, auto, etc. |
Post-C++11 types |
| OO / Memory | class, struct, union, new, delete, this, public, private, friend, virtual |
- |
| Preprocessor | #include, #define, #ifdef, #ifndef, #endif, #pragma, #import, #else |
- |
| Modern C++ | Lambdas, static_assert, thread_local (Keywords) | co_await, module, etc. |
Below are links to documentation for features discussed above.
- Control Flow Statements (
if,while,for,switch) - Fundamental Types (
int,char,float,void) - Classes and Structures (
class,struct,union) - Dynamic Memory Management (
new,delete)
- Virtual Functions (
virtual) - Namespaces (
namespace) - Exceptions (
try,catch,throw) - Modern C++ Support (C++11, C++14, C++17, C++20)
- C++ Compiler (g++, clang++, or MSVC)
- Standard C++ Libraries
sudo apt-get install build-essentialTo build the project on Linux/Unix (full-featured version):
g++ parser.cpp cppparse.cpp -o code2htmlNote
parsefiles.cpp contains a legacy standalone version with limited keyword support. For full C++11 highlighting, always build with parser.cpp and cppparse.cpp.
Run the tool by providing the source file(s) as arguments:
./code2html parsefiles.cppThis will generate parsefiles.cpp.html.
A more complex testing battery is available to run code2html against entire Git repositories. This battery clones a repository, processes all C++ files, and generates a summary report.
Provide the Git repository URL as an argument to the run_test_battery.sh script:
./run_test_battery.sh <repository_url>Example:
./run_test_battery.sh https://github.com/danmar/cppcheck.git- Cloned Repo: The repository is cloned into a local directory.
- HTML Files: All generated HTML files are stored in a
code2html_outputdirectory within the cloned repository, preserving the original directory structure. - Summary Report: A
summary_report.mdis generated in thecode2html_outputdirectory, containing metrics, stats, and details of any failed files.
- This project contains some legacy code for wildcard expansion from the Samba project.