diff --git a/src/descriptionFormatter.ts b/src/descriptionFormatter.ts index a22c4f6..be18986 100644 --- a/src/descriptionFormatter.ts +++ b/src/descriptionFormatter.ts @@ -13,6 +13,7 @@ const NEW_PARAGRAPH_START_THREE_SPACE_SIGNATURE = "2@^5!~#sdE!_NEW_PARAGRAPH_START_THREE_SPACE_SIGNATURE"; const CODE = "2@^5!~#sdE!_CODE"; const CODE_INDENTED = "2@^5!~#sdE!_CODE_INDENTED"; +const TABLE = "2@^5!~#sdE!_TABLE"; interface DescriptionEndLineParams { description: string; @@ -75,6 +76,14 @@ function formatDescription( }, ); + const tables: string[] = []; + text = text.replace(/((\n|^)\|[\s\S]*?)((\n[^|])|$)/g, (code, _1, _2, _3) => { + code = _3 ? code.slice(0, -1) : code; + + tables.push(code); + return `\n\n${TABLE}\n\n${_3 ? _3.slice(1) : ""}`; + }); + /** * Description * @@ -219,6 +228,19 @@ function formatDescription( }, ""); } + if (tables.length > 0) { + text = text.split(TABLE).reduce((pre, cur, index) => { + let result = tables?.[index] || ""; + if (result) { + result = format(result, { + ...options, + parser: "markdown", + }).trim(); + } + return `${pre}${cur.trim()}${result ? `\n\n${result}\n\n` : ""}`; + }, ""); + } + text = text.trim().slice(tagStringLength); return text; diff --git a/tests/__snapshots__/descriptions.test.ts.snap b/tests/__snapshots__/descriptions.test.ts.snap index a18f323..2996bdd 100644 --- a/tests/__snapshots__/descriptions.test.ts.snap +++ b/tests/__snapshots__/descriptions.test.ts.snap @@ -36,6 +36,36 @@ exports[`Long words 1`] = ` " `; +exports[`Markdown Table 1`] = ` +"/** + * Description + * + * | A | B | C | + * | --- | --- | --- | + * | C | V | B | + * | 1 | 2 | 3 | + * + * Description + * + * | A| B |C | + * |C | V | B | + * |1|2|3| + * + * End + */ +" +`; + +exports[`Markdown Table 2`] = ` +"/** + * | A | B | C | + * | --- | --- | --- | + * | C | V | B | + * | 1 | 2 | 3 | + */ +" +`; + exports[`New Lines with star 1`] = ` "/** * Simplifies the token stream to ease the matching with the expected token stream. diff --git a/tests/descriptions.test.ts b/tests/descriptions.test.ts index cdfc9b7..ff5e71a 100644 --- a/tests/descriptions.test.ts +++ b/tests/descriptions.test.ts @@ -563,11 +563,39 @@ test("Long words", () => { expect(result2).toMatchSnapshot(); }); +test("Markdown Table", () => { + const result1 = subject( + ` /** - * If this is a vertical ScrollView scrolls to the bottom. - * If this is a horizontal ScrollView scrolls to the right. - * - * Use `scrollToEnd({ animated: true })` for smooth animated scrolling, - * `scrollToEnd({ animated: false })` for immediate scrolling. - * If no options are passed, `animated` defaults to true. + * description + * | A| B |C | + * | - | - | - | + * |C | V | B | + * |1|2|3| + * + * description + * + * + * | A| B |C | + * |C | V | B | + * |1|2|3| + * end + */ +`, + ); + + expect(result1).toMatchSnapshot(); + + const result2 = subject( + ` +/** + * | A| B |C | + * | - | - | - | + * |C | V | B | + * |1|2|3| */ +`, + ); + + expect(result2).toMatchSnapshot(); +});