Skip to content

Commit

Permalink
parse5 -> parse5-sax-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
milahu committed Oct 11, 2022
1 parent 1593cd6 commit 8f004ca
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion extensions/extension-editing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"dependencies": {
"jsonc-parser": "^3.2.0",
"markdown-it": "^13.0.1",
"parse5": "^7.1.1",
"parse5-sax-parser": "^7.0.0",
"vscode-nls": "^5.2.0"
},
"contributes": {
Expand Down
12 changes: 7 additions & 5 deletions extensions/extension-editing/src/extensionLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class ExtensionLinter {
private readmeQ = new Set<TextDocument>();
private timer: NodeJS.Timer | undefined;
private markdownIt: MarkdownItType | undefined;
private parse5: typeof import('parse5') | undefined;
private parse5: typeof import('parse5-sax-parser') | undefined;

constructor() {
this.disposables.push(
Expand Down Expand Up @@ -225,10 +225,11 @@ export class ExtensionLinter {
for (const tnp of tokensAndPositions) {
if (tnp.token.type === 'text' && tnp.token.content) {
if (!this.parse5) {
this.parse5 = await import('parse5');
this.parse5 = await import('parse5-sax-parser');
}
const parser = new this.parse5.SAXParser({ locationInfo: true });
parser.on('startTag', (name, attrs, _selfClosing, location) => {
const parser = new this.parse5.SAXParser({ sourceCodeLocationInfo: true });
parser.on('startTag', (startTag) => {
const { tagName: name, attrs, sourceCodeLocation: location } = startTag;
if (name === 'img') {
const src = attrs.find(a => a.name === 'src');
if (src && src.value && location) {
Expand All @@ -245,7 +246,8 @@ export class ExtensionLinter {
diagnostics.push(svgStart);
}
});
parser.on('endTag', (name, location) => {
parser.on('endTag', (endTag) => {
const { tagName: name, sourceCodeLocation: location } = endTag;
if (name === 'svg' && svgStart && location) {
const end = tnp.begin + location.endOffset;
svgStart.range = new Range(svgStart.range.start, document.positionAt(end));
Expand Down
9 changes: 8 additions & 1 deletion extensions/extension-editing/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,14 @@ mdurl@^1.0.1:
resolved "https://registry.yarnpkg.com/mdurl/-/mdurl-1.0.1.tgz#fe85b2ec75a59037f2adfec100fd6c601761152e"
integrity sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=

parse5@^7.1.1:
parse5-sax-parser@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/parse5-sax-parser/-/parse5-sax-parser-7.0.0.tgz#4c05064254f0488676aca75fb39ca069ec96dee5"
integrity sha512-5A+v2SNsq8T6/mG3ahcz8ZtQ0OUFTatxPbeidoMB7tkJSGDY3tdfl4MHovtLQHkEn5CGxijNWRQHhRQ6IRpXKg==
dependencies:
parse5 "^7.0.0"

parse5@^7.0.0:
version "7.1.1"
resolved "https://registry.yarnpkg.com/parse5/-/parse5-7.1.1.tgz#4649f940ccfb95d8754f37f73078ea20afe0c746"
integrity sha512-kwpuwzB+px5WUg9pyK0IcK/shltJN5/OVhQagxhCQNtT9Y9QRZqNY2e1cmbu/paRh5LMnz/oVTVLBpjFmMZhSg==
Expand Down

0 comments on commit 8f004ca

Please sign in to comment.