diff --git a/src/xinspect.cpp b/src/xinspect.cpp index 1ec45717..d77c9793 100644 --- a/src/xinspect.cpp +++ b/src/xinspect.cpp @@ -103,6 +103,109 @@ namespace xcpp } return result; } + + std::string escape_html_attribute(const std::string& value) + { + std::string result; + result.reserve(value.size()); + for (char c : value) + { + switch (c) + { + case '&': + result += "&"; + break; + case '"': + result += """; + break; + case '\'': + result += "'"; + break; + case '<': + result += "<"; + break; + case '>': + result += ">"; + break; + default: + result += c; + } + } + return result; + } + + std::string build_cppreference_srcdoc(const std::string& inspect_result) + { + return R"( + +
+ +Loading documentation… Open cppreference
+ + + +)"; + } } std::string inspect(const std::string& code) @@ -198,23 +301,29 @@ namespace xcpp nl::json build_inspect_data(const std::string& inspect_result) { // Format html content. - std::string html_content = R"( - )"; + )"; auto data = nl::json::object({{"text/plain", inspect_result}, {"text/html", html_content}}); return data; diff --git a/test/test_interpreter.cpp b/test/test_interpreter.cpp index a1a11f57..f10097b4 100644 --- a/test/test_interpreter.cpp +++ b/test/test_interpreter.cpp @@ -1014,6 +1014,31 @@ TEST_SUITE("xinspect"){ cmp.child_value = "nonexistentMethod"; REQUIRE(cmp(node) == false); } + + TEST_CASE("build_inspect_data_embeds_cppreference_content"){ + std::string url = "https://en.cppreference.com/w/cpp/container/vector"; + nl::json data = xcpp::build_inspect_data(url); + + REQUIRE(data.contains("text/html")); + std::string html = data["text/html"].get