diff --git a/scripts/apidoc/markdown.ts b/scripts/apidoc/markdown.ts index 88df01507b6..870b4201136 100644 --- a/scripts/apidoc/markdown.ts +++ b/scripts/apidoc/markdown.ts @@ -39,10 +39,15 @@ const htmlSanitizeOptions: sanitizeHtml.IOptions = { function comparableSanitizedHtml(html: string): string { return html + .replace(/&#x[0-9A-F]{2};/g, (x) => + String.fromCodePoint(Number.parseInt(x.slice(3, -1), 16)) + ) .replace(/>/g, '>') - .replace(/ /g, '') + .replace(/</g, '<') + .replace(/&/g, '&') .replace(/"/g, '"') - .replace(/'/g, "'"); + .replace(/=""/g, '') + .replace(/ /g, ''); } /** diff --git a/test/scripts/apidoc/__snapshots__/module.spec.ts.snap b/test/scripts/apidoc/__snapshots__/module.spec.ts.snap index dcd88cd0cf3..2f2d15ddbee 100644 --- a/test/scripts/apidoc/__snapshots__/module.spec.ts.snap +++ b/test/scripts/apidoc/__snapshots__/module.spec.ts.snap @@ -12,7 +12,7 @@ exports[`module > analyzeModule() > ModuleExampleTest 1`] = ` { "comment": "This is a description for a module with a code example.", "deprecated": undefined, - "examples": "
ts
new ModuleExampleTest()
new ModuleExampleTest()
+ "examples": "
ts
new ModuleExampleTest()
", } `; diff --git a/test/scripts/apidoc/__snapshots__/signature.spec.ts.snap b/test/scripts/apidoc/__snapshots__/signature.spec.ts.snap index 04e2ee97c6f..9848720c9f6 100644 --- a/test/scripts/apidoc/__snapshots__/signature.spec.ts.snap +++ b/test/scripts/apidoc/__snapshots__/signature.spec.ts.snap @@ -5,13 +5,10 @@ exports[`signature > analyzeSignature() > complexArrayParameter 1`] = ` "deprecated": undefined, "description": "

Complex array parameter.

", - "examples": "
ts
complexArrayParameter<T>(array: readonly Array<{
-  value: T,
-  weight: number
-}>): T
complexArrayParameter<T>(array: readonly Array<{
-  value: T,
-  weight: number
-}>): T
+ "examples": "
ts
complexArrayParameter<T>(array: readonly Array<{
+  value: T,
+  weight: number
+}>): T
", "name": "complexArrayParameter", "parameters": [ @@ -56,7 +53,7 @@ exports[`signature > analyzeSignature() > defaultBooleanParamMethod 1`] = ` "deprecated": undefined, "description": "

Test with a default parameter.

", - "examples": "
ts
defaultBooleanParamMethod(c: boolean = true): number
defaultBooleanParamMethod(c: boolean = true): number
+ "examples": "
ts
defaultBooleanParamMethod(c: boolean = true): number
", "name": "defaultBooleanParamMethod", "parameters": [ @@ -108,7 +105,7 @@ exports[`signature > analyzeSignature() > functionParamMethod 1`] = ` "deprecated": undefined, "description": "

Test with a function parameters.

", - "examples": "
ts
functionParamMethod(fn: (a: string) => number): number
functionParamMethod(fn: (a: string) => number): number
+ "examples": "
ts
functionParamMethod(fn: (a: string) => number): number
", "name": "functionParamMethod", "parameters": [ @@ -133,7 +130,7 @@ exports[`signature > analyzeSignature() > literalUnionParamMethod 1`] = ` "deprecated": undefined, "description": "

Test with LiteralUnion.

", - "examples": "
ts
literalUnionParamMethod(value: 'a' | 'b' | string, namedValue: 'a' | 'b' | string, array: readonly Array<'a' | 'b' | string>, namedArray: readonly Array<'a' | 'b' | string>, mixed: 'a' | 'b' | string | readonly Array<'a' | 'b' | string>, namedMixed: 'a' | 'b' | string | readonly Array<'a' | 'b' | string>): string
literalUnionParamMethod(value: 'a' | 'b' | string, namedValue: 'a' | 'b' | string, array: readonly Array<'a' | 'b' | string>, namedArray: readonly Array<'a' | 'b' | string>, mixed: 'a' | 'b' | string | readonly Array<'a' | 'b' | string>, namedMixed: 'a' | 'b' | string | readonly Array<'a' | 'b' | string>): string
+ "examples": "
ts
literalUnionParamMethod(value: 'a' | 'b' | string, namedValue: 'a' | 'b' | string, array: readonly Array<'a' | 'b' | string>, namedArray: readonly Array<'a' | 'b' | string>, mixed: 'a' | 'b' | string | readonly Array<'a' | 'b' | string>, namedMixed: 'a' | 'b' | string | readonly Array<'a' | 'b' | string>): string
", "name": "literalUnionParamMethod", "parameters": [ @@ -194,7 +191,7 @@ exports[`signature > analyzeSignature() > methodWithDeprecated 1`] = ` ", "description": "

Test with deprecated and see marker.

", - "examples": "
ts
methodWithDeprecated(): number
methodWithDeprecated(): number
+ "examples": "
ts
methodWithDeprecated(): number
", "name": "methodWithDeprecated", "parameters": [], @@ -213,15 +210,11 @@ exports[`signature > analyzeSignature() > methodWithDeprecatedOption 1`] = ` "deprecated": undefined, "description": "

Test with deprecated option.

", - "examples": "
ts
methodWithDeprecatedOption(option: {
-  a: string,
-  b: () => number,
-  c: number
-}): number
methodWithDeprecatedOption(option: {
-  a: string,
-  b: () => number,
-  c: number
-}): number
+ "examples": "
ts
methodWithDeprecatedOption(option: {
+  a: string,
+  b: () => number,
+  c: number
+}): number
", "name": "methodWithDeprecatedOption", "parameters": [ @@ -269,9 +262,8 @@ exports[`signature > analyzeSignature() > methodWithExample 1`] = ` "deprecated": undefined, "description": "

Test with example marker.

", - "examples": "
ts
methodWithExample(): number
-test.apidoc.methodWithExample() // 0
methodWithExample(): number
-test.apidoc.methodWithExample() // 0
+ "examples": "
ts
methodWithExample(): number
+test.apidoc.methodWithExample() // 0
", "name": "methodWithExample", "parameters": [], @@ -288,7 +280,7 @@ exports[`signature > analyzeSignature() > methodWithMultipleSeeMarkers 1`] = ` "deprecated": undefined, "description": "

Test with multiple see markers.

", - "examples": "
ts
methodWithMultipleSeeMarkers(): number
methodWithMultipleSeeMarkers(): number
+ "examples": "
ts
methodWithMultipleSeeMarkers(): number
", "name": "methodWithMultipleSeeMarkers", "parameters": [], @@ -308,7 +300,7 @@ exports[`signature > analyzeSignature() > methodWithMultipleSeeMarkersAndBacktic "deprecated": undefined, "description": "

Test with multiple see markers and backticks.

", - "examples": "
ts
methodWithMultipleSeeMarkersAndBackticks(): number
methodWithMultipleSeeMarkersAndBackticks(): number
+ "examples": "
ts
methodWithMultipleSeeMarkersAndBackticks(): number
", "name": "methodWithMultipleSeeMarkersAndBackticks", "parameters": [], @@ -328,7 +320,7 @@ exports[`signature > analyzeSignature() > methodWithMultipleThrows 1`] = ` "deprecated": undefined, "description": "

Test with multiple throws.

", - "examples": "
ts
methodWithMultipleThrows(): number
methodWithMultipleThrows(): number
+ "examples": "
ts
methodWithMultipleThrows(): number
", "name": "methodWithMultipleThrows", "parameters": [], @@ -346,7 +338,7 @@ exports[`signature > analyzeSignature() > methodWithSinceMarker 1`] = ` "deprecated": undefined, "description": "

Test with since marker.

", - "examples": "
ts
methodWithSinceMarker(): number
methodWithSinceMarker(): number
+ "examples": "
ts
methodWithSinceMarker(): number
", "name": "methodWithSinceMarker", "parameters": [], @@ -363,7 +355,7 @@ exports[`signature > analyzeSignature() > methodWithThrows 1`] = ` "deprecated": undefined, "description": "

Test with throws.

", - "examples": "
ts
methodWithThrows(): number
methodWithThrows(): number
+ "examples": "
ts
methodWithThrows(): number
", "name": "methodWithThrows", "parameters": [], @@ -380,7 +372,7 @@ exports[`signature > analyzeSignature() > multiParamMethod 1`] = ` "deprecated": undefined, "description": "

Test with multiple parameters.

", - "examples": "
ts
multiParamMethod(a: number, b?: string, c: boolean = true): number
multiParamMethod(a: number, b?: string, c: boolean = true): number
+ "examples": "
ts
multiParamMethod(a: number, b?: string, c: boolean = true): number
", "name": "multiParamMethod", "parameters": [ @@ -419,7 +411,7 @@ exports[`signature > analyzeSignature() > noParamMethod 1`] = ` "deprecated": undefined, "description": "

Test with no parameters.

", - "examples": "
ts
noParamMethod(): number
noParamMethod(): number
+ "examples": "
ts
noParamMethod(): number
", "name": "noParamMethod", "parameters": [], @@ -436,7 +428,7 @@ exports[`signature > analyzeSignature() > optionalStringParamMethod 1`] = ` "deprecated": undefined, "description": "

Test with an optional parameter.

", - "examples": "
ts
optionalStringParamMethod(b?: string): number
optionalStringParamMethod(b?: string): number
+ "examples": "
ts
optionalStringParamMethod(b?: string): number
", "name": "optionalStringParamMethod", "parameters": [ @@ -461,19 +453,13 @@ exports[`signature > analyzeSignature() > optionsInlineParamMethodWithDefaults 1 "deprecated": undefined, "description": "

Test with a function parameters (inline types) with defaults.

", - "examples": "
ts
optionsInlineParamMethodWithDefaults(a: {
-  value: number
-} = { value: 1 }, b: {
-  value: number
-} = { value: 1 }, c: {
-  value: number
-}): number
optionsInlineParamMethodWithDefaults(a: {
-  value: number
-} = { value: 1 }, b: {
-  value: number
-} = { value: 1 }, c: {
-  value: number
-}): number
+ "examples": "
ts
optionsInlineParamMethodWithDefaults(a: {
+  value: number
+} = { value: 1 }, b: {
+  value: number
+} = { value: 1 }, c: {
+  value: number
+}): number
", "name": "optionsInlineParamMethodWithDefaults", "parameters": [ @@ -535,7 +521,7 @@ exports[`signature > analyzeSignature() > optionsInterfaceParamMethodWithDefault "deprecated": undefined, "description": "

Test with a function parameters with defaults.

", - "examples": "
ts
optionsInterfaceParamMethodWithDefaults(a: ParameterOptionsInterfaceA = { value: 1 }, b: ParameterOptionsInterfaceB = { value: 1 }, c: ParameterOptionsInterfaceC): number
optionsInterfaceParamMethodWithDefaults(a: ParameterOptionsInterfaceA = { value: 1 }, b: ParameterOptionsInterfaceB = { value: 1 }, c: ParameterOptionsInterfaceC): number
+ "examples": "
ts
optionsInterfaceParamMethodWithDefaults(a: ParameterOptionsInterfaceA = { value: 1 }, b: ParameterOptionsInterfaceB = { value: 1 }, c: ParameterOptionsInterfaceC): number
", "name": "optionsInterfaceParamMethodWithDefaults", "parameters": [ @@ -574,19 +560,13 @@ exports[`signature > analyzeSignature() > optionsParamMethod 1`] = ` "deprecated": undefined, "description": "

Test with an options parameter.

", - "examples": "
ts
optionsParamMethod(options: {
-  a: number,
-  b: string,
-  c: boolean,
-  d: () => string,
-  e: 'a' | 'b' | string
-}): number
optionsParamMethod(options: {
-  a: number,
-  b: string,
-  c: boolean,
-  d: () => string,
-  e: 'a' | 'b' | string
-}): number
+ "examples": "
ts
optionsParamMethod(options: {
+  a: number,
+  b: string,
+  c: boolean,
+  d: () => string,
+  e: 'a' | 'b' | string
+}): number
", "name": "optionsParamMethod", "parameters": [ @@ -646,7 +626,7 @@ exports[`signature > analyzeSignature() > optionsTypeParamMethodWithDefaults 1`] "deprecated": undefined, "description": "

Test with a function parameters with defaults.

", - "examples": "
ts
optionsTypeParamMethodWithDefaults(a: ParameterOptionsTypeA = { value: 1 }, b: ParameterOptionsTypeB = { value: 1 }, c: ParameterOptionsTypeC): number
optionsTypeParamMethodWithDefaults(a: ParameterOptionsTypeA = { value: 1 }, b: ParameterOptionsTypeB = { value: 1 }, c: ParameterOptionsTypeC): number
+ "examples": "
ts
optionsTypeParamMethodWithDefaults(a: ParameterOptionsTypeA = { value: 1 }, b: ParameterOptionsTypeB = { value: 1 }, c: ParameterOptionsTypeC): number
", "name": "optionsTypeParamMethodWithDefaults", "parameters": [ @@ -685,7 +665,7 @@ exports[`signature > analyzeSignature() > recordParamMethod 1`] = ` "deprecated": undefined, "description": "

Test with a Record parameter.

", - "examples": "
ts
recordParamMethod(object: Record<string, number>): number
recordParamMethod(object: Record<string, number>): number
+ "examples": "
ts
recordParamMethod(object: Record<string, number>): number
", "name": "recordParamMethod", "parameters": [ @@ -710,7 +690,7 @@ exports[`signature > analyzeSignature() > requiredNumberParamMethod 1`] = ` "deprecated": undefined, "description": "

Test with a required parameter.

", - "examples": "
ts
requiredNumberParamMethod(a: number): number
requiredNumberParamMethod(a: number): number
+ "examples": "
ts
requiredNumberParamMethod(a: number): number
", "name": "requiredNumberParamMethod", "parameters": [ @@ -735,15 +715,11 @@ exports[`signature > analyzeSignature() > stringUnionParamMethod 1`] = ` "deprecated": undefined, "description": "

Test with string union.

", - "examples": "
ts
stringUnionParamMethod(value: 'a' | 'b', options?: {
-  casing: 'lower' | 'mixed' | 'upper',
-  excludes: readonly AlphaNumericChar[],
-  format: 'binary' | 'css' | 'decimal' | 'hex'
-}): string
stringUnionParamMethod(value: 'a' | 'b', options?: {
-  casing: 'lower' | 'mixed' | 'upper',
-  excludes: readonly AlphaNumericChar[],
-  format: 'binary' | 'css' | 'decimal' | 'hex'
-}): string
+ "examples": "
ts
stringUnionParamMethod(value: 'a' | 'b', options?: {
+  casing: 'lower' | 'mixed' | 'upper',
+  excludes: readonly AlphaNumericChar[],
+  format: 'binary' | 'css' | 'decimal' | 'hex'
+}): string
", "name": "stringUnionParamMethod", "parameters": [