Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

basic implementation for css counters #281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Dec 28, 2023
Merged

basic implementation for css counters #281

merged 11 commits into from
Dec 28, 2023

Conversation

MicCalo
Copy link
Contributor

@MicCalo MicCalo commented Dec 8, 2023

Very basic implementation for css counters.

Short intro of css counters: W3C Schools
Specification: w3.org

super simple counter usage test page: https://miccalo.github.io/super-duper-tribble/en-US/counter_test.html

Implemented:

  • counter-reset: counter style fixed to decimal
  • counter-increment
  • counter()

In progress:

  • counters()

Missing:

@tordex
Copy link
Member

tordex commented Dec 8, 2023

@MicCalo, please rebase your branch, there are some merge conflict. But after resolving conflicts, branch doesn't build.

…s-vector to elements-list was not auto-merged)
@MicCalo
Copy link
Contributor Author

MicCalo commented Dec 8, 2023

Ups, I wasn't aware that I'm on your repo but thought I'm on my fork :-)

Anyway, what do you think about this in general? Any inputs?

@MicCalo MicCalo changed the title basic implementaion for css counters basic implementation for css counters Dec 8, 2023
@tordex
Copy link
Member

tordex commented Dec 17, 2023

Ups, I wasn't aware that I'm on your repo but thought I'm on my fork :-)

I'll be glad to approve merge when you'll be ready.

Anyway, what do you think about this in general? Any inputs?

Implementation of the new CSS features is very appreciated. I've checked your changes. Here are some recommendations:

  1. There are many changes in "spaces" - not big issue, but makes commit unclear.
  2. I can recommend to add the m_counter_values into the litehtml::element instead of litehtml::html_tag. This will allow to get rid of std::dynamic_pointer_cast. As I saw std::dynamic_pointer_cast has issues with performance.
  3. You are using std::map<string, int> m_counter_values. Is this possible replace strings with int using string_id technique?
  4. If this is possible, create a test for counters

@MicCalo
Copy link
Contributor Author

MicCalo commented Dec 25, 2023

Thanks a lot for your thoughts. I have already moved the counter stuff upwards to litehtml::element which avoids the casts.

Now, I'm working on adding more functionality as I think the 'whole spec' except counter types could be implemented without bloating the code base.

Regarding the string_id approach, I'm not sure. The strings are not predefined but can be any content. Thus a map<string, string_id> would be needed anyway and this would only benefit memory usage when the page defines multiple counter with same name. Code size and complexity would increase.

I will definitely consider writing unit tests. I have to study your approach to see if it is possible.

@tordex
Copy link
Member

tordex commented Dec 25, 2023

Regarding the string_id approach, I'm not sure. The strings are not predefined but can be any content. Thus a map<string, string_id> would be needed anyway and this would only benefit memory usage when the page defines multiple counter with same name. Code size and complexity would increase.

Using _id(string) will give you ID for any string.

I will definitely consider writing unit tests. I have to study your approach to see if it is possible.

Creating tests for litehtml is easy. Just make one or some html files with counters, to cover all/most cases of counters using and place html files into the test/render directory. Then you can build and run tests. Inside litehtml directory:

mkdir build
cmake ../
make
ctest

During the first run all new tests will be FAILED, just find the file your_test_file.htm.FAILED.png, check if this PNG contains valid rendered page and rename it into your_test_file.htm.png. Now running ctest will show you that all tests are passed. Add to the git both htm and png files.

Idea of tests is simple: you have html file with test and png image with correct rendering of this html page. Test just render html file with changed code and compare two images. If images are differ - the test failed.

@MicCalo
Copy link
Contributor Author

MicCalo commented Dec 28, 2023

Alright, I would consider this done :-)

Added tests, used string-ids and reverted whitespace-only changes.

Please feel free to pull it directly or comment on it.

@tordex tordex merged commit ef0a2cd into litehtml:master Dec 28, 2023
@tordex
Copy link
Member

tordex commented Dec 28, 2023

Merged. Thank you for new feature!

@MicCalo MicCalo deleted the css_counters_basic branch December 29, 2023 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.