Skip to content

Commit

Permalink
fix: parsing counter content in pseudo element (#2640)
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasvh committed Aug 9, 2021
1 parent e429e04 commit 1941b9e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/css/types/functions/counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import {contains} from '../../../core/bitwise';
import {CSSParsedCounterDeclaration} from '../../index';

export class CounterState {
readonly counters: {[key: string]: number[]};
constructor() {
this.counters = {};
}
private readonly counters: {[key: string]: number[]} = {};

getCounterValue(name: string): number {
const counter = this.counters[name];
Expand All @@ -18,7 +15,7 @@ export class CounterState {
return 1;
}

getCounterValues(name: string): number[] {
getCounterValues(name: string): readonly number[] {
const counter = this.counters[name];
return counter ? counter : [];
}
Expand All @@ -37,6 +34,9 @@ export class CounterState {
const counter = this.counters[entry.counter];
if (counter && entry.increment !== 0) {
canReset = false;
if (!counter.length) {
counter.push(1);
}
counter[Math.max(0, counter.length - 1)] += entry.increment;
}
});
Expand Down
19 changes: 19 additions & 0 deletions tests/reftests/pseudo-content.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@
of the section counter, separated
by a period */
}

.issue-2639 {
display: flex;
}

.issue-2639::before {
content: counter(ol0) '. ';
counter-increment: ol0;
}

.issue-2639:first-child {
counter-reset: ol0;
}

</style>
</head>
<body>
Expand Down Expand Up @@ -163,5 +177,10 @@
<li>item</li> <!-- 2 -->
</ol>

<ol>
<li class="issue-2639">one</li>
<li class="issue-2639">two</li>
</ol>

</body>
</html>

0 comments on commit 1941b9e

Please sign in to comment.