Skip to content

Commit

Permalink
fix: support desscription with dash
Browse files Browse the repository at this point in the history
/**
   * - A line
   * - Another line
   */
  • Loading branch information
hosseinmd committed Jan 2, 2021
1 parent 24428a0 commit 87a27a6
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 14 deletions.
40 changes: 29 additions & 11 deletions src/stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
descriptionEndLine,
EMPTY_LINE_SIGNATURE,
NEW_LINE_START_THREE_SPACE_SIGNATURE,
NEW_LINE_START_WITH_DASH,
NEW_PARAGRAPH_START_WITH_DASH,
NEW_PARAGRAPH_START_THREE_SPACE_SIGNATURE,
} from "./utils";
import { DESCRIPTION, EXAMPLE, MEMBEROF, SEE } from "./tags";
Expand Down Expand Up @@ -83,18 +85,34 @@ const stringify = (
.map((newParagraph) => {
return newParagraph
.split(EMPTY_LINE_SIGNATURE)
.map((paragraph) => {
paragraph = capitalizer(paragraph);
return paragraph
.split(NEW_LINE_START_THREE_SPACE_SIGNATURE)
.map((value) =>
breakDescriptionToLines(value, maxWidth, beginningSpace),
)
.join("\n ");
})
.join("\n\n");
.map(
(newEmptyLineWithDash) =>
newEmptyLineWithDash
.split(NEW_PARAGRAPH_START_WITH_DASH)
.map(
(newLineWithDash) =>
newLineWithDash
.split(NEW_LINE_START_WITH_DASH)
.map((paragraph) => {
paragraph = capitalizer(paragraph);
return paragraph
.split(NEW_LINE_START_THREE_SPACE_SIGNATURE)
.map((value) =>
breakDescriptionToLines(
value,
maxWidth,
beginningSpace,
),
)
.join("\n "); // NEW_LINE_START_THREE_SPACE_SIGNATURE
})
.join("\n- "), // NEW_LINE_START_WITH_DASH
)
.join("\n\n- "), // NEW_PARAGRAPH_START_WITH_DASH
)
.join("\n\n"); // EMPTY_LINE_SIGNATURE
})
.join("\n\n ");
.join("\n\n "); // NEW_PARAGRAPH_START_THREE_SPACE_SIGNATURE;

tagString = tagString ? `\n${tagString}` : tagString;
}
Expand Down
22 changes: 19 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import { TAGS_NEED_FORMAT_DESCRIPTION } from "./roles";
import { DESCRIPTION, EXAMPLE, TODO } from "./tags";
import { Comment } from "comment-parser";

const EMPTY_LINE_SIGNATURE = "a2@1093NmY^5!~#sdEKHuhPOK*&baSIGNATURE1";
const EMPTY_LINE_SIGNATURE = "a2@^5!~#sdE!_EMPTY_LINE_SIGNATURE";
const NEW_LINE_START_THREE_SPACE_SIGNATURE =
"l2@_0^3N)Y^5!~^sd*KHuh+O~*;vlSIGNATURE2";
"a2@^5!~#sdE!_NEW_LINE_START_THREE_SPACE_SIGNATURE";
const NEW_LINE_START_WITH_DASH = "a2@^5!~#sdE!_NEW_LINE_START_WITH_DASH";
const NEW_PARAGRAPH_START_WITH_DASH =
"a2@^5!~#sdE!_NEW_PARAGRAPH_START_WITH_DASH";
const NEW_PARAGRAPH_START_THREE_SPACE_SIGNATURE =
"l2@_0^s43fb64ds2Huh+O~*;vlSIGNATURE3";
"a2@^5!~#sdE!_NEW_PARAGRAPH_START_THREE_SPACE_SIGNATURE";

