Skip to content

Commit

Permalink
feat: add support break by backslash
Browse files Browse the repository at this point in the history
issue: #102
  • Loading branch information
hosseinmd committed Apr 15, 2021
1 parent 74c1b65 commit 4f4cd07
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/descriptionFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ function formatDescription(
}
}

if (mdAst.type === "break") {
return `\\\n`;
}

return (mdAst.value || "") as string;
}

Expand Down Expand Up @@ -195,21 +199,27 @@ function formatDescription(
}

if (ast.type === "paragraph") {
let paragraph = stringyfy(ast, intention, parent);
const paragraph = stringyfy(ast, intention, parent);
if (ast.costumeType === TABLE) {
return paragraph;
}
paragraph = paragraph.replace(/\s+/g, " "); // Make single line

paragraph = capitalizer(paragraph);
if (options.jsdocDescriptionWithDot)
paragraph = paragraph.replace(/([\w\p{L}])$/u, "$1."); // Insert dot if needed

return `\n\n${breakDescriptionToLines(
paragraph,
printWidth,
intention,
)}`;
return `\n\n${paragraph
/**
* Break by backslash\
* issue: https://github.com/hosseinmd/prettier-plugin-jsdoc/issues/102
*/
.split("\\\n")
.map((_paragraph) => {
_paragraph = _paragraph.replace(/\s+/g, " "); // Make single line
_paragraph = capitalizer(_paragraph);
if (options.jsdocDescriptionWithDot)
_paragraph = _paragraph.replace(/([\w\p{L}])$/u, "$1."); // Insert dot if needed
return breakDescriptionToLines(_paragraph, printWidth, intention);
})
.join("\\\n")}`;
}

if (ast.type === "strong") {
Expand Down
5 changes: 5 additions & 0 deletions tests/__snapshots__/descriptions.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ exports[`New Lines with star 2`] = `
"
`;

exports[`New line with \\ 1`] = `
"/** A short description, * A long description. */
"
`;

exports[`Non-english description with dot 1`] = `
"/**
* Wir brauchen hier eine effizientere Lösung. Die generierten Dateien sind zu groß.
Expand Down
14 changes: 14 additions & 0 deletions tests/descriptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,20 @@ test("Nested list", () => {
expect(result1).toMatchSnapshot();
});

test("New line with \\", () => {
const result1 = subject(
`
/**
* A short description,\
* A long description.
*/
`,
);

expect(result1).toMatchSnapshot();
expect(subject(result1)).toEqual(result1);
});

test("List in tags", () => {
const result1 = subject(
`
Expand Down

0 comments on commit 4f4cd07

Please sign in to comment.