Skip to content

Commit 6c792bc

Browse files
committed
change TSDoc to support forbidding all HTML tags
1 parent 209194b commit 6c792bc

File tree

3 files changed

+172
-3
lines changed

3 files changed

+172
-3
lines changed

tsdoc/src/configuration/TSDocConfiguration.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,6 @@ export class TSDocConfiguration {
215215
* Returns true if the html element is supported in this configuration.
216216
*/
217217
public isHtmlElementSupported(htmlTag: string): boolean {
218-
if (this._supportedHtmlElements.size === 0) {
219-
return true;
220-
}
221218
return this._supportedHtmlElements.has(htmlTag);
222219
}
223220

tsdoc/src/parser/__tests__/NodeParserHtml.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,14 @@ test('11 Supported HTML elements, negative', () => {
121121
config
122122
);
123123
});
124+
125+
test('12 Forbidding all HTML elements, negative', () => {
126+
const config: TSDocConfiguration = new TSDocConfiguration();
127+
config.setSupportedHtmlElements([]);
128+
config.setReportUnsupportedHtmlElements(true);
129+
130+
TestHelpers.parseAndMatchNodeParserSnapshot(
131+
['/**', ' * <a>', ' * <b>', ' * <c>', ' */'].join('\n'),
132+
config
133+
);
134+
});

tsdoc/src/parser/__tests__/__snapshots__/NodeParserHtml.test.ts.snap

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,3 +2235,164 @@ Object {
22352235
},
22362236
}
22372237
`;
2238+
2239+
exports[`12 Forbidding all HTML elements, negative 1`] = `
2240+
Object {
2241+
"buffer": "/**[n] * [<]a[>][n] * [<]b[>][n] * [<]c[>][n] */",
2242+
"gaps": Array [],
2243+
"lines": Array [
2244+
"[<]a[>]",
2245+
"[<]b[>]",
2246+
"[<]c[>]",
2247+
],
2248+
"logMessages": Array [
2249+
"(2,4): Invalid HTML element: The HTML element name \\"a\\" is not defined by your TSDoc configuration",
2250+
"(2,6): The \\">\\" character should be escaped using a backslash to avoid confusion with an HTML tag",
2251+
"(3,4): Invalid HTML element: The HTML element name \\"b\\" is not defined by your TSDoc configuration",
2252+
"(3,6): The \\">\\" character should be escaped using a backslash to avoid confusion with an HTML tag",
2253+
"(4,4): Invalid HTML element: The HTML element name \\"c\\" is not defined by your TSDoc configuration",
2254+
"(4,6): The \\">\\" character should be escaped using a backslash to avoid confusion with an HTML tag",
2255+
],
2256+
"nodes": Object {
2257+
"kind": "Comment",
2258+
"nodes": Array [
2259+
Object {
2260+
"kind": "Section",
2261+
"nodes": Array [
2262+
Object {
2263+
"kind": "Paragraph",
2264+
"nodes": Array [
2265+
Object {
2266+
"errorLocation": "a",
2267+
"errorLocationPrecedingToken": "<",
2268+
"errorMessage": "Invalid HTML element: The HTML element name [q]a[q] is not defined by your TSDoc configuration",
2269+
"kind": "ErrorText",
2270+
"nodes": Array [
2271+
Object {
2272+
"kind": "Excerpt: ErrorText",
2273+
"nodeExcerpt": "[<]",
2274+
},
2275+
],
2276+
},
2277+
Object {
2278+
"kind": "PlainText",
2279+
"nodes": Array [
2280+
Object {
2281+
"kind": "Excerpt: PlainText",
2282+
"nodeExcerpt": "a",
2283+
},
2284+
],
2285+
},
2286+
Object {
2287+
"errorLocation": "[>]",
2288+
"errorLocationPrecedingToken": "a",
2289+
"errorMessage": "The [q][>][q] character should be escaped using a backslash to avoid confusion with an HTML tag",
2290+
"kind": "ErrorText",
2291+
"nodes": Array [
2292+
Object {
2293+
"kind": "Excerpt: ErrorText",
2294+
"nodeExcerpt": "[>]",
2295+
},
2296+
],
2297+
},
2298+
Object {
2299+
"kind": "SoftBreak",
2300+
"nodes": Array [
2301+
Object {
2302+
"kind": "Excerpt: SoftBreak",
2303+
"nodeExcerpt": "[n]",
2304+
},
2305+
],
2306+
},
2307+
Object {
2308+
"errorLocation": "b",
2309+
"errorLocationPrecedingToken": "<",
2310+
"errorMessage": "Invalid HTML element: The HTML element name [q]b[q] is not defined by your TSDoc configuration",
2311+
"kind": "ErrorText",
2312+
"nodes": Array [
2313+
Object {
2314+
"kind": "Excerpt: ErrorText",
2315+
"nodeExcerpt": "[<]",
2316+
},
2317+
],
2318+
},
2319+
Object {
2320+
"kind": "PlainText",
2321+
"nodes": Array [
2322+
Object {
2323+
"kind": "Excerpt: PlainText",
2324+
"nodeExcerpt": "b",
2325+
},
2326+
],
2327+
},
2328+
Object {
2329+
"errorLocation": "[>]",
2330+
"errorLocationPrecedingToken": "b",
2331+
"errorMessage": "The [q][>][q] character should be escaped using a backslash to avoid confusion with an HTML tag",
2332+
"kind": "ErrorText",
2333+
"nodes": Array [
2334+
Object {
2335+
"kind": "Excerpt: ErrorText",
2336+
"nodeExcerpt": "[>]",
2337+
},
2338+
],
2339+
},
2340+
Object {
2341+
"kind": "SoftBreak",
2342+
"nodes": Array [
2343+
Object {
2344+
"kind": "Excerpt: SoftBreak",
2345+
"nodeExcerpt": "[n]",
2346+
},
2347+
],
2348+
},
2349+
Object {
2350+
"errorLocation": "c",
2351+
"errorLocationPrecedingToken": "<",
2352+
"errorMessage": "Invalid HTML element: The HTML element name [q]c[q] is not defined by your TSDoc configuration",
2353+
"kind": "ErrorText",
2354+
"nodes": Array [
2355+
Object {
2356+
"kind": "Excerpt: ErrorText",
2357+
"nodeExcerpt": "[<]",
2358+
},
2359+
],
2360+
},
2361+
Object {
2362+
"kind": "PlainText",
2363+
"nodes": Array [
2364+
Object {
2365+
"kind": "Excerpt: PlainText",
2366+
"nodeExcerpt": "c",
2367+
},
2368+
],
2369+
},
2370+
Object {
2371+
"errorLocation": "[>]",
2372+
"errorLocationPrecedingToken": "c",
2373+
"errorMessage": "The [q][>][q] character should be escaped using a backslash to avoid confusion with an HTML tag",
2374+
"kind": "ErrorText",
2375+
"nodes": Array [
2376+
Object {
2377+
"kind": "Excerpt: ErrorText",
2378+
"nodeExcerpt": "[>]",
2379+
},
2380+
],
2381+
},
2382+
Object {
2383+
"kind": "SoftBreak",
2384+
"nodes": Array [
2385+
Object {
2386+
"kind": "Excerpt: SoftBreak",
2387+
"nodeExcerpt": "[n]",
2388+
},
2389+
],
2390+
},
2391+
],
2392+
},
2393+
],
2394+
},
2395+
],
2396+
},
2397+
}
2398+
`;

0 commit comments

Comments
 (0)