function convertToModernArray(type: string): string {
if (!type) {
Expand Down Expand Up @@ -122,6 +125,17 @@ function formatDescription(
/(\n\n\s\s\s+)|(\n\s+\n\s\s\s+)/g,
NEW_PARAGRAPH_START_THREE_SPACE_SIGNATURE,
); // Add a signature for new paragraph start with three space

text = text.replace(
/(\n\n+(\s+|)-(\s+|))/g, // `\n\n - ` | `\n\n-` | `\n\n -` | `\n\n- `
NEW_PARAGRAPH_START_WITH_DASH,
);

text = text.replace(
/(\n(\s+|)-(\s+|))/g, // `\n - ` | `\n-` | `\n -` | `\n- `
NEW_LINE_START_WITH_DASH,
);

text = text.replace(/(\n\n)|(\n\s+\n)/g, EMPTY_LINE_SIGNATURE); // Add a signature for empty line and use that later
text = text.replace(/\n\s\s\s+/g, NEW_LINE_START_THREE_SPACE_SIGNATURE); // Add a signature for new line start with three space
text = text.replace(/\s\s+/g, " "); // Avoid multiple spaces
Expand Down Expand Up @@ -170,6 +184,8 @@ function capitalizer(str: string): string {

export {
EMPTY_LINE_SIGNATURE,
NEW_LINE_START_WITH_DASH,
NEW_PARAGRAPH_START_WITH_DASH,
NEW_LINE_START_THREE_SPACE_SIGNATURE,
NEW_PARAGRAPH_START_THREE_SPACE_SIGNATURE,
convertToModernArray,
Expand Down
35 changes: 35 additions & 0 deletions tests/__snapshots__/paragraph.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,38 @@ exports[`description contain paragraph 4`] = `
*/
"
`;
exports[`description new line with dash 1`] = `
"/**
* We will allow the scroll view to give up its lock iff it acquired the lock
* during an animation. This is a very useful default that happens to satisfy
* many common user experiences.
*
* - Stop a scroll on the left edge, then turn that into an outer view's backswipe.
* - Stop a scroll mid-bounce at the top, continue pulling to have the outer view dismiss.
* - However, without catching the scroll view mid-bounce (while it is
* motionless), if you drag far enough for the scroll view to become
* responder (and therefore drag the scroll view a bit), any backswipe
* navigation of a swipe gesture higher in the view hierarchy, should be rejected.
*/
function scrollResponderHandleTerminationRequest() {
return !this.state.observedScrollSinceBecomingResponder;
}
/**
* - Stop a scroll on the left edge, then turn that into an outer view's backswipe.
* - Stop a scroll mid-bounce at the top, continue pulling to have the outer view dismiss.
*/
function scrollResponderHandleTerminationRequest() {
return !this.state.observedScrollSinceBecomingResponder;
}
/**
* - Stop a scroll on the left edge, then turn that into an outer view's backswipe.
* - Stop a scroll mid-bounce at the top, continue pulling to have the outer view dismiss.
*/
function scrollResponderHandleTerminationRequest() {
return !this.state.observedScrollSinceBecomingResponder;
}
"
`;
46 changes: 46 additions & 0 deletions tests/paragraph.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,49 @@ test("description contain paragraph", () => {

expect(result4).toMatchSnapshot();
});

test("description new line with dash", () => {
const result1 = subject(`
/**
* We will allow the scroll view to give up its lock iff it acquired the lock
* during an animation. This is a very useful default that happens to satisfy
* many common user experiences.
*
* - Stop a scroll on the left edge, then turn that into an outer view's
* backswipe.
* - Stop a scroll mid-bounce at the top, continue pulling to have the outer
* view dismiss.
* - However, without catching the scroll view mid-bounce (while it is
* motionless), if you drag far enough for the scroll view to become
* responder (and therefore drag the scroll view a bit), any backswipe
* navigation of a swipe gesture higher in the view hierarchy, should be
* rejected.
*/
function scrollResponderHandleTerminationRequest() {
return !this.state.observedScrollSinceBecomingResponder;
}
/**
* - stop a scroll on the left edge, then turn that into an outer view's
* backswipe.
* - Stop a scroll mid-bounce at the top, continue pulling to have the outer
* view dismiss.
*/
function scrollResponderHandleTerminationRequest() {
return !this.state.observedScrollSinceBecomingResponder;
}
/**- stop a scroll on the left edge, then turn that into an outer view's
* backswipe.
* - Stop a scroll mid-bounce at the top, continue pulling to have the outer
* view dismiss.
*/
function scrollResponderHandleTerminationRequest() {
return !this.state.observedScrollSinceBecomingResponder;
}
`);

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

0 comments on commit 87a27a6

Please sign in to comment.