aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/css
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-06-10 17:21:09 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-06-11 15:09:10 +0100
commite02a4f2831af83eec951b98cc93823568c226f4f (patch)
tree3e5d651caa93e15102fa771f5bced94969ed5328 /src/libserver/css
parent9b2fb6ce7e647bdf719c6598098ecd0f112cb016 (diff)
downloadrspamd-e02a4f2831af83eec951b98cc93823568c226f4f.tar.gz
rspamd-e02a4f2831af83eec951b98cc93823568c226f4f.zip
[Project] Html/CSS: Switch styles parsing to css parser
Diffstat (limited to 'src/libserver/css')
-rw-r--r--src/libserver/css/css_parser.cxx14
-rw-r--r--src/libserver/css/css_parser.hxx13
2 files changed, 27 insertions, 0 deletions
diff --git a/src/libserver/css/css_parser.cxx b/src/libserver/css/css_parser.cxx
index 774a65cfc..34d65aadc 100644
--- a/src/libserver/css/css_parser.cxx
+++ b/src/libserver/css/css_parser.cxx
@@ -801,6 +801,20 @@ auto parse_css(rspamd_mempool_t *pool, const std::string_view &st,
"cannot parse input"});
}
+auto
+parse_css_declaration(rspamd_mempool_t *pool, const std::string_view &st)
+ -> rspamd::html::html_block *
+{
+ auto &&res = process_declaration_tokens(pool,
+ get_rules_parser_functor(pool, st));
+
+ if (res) {
+ return res->compile_to_block(pool);
+ }
+
+ return nullptr;
+}
+
TEST_SUITE("css parser") {
TEST_CASE("parse colors") {
const std::vector<const char *> cases{
diff --git a/src/libserver/css/css_parser.hxx b/src/libserver/css/css_parser.hxx
index ec6d5159a..1e0762d78 100644
--- a/src/libserver/css/css_parser.hxx
+++ b/src/libserver/css/css_parser.hxx
@@ -30,6 +30,10 @@
#include "contrib/expected/expected.hpp"
#include "logger.h"
+/* Forward declaration */
+namespace rspamd::html {
+struct html_block;
+}
namespace rspamd::css {
@@ -205,6 +209,15 @@ auto get_selectors_parser_functor(rspamd_mempool_t *pool,
auto get_rules_parser_functor(rspamd_mempool_t *pool,
const std::string_view &st) -> blocks_gen_functor;
+/**
+ * Parses a css declaration (e.g. embedded css and returns a completed html block)
+ * @param pool
+ * @param st
+ * @return
+ */
+auto parse_css_declaration(rspamd_mempool_t *pool, const std::string_view &st)
+ -> rspamd::html::html_block *;
+
}
#endif //RSPAMD_CSS_PARSER_HXX