Skip to content

Commit

Permalink
Embedded SVGs not valid
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Jun 27, 2017
1 parent 1070a6a commit 15b579d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions extensions/extension-editing/src/extensionLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const localize = nls.loadMessageBundle();

const httpsRequired = localize('httpsRequired', "Images must use the HTTPS protocol.");
const svgsNotValid = localize('svgsNotValid', "SVGs are not a valid image source.");
const embeddedSvgsNotValid = localize('embeddedSvgsNotValid', "Embedded SVGs are not a valid image source.");
const dataUrlsNotValid = localize('dataUrlsNotValid', "Data URLs are not a valid image source.");
const relativeUrlRequiresHttpsRepository = localize('relativeUrlRequiresHttpsRepository', "Relative image URLs require a repository with HTTPS protocol in the package.json.");

Expand Down Expand Up @@ -195,6 +196,7 @@ export class ExtensionLinter {
}
});

let svgStart: Diagnostic;
tokensAndPositions.filter(tnp => tnp.token.type === 'text' && tnp.token.content)
.map(tnp => {
const parser = new parse5.SAXParser({ locationInfo: true });
Expand All @@ -207,6 +209,18 @@ export class ExtensionLinter {
this.addDiagnostics(diagnostics, document, begin, begin + src.value.length, src.value, Context.MARKDOWN, info);
}
}
} else if (name === 'svg') {
const begin = tnp.begin + location.startOffset;
const end = tnp.begin + location.endOffset;
const range = new Range(document.positionAt(begin), document.positionAt(end));
svgStart = new Diagnostic(range, embeddedSvgsNotValid, DiagnosticSeverity.Warning);
diagnostics.push(svgStart);
}
});
parser.on('endTag', (name, location) => {
if (name === 'svg' && svgStart) {
const end = tnp.begin + location.endOffset;
svgStart.range = new Range(svgStart.range.start, document.positionAt(end));
}
});
parser.write(tnp.token.content);
Expand Down

0 comments on commit 15b579d

Please sign in to comment.