Skip to content
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

wrap each col element in a colgroup when render col in a separate function #159

Open
cWenyu opened this issue Jul 19, 2023 · 2 comments
Open

Comments

@cWenyu
Copy link

cWenyu commented Jul 19, 2023

What happened?

Hi,
I'm using html-minifier-terser to handle HTML template literal, and define each template source using html as keyword. For some reason, I have to define customer col separately and repeated to generate col 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

import { html } from 'lit-html';
import {repeat} from 'lit/directives/repeat.js';

export default class MinifyTester {
  _renderCol() {
    return repeat(this.cols, (col) => html `<col/>`);
  }
  _renderColumnGroup() {
    return html`
      <colgroup>
        ${this._renderCol()}
      </colgroup>
    `;
  }
}

minified output:

import { html } from 'lit-html';
import {repeat} from 'lit/directives/repeat.js';

class MinifyTester {
  _renderCol() {
    return html`<colgroup><col></colgroup>`;
  }
  _renderColumnGroup() {
    return html`<colgroup>${this._renderCol()}</colgroup>`;
  }
}

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).

  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 the case in the future?
Thanks

Version

V7.2.0

What browsers are you seeing the problem on?

Firefox, Chrome, Safari

Link to reproduce

No response

Relevant log output

No response

Willing to submit a PR?

None

@cWenyu cWenyu changed the title [Bug]: wrap each col element in a colgroup when render col in a seperate function [Bug]: wrap each col element in a colgroup when render col in a separate function Jul 19, 2023
@cWenyu cWenyu changed the title [Bug]: wrap each col element in a colgroup when render col in a separate function wrap each col element in a colgroup when render col in a separate function Jul 21, 2023
@cWenyu
Copy link
Author

cWenyu commented Jul 21, 2023

A duplicated question: kangax/html-minifier#1145

@DanielRuf
Copy link
Contributor

You can tell htmlninifier to ignore parts. See https://github.com/terser/html-minifier-terser?tab=readme-ov-file#ignoring-chunks-of-markup

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

No branches or pull requests

2 participants