Add CSS selector for ":contains(text)"
f34nk opened this issue · 6 comments
Hello,
I would like to implement a new selector for the pseudo class :contains(text)
.
:contains() Selector
Select all elements that contain the specified text.
The current W3C CSS specification left this section intentionally blank. However, some information can be found in an old spec from 2001.
Since I am new to the code-stack would you be so kind and give me some hints?
I will document my progress here.
Best, Fr34nk
I followed the implementation of the :has()
pseudo class.
You can compare my changes here.
I added all the necessary functions, enums and incremented MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_LAST_ENTRY.
However, running make
I get the following error.
cc -Wall -Werror -pipe -pedantic -Isource -fPIC -D_POSIX_C_SOURCE=199309L -O2 -Wno-unused-variable -Wno-unused-function -std=c99 -DMODEST_BUILD_OS=Linux -DMODEST_PORT_NAME=posix -DMyCORE_OS_LINUX -c -o source/modest/finder/finder.o source/modest/finder/finder.c
In file included from source/modest/finder/finder.c:22:0:
source/modest/finder/resource.h:57:5: error: ‘modest_finder_selector_sub_type_pseudo_class_function_contains’ undeclared here (not in a function)
modest_finder_selector_sub_type_pseudo_class_function_contains /* MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_CONTAINS */
^
make: *** [source/modest/finder/finder.o] Error 1
I don't quite understand what I did wrong since this error points to the modest_finder_static_selector_sub_type_pseudo_class_function_map
and I thought the "xy_LAST_ENTRY" holds the correct value?
Any help greatly appreciated.
Hi!
I will try to help with this, at the moment there is not much time. Later I'll figure it out.
Ok, I found it. Of course I missed something :)
I'll keep posting...
Hey man. I am close to refactoring my Elixir binding package modest_ex and the first major release.
However, it would be awesome if I would be able to include the ":contains" selector in my Modest fork.
As far as I can see I added all functions and some dummy code for the selector. It compiles but the test returns with "BAD_SELECTOR".
You can compare my changes here.
Would you be so kind and take a look where I went wrong?
Best, f34nk
Here is my Problem:
mycss_selectors_function_begin_f to_func = mycss_function_begin_by_name(str->data, str->length);
in parser.c
does not return the correct function for "contains".
mycss_function_begin_entry_by_name() in functions.c
size_t idx = ((mycore_string_chars_lowercase_map[ (const unsigned char)name[0] ] *
mycore_string_chars_lowercase_map[ (const unsigned char)name[(length - 1)] ] *
length)
% MyCSS_SELECTORS_FUNCTION_NAME_STATIC_SIZE) + 1;
idx == 44
, which is the wrong index, obviously.
@f34nk
You need to generate new mycss_selectors_function_begin_map_index
variable for function_resource.h file.
For generate new variable resource use utils/MyCSS/functions.pl file. Append your function name to my $func_map = {...}
hash and try to run script.
See mycss_selectors_sub_type_pseudo_class_function
in myosi.h, append your function name like a
...
MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_CONTAINS = 0x0f,
MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_LAST_ENTRY = 0x10
...
and append your function to mycss_selectors_value_function_destroy_map
in
value_resource.h file by index MyCSS_SELECTORS_SUB_TYPE_PSEUDO_CLASS_FUNCTION_CONTAINS
, some like a:
...
mycss_selectors_value_pseudo_class_function_nth_of_type_destroy,
mycss_selectors_value_pseudo_class_function_nth_of_type_contains
};
And append serialization for your function to serialization.c