Force wrap col within colgroup
- Dominant language
- JavaScript
- Stars
- 5k
- Forks
- 577
- PR merge metrics
- No merged PRs in 30d
Description
Hi, I'm using html-minifier to handle lit HTML template literal, and define each template source using html as keyword. For some reason, I have to define customer col separately and repeat to render different cols for few times. The following code snippet shows the simplest case I have, the output forces adding colgroup for col, which is not expected.
**source code to be minified**
```javascript
import { html } from 'lit-html';
import {repeat} from 'lit/directives/repeat.js';
export default class MinifyTester {
_renderCol() {
return repeat(this.cols, (col) => html ``);
}
_renderColumnGroup() {
return html`
${this._renderCol()}
`;
}
}
```
**minified output:**
```javascript
import { html } from 'lit-html';
import {repeat} from 'lit/directives/repeat.js';
class MinifyTester {
_renderCol() {
return html``;
}
_renderColumnGroup() {
return html`${this._renderCol()}`;
}
}
export { MinifyTester as default };
```
col element is a special case in htmlparser.js, if there's no colgroup in the same template then have to push one and trigger start with two tags (colgroup & col).
```javascript
if (tagName === 'col' && findTag('colgroup') < 0) {
lastTag = 'colgroup';
stack.push({ tag: lastTag, attrs: [] });
if (handler.start) {
await handler.start(lastTag, [], false, '');
}
}
```
Is any chance to cover this case?
Thanks
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in htmlparser.js at the special-case handling for a col without a colgroup, then reproduce the issue with the supplied lit-html template and repeat directive. Verify that a col rendered inside an existing colgroup is not wrapped in an extra colgroup, while ordinary col parsing still behaves as expected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100