/* * Copyright (c) 2020, Hunter Salyer * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace JS { class MarkupGenerator { public: static ErrorOr html_from_source(StringView); static ErrorOr html_from_value(Value); static ErrorOr html_from_error(Error const&, bool); private: enum class StyleType { Invalid, String, Number, KeywordBold, Punctuation, Operator, Keyword, ControlKeyword, Identifier, ObjectType, }; static ErrorOr value_to_html(Value, StringBuilder& output_html, HashTable seen_objects = {}); static ErrorOr array_to_html(Array const&, StringBuilder& output_html, HashTable&); static ErrorOr object_to_html(Object const&, StringBuilder& output_html, HashTable&); static ErrorOr function_to_html(Object const&, StringBuilder& output_html, HashTable&); static ErrorOr date_to_html(Object const&, StringBuilder& output_html, HashTable&); static ErrorOr error_to_html(Error const&, StringBuilder& output_html, bool in_promise); static ErrorOr trace_to_html(TracebackFrame const&, StringBuilder& output_html); static StringView style_from_style_type(StyleType); static StyleType style_type_for_token(Token); static ErrorOr open_style_type(StyleType type); static ErrorOr wrap_string_in_style(StringView source, StyleType type); }; }