-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from Microsoft/octref/pseudo-selectors-only
Add new pseudo selectors / elements from MDN. Fix microsoft/vscode#41248
- Loading branch information
Showing
8 changed files
with
277 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
//@ts-check | ||
|
||
const mdnData = require('mdn-data') | ||
const { pseudoSelectorDescriptions, pseudoElementDescriptions } = require('./mdn-documentation') | ||
|
||
function addMDNPseudoElements(vscPseudoElements) { | ||
const mdnSelectors = mdnData.css.selectors | ||
const allPseudoElements = vscPseudoElements | ||
|
||
const allPseudoElementNames = vscPseudoElements.map(s => s.name) | ||
|
||
for (const selectorName of Object.keys(mdnSelectors)) { | ||
const selector = mdnSelectors[selectorName] | ||
if (selector.syntax.startsWith('::')) { | ||
if ( | ||
!allPseudoElementNames.includes(selectorName) && | ||
!allPseudoElementNames.includes(selectorName + '()') | ||
) { | ||
allPseudoElements.push({ | ||
name: selectorName, | ||
desc: pseudoElementDescriptions[selectorName] ? pseudoElementDescriptions[selectorName] : '' | ||
}) | ||
} | ||
} | ||
} | ||
return allPseudoElements | ||
} | ||
|
||
const mdnExcludedPseudoSelectors = [ | ||
/** | ||
* See https://developer.mozilla.org/en-US/docs/Web/CSS/:matches | ||
* -moz-any and -webkit-any are already in css-schema.xml | ||
*/ | ||
':any' | ||
] | ||
|
||
function addMDNPseudoSelectors(vscPseudoClasses) { | ||
const mdnSelectors = mdnData.css.selectors | ||
const allPseudoSelectors = vscPseudoClasses | ||
|
||
const allPseudoSelectorNames = vscPseudoClasses.map(s => s.name) | ||
|
||
for (const selectorName of Object.keys(mdnSelectors)) { | ||
const selector = mdnSelectors[selectorName] | ||
if (selector.syntax.startsWith(':') && !selector.syntax.startsWith('::')) { | ||
if ( | ||
!mdnExcludedPseudoSelectors.includes(selectorName) && | ||
!allPseudoSelectorNames.includes(selectorName) && | ||
!allPseudoSelectorNames.includes(selectorName + '()') | ||
) { | ||
allPseudoSelectors.push({ | ||
name: selectorName, | ||
desc: pseudoSelectorDescriptions[selectorName] ? pseudoSelectorDescriptions[selectorName] : '' | ||
}) | ||
} | ||
} | ||
} | ||
return allPseudoSelectors | ||
} | ||
|
||
module.exports = { | ||
addMDNPseudoElements, | ||
addMDNPseudoSelectors | ||
} |
Oops, something went wrong.