Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions src/services/selectorPrinting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,32 +168,29 @@ class MarkedStringPrinter {
}

// the real deal
const content = ['<'];

// element name
const content = [];
if (name) {
content.push(name);
} else {
content.push('element');
content.push(this.prepareElement(name, element.attributes?.filter(x => x.name !== 'name')));
}
content.push(this.prepareElement('element', element.attributes));
this.writeLine(indent, content.join('|'));
}

// attributes
if (element.attributes) {
for (const attr of element.attributes) {
if (attr.name !== 'name') {
content.push(' ');
content.push(attr.name);
const value = attr.value;
if (value) {
content.push('=');
content.push(quotes.ensure(value, this.quote));
}
private prepareElement(name: string, attributes?: Element['attributes']): string {
const content = [`<${name}`];
if (attributes) {
for (const attr of attributes) {
content.push(' ');
content.push(attr.name);
const value = attr.value;
if (value) {
content.push('=');
content.push(quotes.ensure(value, this.quote));
}
}
}
content.push('>');

this.writeLine(indent, content.join(''));
return content.join('');
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/test/css/hover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ suite('CSS Hover', () => {
'[Selector Specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity): (0, 1, 0)'
]
});
assertHover('[name="something"] { color: blue; }', {
contents: [
{ language: 'html', value: '<something>|<element name="something">' },
'[Selector Specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity): (0, 1, 0)'
]
});
assertHover('[attr="something"] { color: blue; }', {
contents: [
{ language: 'html', value: '<element attr="something">' },
'[Selector Specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity): (0, 1, 0)'
]
});
});
});

Expand Down