Commit b398dc78 authored by jan.koester's avatar jan.koester
Browse files

test

parents 3b24881b 88364f09
Loading
Loading
Loading
Loading
+26 −1
Original line number Diff line number Diff line
project(libhtmlpp CXX)
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.23)
enable_testing ()

set(LIBV "1.0.0")
set(Upstream_VERSION 1.0.0)

find_package(Doxygen QUIET)
if (DOXYGEN_FOUND)
    set(DOXYFILE_IN  ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
    set(DOXYFILE_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
    set(DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/libhtmlpp/html")

    # Allow @LIBV@ substitution from your existing variable
    configure_file(${DOXYFILE_IN} ${DOXYFILE_OUT} @ONLY)

    add_custom_target(docs ALL
        COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE_OUT}
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
        COMMENT "Generating API documentation with Doxygen (sources: ${CMAKE_SOURCE_DIR}/src)"
        VERBATIM)

   install(
        DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/docs/html/"
        DESTINATION "${DOC_INSTALL_DIR}"
        COMPONENT docs
   )

else()
    message(STATUS "Doxygen not found; 'docs' target will not be available.")
endif()

if(NOT ${CMAKE_CXX_COMPILER} MATCHES "MSVC")
set(CMAKE_CXX_FLAGS "-fPIC -Wall")
endif()

Doxyfile.in

0 → 100644
+59 −0
Original line number Diff line number Diff line
# Doxygen configuration for libhtmlpp
# This file is configured by CMake (configure_file) to produce a Doxyfile.

PROJECT_NAME           = "libhtmlpp"
PROJECT_NUMBER         = "@LIBV@"

OUTPUT_DIRECTORY       = "@CMAKE_BINARY_DIR@/docs"
CREATE_SUBDIRS         = NO

# What to document
INPUT                  = "@CMAKE_SOURCE_DIR@/src" "@CMAKE_SOURCE_DIR@"
RECURSIVE              = YES
FILE_PATTERNS          = *.h *.hpp *.hh *.hxx *.c *.cc *.cpp *.cxx

# Extraction options
EXTRACT_ALL            = YES
EXTRACT_PRIVATE        = NO
EXTRACT_STATIC         = NO
EXTRACT_LOCAL_CLASSES  = YES
EXTRACT_ANON_NSPACES   = YES

# Warnings
WARNINGS               = YES
WARN_IF_UNDOCUMENTED   = NO
WARN_IF_DOC_ERROR      = YES
WARN_NO_PARAMDOC       = YES
WARN_LOGFILE           = "@CMAKE_BINARY_DIR@/docs/doxygen-warnings.log"

# Source browser
SOURCE_BROWSER         = YES
INLINE_SOURCES         = NO
STRIP_CODE_COMMENTS    = YES

# HTML output
GENERATE_HTML          = YES
HTML_OUTPUT            = html
SEARCHENGINE           = YES

# Disable LaTeX/PDF by default
GENERATE_LATEX         = NO

# Diagrams (optional, requires Graphviz "dot")
HAVE_DOT               = YES
DOT_IMAGE_FORMAT       = svg
DOT_TRANSPARENT        = YES
CALL_GRAPH             = NO
CALLER_GRAPH           = NO
CLASS_GRAPH            = YES
COLLABORATION_GRAPH    = NO
INCLUDE_GRAPH          = YES
INCLUDED_BY_GRAPH      = YES

# Misc
TAB_SIZE               = 4
JAVADOC_AUTOBRIEF      = YES
MULTILINE_CPP_IS_BRIEF = NO
OPTIMIZE_OUTPUT_FOR_C  = NO
OPTIMIZE_OUTPUT_JAVA   = NO
OPTIMIZE_FOR_FORTRAN   = NO
+1 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ namespace libhtmlpp {
        {"<","&lt;"},
        {">","&gt;"},
        {"'","&apos;"},
        {"+","&plus;"},
        {nullptr,nullptr}
    };
};
+829 −282

File changed.

Preview size limit exceeded, changes collapsed.

+120 −4
Original line number Diff line number Diff line
/**
 * @file html.h
 * @brief Public declarations for libhtmlpp HTML element types and utilities.
 * @date 2025-10-30
 *
 * This file is part of libhtmlpp and provides HTML parsing, DOM-like element
 * types, serialization helpers, and encoding utilities.
 */
/*******************************************************************************
Copyright (c) 2014, Jan Koester jan.koester@gmx.net
All rights reserved.
@@ -34,10 +42,23 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <memory>

#pragma once
/**
 * @namespace libhtmlpp
 * @brief Core namespace for the libhtmlpp HTML parsing and printing library.
 */

namespace libhtmlpp {
/**
 * @brief Internal helper frame used while building the tree during parsing.
 */
    class DocElements;
/**
 * @brief Concrete element representing a generic HTML tag with attributes and child/next links.
 */
    class HtmlElement;
/**
 * @brief Mutable string buffer for HTML input/output with parsing facilities.
 */
    class HtmlString;

    enum ElementType{
@@ -45,8 +66,12 @@ namespace libhtmlpp {
        HtmlEl=1,
        CommentEl=2,
        ScriptEL=3,
        SvgEL=4
        SvgEL=4,
        TextAreaEL=5
    };
/**
 * @brief Abstract base class for all nodes in the HTML tree. Provides linkage and common operations.
 */

    class Element {
    public:
@@ -115,6 +140,8 @@ namespace libhtmlpp {

        int    getType() const;
        void   remove(Element* el);

        static size_t parseElement(const std::vector<char> &in,std::unique_ptr<libhtmlpp::Element> &el,size_t start,bool &termination);
    protected:

        std::unique_ptr<Element>  _childElement=nullptr;
@@ -127,6 +154,7 @@ namespace libhtmlpp {
            std::unique_ptr<Attributes> _nextAttr;
        };

        void _serialelize(const std::vector<char> &in);
    private:
        //if text tagname must be zero
        std::vector<char> _TagName;
@@ -140,6 +168,9 @@ namespace libhtmlpp {
        friend void  print(const Element& element, HtmlString &output,bool formated);
        friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src);
    };
/**
 * @brief Leaf node representing plain text content of an HTML document.
 */

    class TextElement : public Element {
    public:
@@ -155,12 +186,18 @@ namespace libhtmlpp {
        void                       setText(const std::string &txt);

        int         getType() const;

        static size_t parseElement(const std::vector<char> &in,std::unique_ptr<libhtmlpp::Element> &el,size_t start,bool &termination);

    protected:
        std::vector<char> _Text;
        friend class HtmlString;
        friend void  print(const Element& element, HtmlString &output,bool formated);
        friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src);
    };
/**
 * @brief Leaf node representing an HTML comment (<!-- -->).
 */

    class CommentElement : public Element{
    public:
@@ -175,12 +212,17 @@ namespace libhtmlpp {
        void        setComment(const std::string &txt);

        int         getType() const;

        static size_t parseElement(const std::vector<char> &in,std::unique_ptr<libhtmlpp::Element> &el,size_t start,bool &termination);
    protected:
        std::vector<char> _Comment;
        friend class HtmlString;
        friend void  print(const Element& element, HtmlString &output,bool formated);
        friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src);
    };
/**
 * @brief Element representing a <script> tag and its text content.
 */

    class ScriptElement : public HtmlElement{
    public:
@@ -201,6 +243,7 @@ namespace libhtmlpp {
        void         appendChild(const Element* el)=delete;
        void         appendChild(const Element& el)=delete;

        static size_t parseElement(const std::vector<char> &in,std::unique_ptr<libhtmlpp::Element> &el,size_t start,bool &termination);
    protected:

        std::unique_ptr<Element> _childElement=nullptr;
@@ -210,6 +253,9 @@ namespace libhtmlpp {
        friend void  print(const Element& element, HtmlString &output,bool formated);
        friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src);
    };
/**
 * @brief Element representing an embedded <svg> tag and its attributes/content.
 */

    class SvgElement : public HtmlElement{
    public:
@@ -230,6 +276,7 @@ namespace libhtmlpp {
        void         appendChild(const Element* el)=delete;
        void         appendChild(const Element& el)=delete;

        static size_t parseElement(const std::vector<char> &in,std::unique_ptr<libhtmlpp::Element> &el,size_t start,bool &termination);
    protected:

        std::unique_ptr<Element> _childElement=nullptr;
@@ -240,6 +287,48 @@ namespace libhtmlpp {
        friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src);
    };

/**
 * @brief Element representing an embedded <textarea> tag and its attributes/content.
 */

    class TextArea : public HtmlElement{
    public:
        TextArea();
        TextArea(const TextArea &textsrc);
        ~TextArea();

        TextArea& operator=(const Element &hel);
        TextArea& operator=(const Element *hel);

        const std::vector<char> getText();
        void                    setText(const std::string  &text);

        int            getType() const;

        void         insertChild(const Element* el)=delete;
        void         insertChild(const Element& el)=delete;
        void         appendChild(const Element* el)=delete;
        void         appendChild(const Element& el)=delete;

        static size_t parseElement(const std::vector<char> &in,std::unique_ptr<libhtmlpp::Element> &el,size_t start,bool &termination);
    protected:

        std::unique_ptr<Element> _childElement=nullptr;

        std::vector<char> _Text;
        friend class HtmlString;
        friend void  print(const Element& element, HtmlString &output,bool formated);
        friend void _copy(libhtmlpp::Element *dest,const libhtmlpp::Element *src);
    };

/**
 * @brief Serializes an element (and its subtree) into an HtmlString.
 * @param element Root element to print.
 * @param output Output buffer to append serialized HTML to.
 * @param formated If true, pretty-prints the output with line breaks/indentation.
 */


    void print(const Element& element, HtmlString &output,bool formated=false);

    class HtmlString {
@@ -247,7 +336,7 @@ namespace libhtmlpp {

        using value_type = char;

        HtmlString();
        HtmlString()=default;
        HtmlString(const HtmlString &str);
        HtmlString(char str);
        HtmlString(const std::string &str);
@@ -284,21 +373,46 @@ namespace libhtmlpp {
        const std::vector<char>&  data() const;
        const std::string                  str() const;
        const char                         *c_str() const;
/**
 * @brief Parses the current buffer into a DOM-like tree and returns the root element.
 * @return Reference to the root Element stored internally.
 * @throws HTMLException on malformed input.
 */

        libhtmlpp::Element &parse();

    private:
        std::unique_ptr<Element> _rootEl;
        void                 _serialelize(std::vector<char> in, HtmlElement* out);
        void                 _buildTree();
        void _buildtreenode(DocElements *firstel,DocElements *lastel,std::unique_ptr<Element>&html);
        std::vector<char>    _Data;
        friend void HtmlEncode(const std::string &input,HtmlString *output);
        friend class HtmlPage;
    };
/**
 * @brief Decodes special HTML characters in a string and appends to an HtmlString.
 * @param input Plain input string.
 * @param output Destination HtmlString that receives encoded characters.
 */
    void HtmlDecode(const std::string &input,HtmlString &output);

/**
 * @brief Decodes special HTML characters in a string and appends to an std::string.
 * @param input Plain input string.
 * @param output Destination HtmlString that receives encoded characters.
 */
    void HtmlDecode(const std::string &input,std::string &output);

/**
 * @brief Encodes special HTML characters in a string and writes into std::string.
 * @param input Plain input string.
 * @param output Receives encoded HTML string.
 */

    void HtmlEncode(const std::string &input,HtmlString *output);
    void HtmlEncode(const std::string &input,std::string &output);
/**
 * @brief High level loader/saver for HTML documents (files and strings).
 */

    class HtmlPage {
    public:
@@ -374,3 +488,5 @@ namespace libhtmlpp {
        size_t   _count;
    };
};

std::ostream& operator<<(std::ostream& os, const libhtmlpp::HtmlString& p);
Loading