SRombauts / HtmlBuilder

A simple C++ HTML Generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HtmlBuilder

license Travis CI Linux Build Status AppVeyor Windows Build status

A simple C++ header-only HTML 5 Generator library, using a Document Object Model (DOM).

HTML5 logo

Copyright (c) 2017-2022 SĂ©bastien Rombauts (sebastien.rombauts@gmail.com)

Current status

Deployed in production in a small application.

Support

  • Windows 10 - VS2015 / 2017 / 2019
  • Linux Ubuntu 16.04 Clang 7 / GCC 5.4

Features

  1. DOM Model
  2. Example featuring Bootstrap's navigation bar

Missing features

  1. Encoding of HTML Entities (special chars)
  2. Support for HTML Comments
  3. Support for CSS inline style (this is probably easy)

Javascript inline script is currently out of scope.

Example

The following example is provided in src/Main.cpp.

Source Code

    HTML::Document document("Welcome to HTML");
    document.addAttribute("lang", "en");
    document << HTML::Header2("Generated HTML") << HTML::Break() << HTML::Break();
    document.body() << "Which results in the following HTML page (truncated to fit in this README): ";
    document << HTML::Text("Text directly in the body. ") << HTML::Text("Text directly in the body.") << HTML::Break()
        << HTML::Text("Text directly in the body.");
    document << HTML::Paragraph("This is the way to go for a big text in a multi-line paragraph.");
    document << HTML::Link("Google", "http://google.com").cls("my_style");
    document << (HTML::Paragraph("A paragraph. ").addAttribute("style", "font-family:arial")
        << HTML::Text("Text child.") << HTML::Break() << HTML::Text("And more text."));

    document << (HTML::List()
        << (HTML::ListItem("Text item"))
        << (HTML::ListItem() << HTML::Link("Github Link", "http://srombauts.github.io").title("SRombaut's Github home page"))
        << (HTML::ListItem() << (HTML::List()
                << HTML::ListItem("val1")
                << HTML::ListItem("val2"))));

    document << (HTML::Table()
        << (HTML::Row() << HTML::ColHeader("A") << HTML::ColHeader("B"))
        << (HTML::Row() << HTML::Col("Cell_11") << HTML::Col("Cell_12"))
        << (HTML::Row() << HTML::Col("Cell_21") << HTML::Col("Cell_22"))
        << (HTML::Row() << HTML::Col("") << HTML::Col("Cell_32")));

Generated HTML

Which results in the following HTML page (truncated to fit in this README):

Text directly in the body. Text directly in the body.
Text directly in the body.

This is the way to go for a big text in a multi-line paragraph.

Google

A paragraph. Text child.
And more text.

A B
Cell_11 Cell_12
Cell_21 Cell_22
Cell_32

Building with CMake

This is a header only library, so just include the include folder and go on.

Get cpplint submodule

git submodule init
git submodule update

Typical generic build (see also "build.bat" or "./build.sh")

mkdir build
cd build
cmake ..        # cmake .. -G "Visual Studio 10"    # for Visual Studio 2010
cmake --build . # make

Debug build for Unix Makefiles

mkdir Debug
cd Debug
cmake .. -DCMAKE_BUILD_TYPE=Debug   # -G "Unix Makefiles"
cmake --build . # make

Release build

mkdir Release
cd Release
cmake .. -DCMAKE_BUILD_TYPE=Release  # -G "Unix Makefiles"
cmake --build . # make

About

A simple C++ HTML Generator

License:MIT License


Languages

Language:C++ 83.7%Language:CMake 12.7%Language:Shell 1.5%Language:C 1.2%Language:Batchfile 1.0%