Skip to content

Commit e66ec2c

Browse files
authored
Merge pull request #317 from josephjunker/allowlist-html-tags
Add allowlist for HTML tags and corresponding validation
2 parents 90331de + cb51187 commit e66ec2c

30 files changed

+887
-3
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/tsdoc-config",
5+
"comment": "Add `supportedHtmlTags` and `reportUnsupportedHtmlTags` configuration options",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "@microsoft/tsdoc-config",
10+
"email": "josephjunker@users.noreply.github.com"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/tsdoc",
5+
"comment": "Add `supportedHtmlTags` and `reportUnsupportedHtmlTags` options and corresponding validation",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "@microsoft/tsdoc",
10+
"email": "josephjunker@users.noreply.github.com"
11+
}

tsdoc-config/src/TSDocConfigFile.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ interface IConfigJson {
4141
noStandardTags?: boolean;
4242
tagDefinitions?: ITagConfigJson[];
4343
supportForTags?: { [tagName: string]: boolean };
44+
supportedHtmlElements?: string[];
45+
reportUnsupportedHtmlElements?: boolean;
4446
}
4547

4648
/**
@@ -69,6 +71,8 @@ export class TSDocConfigFile {
6971
private readonly _tagDefinitions: TSDocTagDefinition[];
7072
private readonly _tagDefinitionNames: Set<string>;
7173
private readonly _supportForTags: Map<string, boolean>;
74+
private _supportedHtmlElements: Set<string> | undefined;
75+
private _reportUnsupportedHtmlElements: boolean | undefined;
7276

7377
private constructor() {
7478
this.log = new ParserMessageLog();
@@ -167,6 +171,18 @@ export class TSDocConfigFile {
167171
return this._supportForTags;
168172
}
169173

174+
public get supportedHtmlElements(): ReadonlyArray<string> | undefined {
175+
return this._supportedHtmlElements && Array.from(this._supportedHtmlElements);
176+
}
177+
178+
public get reportUnsupportedHtmlElements(): boolean | undefined {
179+
return this._reportUnsupportedHtmlElements;
180+
}
181+
182+
public set reportUnsupportedHtmlElements(value: boolean | undefined) {
183+
this._reportUnsupportedHtmlElements = value;
184+
}
185+
170186
/**
171187
* Removes all items from the `tagDefinitions` array.
172188
*/
@@ -217,6 +233,23 @@ export class TSDocConfigFile {
217233
this._tagDefinitions.push(tagDefinition);
218234
}
219235

236+
/**
237+
* Adds a new item to the `supportedHtmlElements` array.
238+
*/
239+
public addSupportedHtmlElement(htmlElement: string): void {
240+
if (!this._supportedHtmlElements) {
241+
this._supportedHtmlElements = new Set();
242+
}
243+
this._supportedHtmlElements.add(htmlElement);
244+
}
245+
246+
/**
247+
* Removes the explicit list of allowed html elements.
248+
*/
249+
public clearSupportedHtmlElements(): void {
250+
this._supportedHtmlElements = undefined;
251+
}
252+
220253
/**
221254
* Removes all entries from the "supportForTags" map.
222255
*/
@@ -334,6 +367,15 @@ export class TSDocConfigFile {
334367
});
335368
}
336369

370+
if (configJson.supportedHtmlElements) {
371+
this._supportedHtmlElements = new Set();
372+
for (const htmlElement of configJson.supportedHtmlElements) {
373+
this.addSupportedHtmlElement(htmlElement);
374+
}
375+
}
376+
377+
this._reportUnsupportedHtmlElements = configJson.reportUnsupportedHtmlElements;
378+
337379
if (configJson.supportForTags) {
338380
for (const tagName of Object.keys(configJson.supportForTags)) {
339381
const supported: boolean = configJson.supportForTags[tagName];
@@ -553,6 +595,12 @@ export class TSDocConfigFile {
553595
configFile.setSupportForTag(tagDefinition.tagName, true);
554596
}
555597

598+
for (const htmlElement of configuration.supportedHtmlElements) {
599+
configFile.addSupportedHtmlElement(htmlElement);
600+
}
601+
602+
configFile.reportUnsupportedHtmlElements = configuration.validation.reportUnsupportedHtmlElements;
603+
556604
return configFile;
557605
}
558606

@@ -591,6 +639,14 @@ export class TSDocConfigFile {
591639
});
592640
}
593641

642+
if (this.supportedHtmlElements) {
643+
configJson.supportedHtmlElements = [...this.supportedHtmlElements];
644+
}
645+
646+
if (this._reportUnsupportedHtmlElements !== undefined) {
647+
configJson.reportUnsupportedHtmlElements = this._reportUnsupportedHtmlElements;
648+
}
649+
594650
return configJson;
595651
}
596652

@@ -712,6 +768,16 @@ export class TSDocConfigFile {
712768
});
713769
}
714770
});
771+
772+
if (this.supportedHtmlElements) {
773+
configuration.setSupportedHtmlElements([...this.supportedHtmlElements]);
774+
}
775+
776+
if (this._reportUnsupportedHtmlElements === false) {
777+
configuration.validation.reportUnsupportedHtmlElements = false;
778+
} else if (this._reportUnsupportedHtmlElements === true) {
779+
configuration.validation.reportUnsupportedHtmlElements = true;
780+
}
715781
}
716782

717783
private _getNoStandardTagsWithExtends(): boolean {

0 commit comments

Comments
 (0)