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

Force wrap col within colgroup #1145

Open
cWenyu opened this issue Jul 21, 2023 · 1 comment
Open

Force wrap col within colgroup #1145

cWenyu opened this issue Jul 21, 2023 · 1 comment

Comments

@cWenyu
Copy link

cWenyu commented Jul 21, 2023

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

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 this case?
Thanks

@cWenyu
Copy link
Author

cWenyu commented Jul 24, 2023

A duplicated question on terser/html-minifier-terser#159

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

1 participant